2

I want to measure the runtime of a procedure that will last multiple days. This means the executing process will be interrupted many times since the Linux PC will be suspended to standby repeatedly. I don't want to include those sleep phases in my time measurement so I can't use simple time stamps.

Is there a better way to measure the net runtime of a procedure other than firing a QTimer every second and counting those timeouts?

Silicomancer
  • 8,604
  • 10
  • 63
  • 130
  • You could have a look at `boost.timer` -- specifically [`boost::timer::auto_cpu_timer`](https://www.boost.org/doc/libs/1_73_0/libs/timer/doc/cpu_timers.html#Example). – G.M. May 29 '20 at 06:56
  • What kind of procedure is that? Is it an application, script, a function? – vahancho May 29 '20 at 06:58
  • @vahancho: A calculation executed by several worker threads in an application. I would be fine with both, a method to measure the added up time of all threads or a method to measure the absolute time the threads are active (not matter how many threads are working). – Silicomancer May 29 '20 at 07:26
  • @Silicomancer, roughly, I would let each thread count time while it runs individually. If you use `QTimer` just increment counter every second, for example, on `timeout()` signal. After thread is finished, read the counter (seconds) value and store it. Repeat this for all threads. In other words, you should not measure time by subtracting start time from the end time, but count it only when the timer is active. – vahancho May 29 '20 at 07:57
  • @vahancho: Good idea, however while the threads are busy, they do not listen to events and do not enter an event loop. Maybe I could change this, still it would essentially counting periodic events and I hoped there would be a more elegant way. – Silicomancer May 29 '20 at 08:32
  • @G.M. I tried boost's cpu_timer an it works fine. Make your comment an answer so I can accept it. – Silicomancer May 30 '20 at 21:30

1 Answers1

0

As G.M. proposed, I used boost::timer::cpu_timer time to solve my issue. It returns the summed up computation time and the run time of the entire process which is fine for my purpose. Boost is not Qt but it is cross-platform anyway.

Silicomancer
  • 8,604
  • 10
  • 63
  • 130