28 #ifndef SIGNAL_STATUS_REPORT
29 #define SIGNAL_STATUS_REPORT
60 virtual void handle_signal(
int) = 0;
66 template<
typename TaskDispatcher,
typename Logger,
typename TimerClock = std::chrono::system_clock>
70 : tasks(tasks_), logger(logger_), time_start()
72 tasks->set_status_report_handler(
73 [
this](
const typename TaskDispatcher::FullStatusReportType& report) {
74 logger.debug(
"SigHandlerStatusReporter/lambda",
"intermediate progress report lambda called");
79 TaskDispatcher * tasks;
82 typename TimerClock::time_point time_start;
84 virtual void handle_signal(
int )
86 tasks->request_status_report();
97 "=========================== Intermediate Progress Report ============================\n"
98 " (hit Ctrl+C quickly again to interrupt)\n"
99 " Total Completed Runs: %d/%d: %5.2f%%\n"
100 " %s total elapsed\n"
101 "Current Run(s) information (threads working/spawned %d/%d):\n",
102 report.num_completed, report.num_total_runs,
103 (
double)report.num_completed/report.num_total_runs*100.0,
104 elapsed.
c_str(), report.num_active_working_threads,
114 for (
int k = 0; k < report.num_threads; ++k) {
119 fprintf(stderr,
"=== Thread #%2d: %s\n", k, msg.
c_str());
122 "=====================================================================================\n\n");
127 template<
typename TaskDispatcher,
typename LoggerT>
128 SigHandlerTaskDispatcherStatusReporter<TaskDispatcher, LoggerT>
129 makeSigHandlerTaskDispatcherStatusReporter(TaskDispatcher * tasks, LoggerT & logger)
132 return SigHandlerTaskDispatcherStatusReporter<TaskDispatcher, LoggerT>(tasks, logger);
138 #ifndef SIG_STATUS_REPORT_REPEAT_EXIT_DELAY
139 #define SIG_STATUS_REPORT_REPEAT_EXIT_DELAY 2
142 namespace tomo_internal {
144 static SignalHandler * signal_handler = NULL;
146 void signal_dispatch_fn(
int signal)
151 if ( (now - tomo_internal::last_sig_hit_time) < SIG_STATUS_REPORT_REPEAT_EXIT_DELAY ) {
157 tomo_internal::last_sig_hit_time = now;
159 if (signal_handler != NULL) {
160 signal_handler->handle_signal(signal);
162 fprintf(stderr,
"Warning: sig_handle: no signal handler set (got signal %d)\n", signal);
177 template<
typename SigHandler>
180 tomo_internal::signal_handler = sobj;
181 signal(signum, tomo_internal::signal_dispatch_fn);
Base namespace for the Tomographer project.