diff options
author | Toni Uhlig <matzeton@googlemail.com> | 2018-09-23 09:14:22 +0200 |
---|---|---|
committer | Toni Uhlig <matzeton@googlemail.com> | 2018-09-23 09:14:22 +0200 |
commit | 5251665d3fab40d01d953e43e7362e14e974744f (patch) | |
tree | c992cca7c9d360c45f21343469d1ceeee410ae9c /src | |
parent | 87ec513d57b4865db7008a3c14b5ff2425ed855e (diff) |
print total, success and failed updates in a windows status log
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/UpdateGUI.cpp | 78 | ||||
-rw-r--r-- | src/UpdateGUI.hpp | 7 |
2 files changed, 56 insertions, 29 deletions
diff --git a/src/UpdateGUI.cpp b/src/UpdateGUI.cpp index 20dee20..e153d16 100644 --- a/src/UpdateGUI.cpp +++ b/src/UpdateGUI.cpp @@ -283,6 +283,7 @@ void UpdateGUIFrame::OnImportCSV(wxCommandEvent& event) /* add all csv jobs to the job queue */ jobid = rand(); for (auto *u : uf) { + totalUpdates++; jobs->AddJob(Job(Job::eID_THREAD_JOB, JobArgs(jobid, *u))); jobid++; delete u; @@ -314,6 +315,7 @@ void UpdateGUIFrame::OnUpdate(wxCommandEvent& event) /* add all jobs to the job queue */ int jobid = rand(); for (auto *u : uf) { + totalUpdates++; std::ostringstream log; log << "Update started ... (Job: #" << jobid << ")"; tLog(RTL_DEFAULT, log.str().c_str()); @@ -374,37 +376,29 @@ void UpdateGUIFrame::OnThread(wxCommandEvent& event) } /* process the wx event itself */ + wxs = wxString::Format(wxT("Thread [%i]: %s"), event.GetInt(), event.GetString().c_str()); switch (event.GetId()) { - case Job::eID_THREAD_JOB: + /* case Job::eID_THREAD_JOB: SetStatusText(wxs); break; */ + case Job::eID_THREAD_MSG: break; + case Job::eID_THREAD_MSGOK: SetStatusText(wxs); tp = RTL_GREEN; break; + case Job::eID_THREAD_MSGERR: successUpdates--; tp = RTL_RED; break; case Job::eID_THREAD_JOB_DONE: - case Job::eID_THREAD_MSG: - case Job::eID_THREAD_MSGOK: - case Job::eID_THREAD_MSGERR: - wxs = wxString::Format(wxT("Thread [%i]: %s"), event.GetInt(), event.GetString().c_str()); - - switch (event.GetId()) { - case Job::eID_THREAD_JOB_DONE: - /* calculate job execution times (total/average/estimated) */ - jobReport = dynamic_cast<JobReport *>(event.GetClientObject()); - std::tie (avgJobTime, totJobTime, estTotalJobTime) = calcJobTimingsAvgTotEst(*jobs, threads.size(), *jobReport, jobTimings); - /* If more then one job was in the queue - * inform the user about job completion, - * otherwise reset completed job counter. - */ - if (jobs->Stacksize() == 0 && jobs->getBusyWorker() == 0) { - if (jobs->getTotalJobsDone() > 1) - allJobsDone = true; - jobs->resetTotalJobsDone(); - } else { - SetStatusText(wxString::Format(wxT("Jobs remaining: %u, estimated remaining time: %umin"), - jobs->Stacksize() + jobs->getBusyWorker(), estTotalJobTime)); - } - break; - case Job::eID_THREAD_JOB: SetStatusText(wxs); break; - case Job::eID_THREAD_MSGOK: SetStatusText(wxs); tp = RTL_GREEN; break; - case Job::eID_THREAD_MSGERR: tp = RTL_RED; break; + successUpdates++; + /* calculate job execution times (total/average/estimated) */ + jobReport = dynamic_cast<JobReport *>(event.GetClientObject()); + std::tie (avgJobTime, totJobTime, estTotalJobTime) = calcJobTimingsAvgTotEst(*jobs, threads.size(), *jobReport, jobTimings); + /* If more then one job was in the queue + * inform the user about job completion, + * otherwise reset completed job counter. + */ + if (jobs->Stacksize() == 0 && jobs->getBusyWorker() == 0) { + if (jobs->getTotalJobsDone() > 1) + allJobsDone = true; + jobs->resetTotalJobsDone(); + } else { + SetStatusText(wxString::Format(wxT("Jobs remaining: %u, estimated remaining time: %umin"), + jobs->Stacksize() + jobs->getBusyWorker(), estTotalJobTime)); } - tLog(tp, wxs); break; case Job::eID_THREAD_EXIT: /* should only be run once per thread and only if the app exits */ @@ -419,14 +413,40 @@ void UpdateGUIFrame::OnThread(wxCommandEvent& event) default: event.Skip(); } + /* output the wxString in the status log */ + switch (event.GetId()) { + case Job::eID_THREAD_JOB: + case Job::eID_THREAD_JOB_DONE: + case Job::eID_THREAD_MSG: + case Job::eID_THREAD_MSGOK: + case Job::eID_THREAD_MSGERR: + tLog(tp, wxs); + break; + default: + break; + } + /* job queue is now empty and had more than one job */ if (allJobsDone) { counter = 0; /* we presume that threads.size() jobs ran at the same time */ - wxs = wxString::Format(wxT("All jobs finished. Time consumption: %umin (average per device: %umin %usec)"), (unsigned)((float)totJobTime + 0.5f) /* roundup */, avgJobTime / 60, avgJobTime % 60); + wxs = wxString::Format(wxT("All jobs finished. Time consumption: %umin " + "(average per device: %umin %usec)"), + (unsigned)((float)totJobTime + 0.5f) /* roundup */, + avgJobTime / 60, avgJobTime % 60); SetStatusText(wxs); tLog(RTL_GREEN, wxs); + /* + * The correct size_t format specifier %zu might not + * be available on older mingw xcompiler, so use %lu. + */ + wxs = wxString::Format(wxT("Total updates: %lu, success: %lu, failed: %lu"), + (unsigned long) getTotalUpdates(), (unsigned long) getSuccessUpdates(), + (unsigned long) (getTotalUpdates() - getSuccessUpdates())); + tLog(RTL_DEFAULT, wxs); jobTimings.clear(); + totalUpdates = 0; + successUpdates = 0; } } diff --git a/src/UpdateGUI.hpp b/src/UpdateGUI.hpp index ab369af..26564ec 100644 --- a/src/UpdateGUI.hpp +++ b/src/UpdateGUI.hpp @@ -55,6 +55,10 @@ private: void OnNavigationKey(wxNavigationKeyEvent& event); void OnThread(wxCommandEvent& event); + /* overall job stats */ + size_t getTotalUpdates() { return this->totalUpdates; } + size_t getSuccessUpdates() { return this->successUpdates; } + wxDECLARE_EVENT_TABLE(); /* GUI elements */ @@ -67,6 +71,9 @@ private: Queue *jobs; /** Thread list IDs */ std::list<int> threads; + + /* stats */ + size_t totalUpdates = 0, successUpdates = 0; }; bool isLicenseAlreadyAccepted(); |