Hello,
I would like to know, how can I measure time so as it always gives me
the difference between "now" and "start_of_process/thread" time,
regardless of whether the process/thread is running, sleeping or doing
whatever else...
I don't need a high accuracy resolution, milliseconds will be enough.
To what I know, both clock() and clock_gettime() (with id
CLOCK_PROCESS_CPUTIME_ID or CLOCK_THREAD_CPUTIME_ID) provide "correct"
results only in case of running process/thread. That means, whenever I
use a (nano)sleep(), the results are going to be affected by that.
Well, and I need to note that using gettimeofday() or similar
functions is not convenient, since the system time can be changed at
any time of my app running.
Thanks a lot in advance.
|
|
0
|
|
|
|
Reply
|
marcel.balas (2)
|
3/24/2009 12:21:00 PM |
|
kakofony <marcel.balas@gmail.com> writes:
> I would like to know, how can I measure time so as it always gives me
> the difference between "now" and "start_of_process/thread" time,
> regardless of whether the process/thread is running, sleeping or doing
> whatever else...
> I don't need a high accuracy resolution, milliseconds will be enough.
>
> To what I know, both clock() and clock_gettime() (with id
> CLOCK_PROCESS_CPUTIME_ID or CLOCK_THREAD_CPUTIME_ID) provide "correct"
> results only in case of running process/thread. That means, whenever I
> use a (nano)sleep(), the results are going to be affected by that.
>
> Well, and I need to note that using gettimeofday() or similar
> functions is not convenient, since the system time can be changed at
> any time of my app running.
Provided that you can 'live as a timeless island', which is likely,
given your statement above, use CLOCK_MONOTONIC.
|
|
0
|
|
|
|
Reply
|
rweikusat (2683)
|
3/24/2009 12:43:41 PM
|
|
On 2009-03-24, kakofony <marcel.balas@gmail.com> wrote:
> Hello,
>
> I would like to know, how can I measure time so as it always gives me
> the difference between "now" and "start_of_process/thread" time,
> regardless of whether the process/thread is running, sleeping or doing
> whatever else...
> I don't need a high accuracy resolution, milliseconds will be enough.
> To what I know, both clock() and clock_gettime() (with id
> CLOCK_PROCESS_CPUTIME_ID or CLOCK_THREAD_CPUTIME_ID) provide "correct"
> results only in case of running process/thread. That means, whenever I
> use a (nano)sleep(), the results are going to be affected by that.
>
> Well, and I need to note that using gettimeofday() or similar
> functions is not convenient, since the system time can be changed at
> any time of my app running.
#include <time.h>
struct timespec ts;
clock_gettime(TIME_MONOTINIC,&ts);
|
|
0
|
|
|
|
Reply
|
jasen (107)
|
3/26/2009 9:43:27 AM
|
|
I forgot to thank you. MONOTONIC works great.
|
|
0
|
|
|
|
Reply
|
marcel.balas (2)
|
4/8/2009 7:10:34 AM
|
|
|
3 Replies
47 Views
(page loaded in 0.119 seconds)
|