diff --git a/common/waifu2x.cpp b/common/waifu2x.cpp index fa76d4f..6c71ab5 100644 --- a/common/waifu2x.cpp +++ b/common/waifu2x.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #if defined(WIN32) || defined(WIN64) #include @@ -406,11 +407,13 @@ eWaifu2xError ReconstructImage(boost::shared_ptr> net, cv::Mat eWaifu2xError waifu2x(int argc, char** argv, const std::vector &file_paths, const std::string &mode, const int noise_level, const double scale_ratio, const std::string &model_dir, const std::string &process, - std::vector &errors, const waifu2xCancelFunc cancel_func, const waifu2xProgressFunc progress_func) + std::vector &errors, const waifu2xCancelFunc cancel_func, const waifu2xProgressFunc progress_func, const waifu2xTimeFunc time_func) { if (scale_ratio <= 0.0) return eWaifu2xError_InvalidParameter; + const auto StartTime = std::chrono::system_clock::now(); + eWaifu2xError ret; std::call_once(waifu2x_once_flag, [argc, argv]() @@ -424,6 +427,8 @@ eWaifu2xError waifu2x(int argc, char** argv, const std::vector(InitTime).count() + , std::chrono::duration_cast(cuDNNCheckTime).count() + , std::chrono::duration_cast(ProcessTime).count()); + return eWaifu2xError_OK; } diff --git a/common/waifu2x.h b/common/waifu2x.h index 5dc5b6f..7d5a154 100644 --- a/common/waifu2x.h +++ b/common/waifu2x.h @@ -1,5 +1,6 @@ #pragma once +#include #include #include #include @@ -22,6 +23,7 @@ typedef std::pair InputOutputPathPair; typedef std::pair PathAndErrorPair; typedef std::function waifu2xCancelFunc; typedef std::function waifu2xProgressFunc; +typedef std::function waifu2xTimeFunc; bool can_use_cuDNN(); @@ -29,4 +31,4 @@ bool can_use_cuDNN(); // process: cpu or gpu or cudnn eWaifu2xError waifu2x(int argc, char** argv, const std::vector &file_paths, const std::string &mode, const int noise_level, const double scale_ratio, const std::string &model_dir, const std::string &process, - std::vector &errors, const waifu2xCancelFunc cancel_func = nullptr, const waifu2xProgressFunc progress_func = nullptr); + std::vector &errors, const waifu2xCancelFunc cancel_func = nullptr, const waifu2xProgressFunc progress_func = nullptr, const waifu2xTimeFunc time_func = nullptr); diff --git a/waifu2x-caffe-gui/Resource.rc b/waifu2x-caffe-gui/Resource.rc index 87e5205..fed00cc 100644 Binary files a/waifu2x-caffe-gui/Resource.rc and b/waifu2x-caffe-gui/Resource.rc differ diff --git a/waifu2x-caffe-gui/Source.cpp b/waifu2x-caffe-gui/Source.cpp index 846bdb4..f7b17ec 100644 --- a/waifu2x-caffe-gui/Source.cpp +++ b/waifu2x-caffe-gui/Source.cpp @@ -17,6 +17,7 @@ #define WM_FAILD_CREATE_DIR (WM_APP + 5) #define WM_END_WAIFU2X (WM_APP + 6) #define WM_END_THREAD (WM_APP + 7) +#define WM_TIME_WAIFU2X (WM_APP + 8) const size_t AR_PATH_MAX(1024); @@ -82,6 +83,13 @@ private: std::string autoSetAddName; bool isLastError; + struct stWaifu2xTime + { + uint64_t InitTime; + uint64_t cuDNNCheckTime; + uint64_t ProcessTime; + }; + private: std::string AddName() const { @@ -264,11 +272,21 @@ private: SendMessage(GetDlgItem(dh, IDC_PROGRESS), PBM_SETPOS, ProgressFileNow, 0); }; + const auto TimeFunc = [this](const uint64_t InitTime, const uint64_t cuDNNCheckTime, const uint64_t ProcessTime) + { + stWaifu2xTime t; + t.InitTime = InitTime; + t.cuDNNCheckTime = cuDNNCheckTime; + t.ProcessTime = ProcessTime; + + SendMessage(dh, WM_TIME_WAIFU2X, (WPARAM)&t, 0); + }; + std::vector errors; const eWaifu2xError ret = waifu2x(__argc, __argv, file_paths, mode, noise_level, scale_ratio, "models", process, errors, [this]() { return cancelFlag; - }, ProgessFunc); + }, ProgessFunc, TimeFunc); SendMessage(dh, WM_END_WAIFU2X, (WPARAM)&ret, (LPARAM)&errors); @@ -347,6 +365,43 @@ public: MessageBeep(MB_ICONASTERISK); } + void Waifu2xTime(HWND hWnd, WPARAM wParam, LPARAM lParam, LPVOID lpData) + { + const stWaifu2xTime *tp = (const stWaifu2xTime *)wParam; + + char msg[1024*2]; + char *ptr = msg; + + { + uint64_t t = tp->ProcessTime; + const int msec = t % 1000; t /= 1000; + const int sec = t % 60; t /= 60; + const int min = t % 60; t /= 60; + const int hour = (int)t; + ptr += sprintf(ptr, "処理時間: %02d:%02d:%02d.%d\r\n", hour, min, sec, msec); + } + + { + uint64_t t = tp->InitTime; + const int msec = t % 1000; t /= 1000; + const int sec = t % 60; t /= 60; + const int min = t % 60; t /= 60; + const int hour = (int)t; + ptr += sprintf(ptr, "初期化時間: %02d:%02d:%02d.%d\r\n", hour, min, sec, msec); + } + + { + uint64_t t = tp->cuDNNCheckTime; + const int msec = t % 1000; t /= 1000; + const int sec = t % 60; t /= 60; + const int min = t % 60; t /= 60; + const int hour = (int)t; + ptr += sprintf(ptr, "cuDNNチェック時間: %02d:%02d:%02d.%d", hour, min, sec, msec); + } + + SetWindowTextA(GetDlgItem(hWnd, IDC_EDIT_LOG), msg); + } + void OnDialogEnd(HWND hWnd, WPARAM wParam, LPARAM lParam, LPVOID lpData) { if (!processThread.joinable()) @@ -594,6 +649,7 @@ int WINAPI WinMain(HINSTANCE hInstance, cDialog.SetEventCallBack(SetClassFunc(DialogEvent::OnFaildCreateDir, &cDialogEvent), NULL, WM_FAILD_CREATE_DIR); cDialog.SetEventCallBack(SetClassFunc(DialogEvent::OnEndWaifu2x, &cDialogEvent), NULL, WM_END_WAIFU2X); cDialog.SetEventCallBack(SetClassFunc(DialogEvent::WaitThreadExit, &cDialogEvent), NULL, WM_END_THREAD); + cDialog.SetEventCallBack(SetClassFunc(DialogEvent::Waifu2xTime, &cDialogEvent), NULL, WM_TIME_WAIFU2X); // ダイアログを表示 cDialog.DoModal(hInstance, IDD_DIALOG); diff --git a/waifu2x-caffe-gui/resource.h b/waifu2x-caffe-gui/resource.h index 50d8ac4..eff5780 100644 Binary files a/waifu2x-caffe-gui/resource.h and b/waifu2x-caffe-gui/resource.h differ