Monitoring cpu time in us (or even ns?)

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Monitoring cpu time in us (or even ns?)

corpaul
I am probably completely overlooking this in the docs, but how can I monitor the time spent within a function?
I have tried using task_utime() and task_stime() but these appear to give results in ms, which is not fine enough granularity for me. How can I get these times in us or even ns?

Thanks, Cor-Paul
Reply | Threaded
Open this post in threaded view
|

Re: Monitoring cpu time in us (or even ns?)

Frank Ch. Eigler

c.bezemer wrote:

> I am probably completely overlooking this in the docs, but how can I
> monitor the time spent within a function?

One general approach is to have a function.return probe that measures
elapsed time with something like

        probe FOO.function(BAR).return {
              time_spent_within_function = gettimeofday_us()-
                                    @entry(gettimeofday_us())
              /* ... */
        }

> I have tried using task_utime() and task_stime() but these appear to
> give results in ms

Those functions return the values as stored by the kernel; systemtap
is not rounding them off.

> [...] How can I get these times in us or even ns?

(At times so small, the probe effect (q.v.) will impact measurements.)

- FChE
Reply | Threaded
Open this post in threaded view
|

RE: Monitoring cpu time in us (or even ns?)

corpaul
Thanks - I thought using the gettimeofday* functions for measuring cpu time are inappropriate as they represent the time the function uses the CPU plus the time the function is waiting for other functions?

--CP
________________________________________
From: Frank Ch. Eigler [[hidden email]]
Sent: Tuesday, October 22, 2013 8:48 PM
To: Cor-paul Bezemer - EWI
Cc: [hidden email]
Subject: Re: Monitoring cpu time in us (or even ns?)

c.bezemer wrote:

> I am probably completely overlooking this in the docs, but how can I
> monitor the time spent within a function?

One general approach is to have a function.return probe that measures
elapsed time with something like

        probe FOO.function(BAR).return {
              time_spent_within_function = gettimeofday_us()-
                                    @entry(gettimeofday_us())
              /* ... */
        }

> I have tried using task_utime() and task_stime() but these appear to
> give results in ms

Those functions return the values as stored by the kernel; systemtap
is not rounding them off.

> [...] How can I get these times in us or even ns?

(At times so small, the probe effect (q.v.) will impact measurements.)

- FChE
Reply | Threaded
Open this post in threaded view
|

Re: Monitoring cpu time in us (or even ns?)

Frank Ch. Eigler

C.Bezemer wrote:

> Thanks - I thought using the gettimeofday* functions for measuring
> cpu time are inappropriate as they represent the time the function
> uses the CPU plus the time the function is waiting for other
> functions?

The gettimeofday* functions snapshot estimates of then-current time.
What matters is when those snapshots are taken and the arithmetic
performed on them.  If you want to measure elapsed time for a function
(including its callees), then subtract $before from $after, and that's
it.

If you want to exclude callees' time, it's a much more difficult
problem (many more events to track - many more time snapshots to
add/subtract), and you'd probably be better off using sampling-based
techniques.

- FChE