This is the mail archive of the
systemtap@sourceware.org
mailing list for the systemtap project.
measuring time spend of a process
- From: Frits Hoogland <frits dot hoogland at gmail dot com>
- To: systemtap at sourceware dot org
- Date: Wed, 12 Aug 2009 20:21:10 +0200
- Subject: measuring time spend of a process
I want to measure the real cpu time, time in runqueue, and time in
interruptible and uninterruptible state of a process.
below is my current systemtap script. is this the best way to do that?
(please mind I am using version 0.7.2 which comes with Centos 5.3)
any comments are welcome and appreciated!
frits
--begin--
// Return the task of the given process id
function pid2task:long (pid:long) %{ /* pure */
struct task_struct *t = NULL;
pid_t t_pid = (pid_t)(long)THIS->pid;
rcu_read_lock();
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
t = find_task_by_vpid (t_pid);
#else
t = find_task_by_pid (t_pid);
#endif
rcu_read_unlock();
THIS->__retvalue = (long)t;
CATCH_DEREF_FAULT();
%}
global task
global prev_time_us
global running, interruptible, uninterruptible
global start_cpu_time, on_cpu_time
global slices, start_time
probe begin{
task=pid2task(target())
printf("Start of profile of pid: %d, task: %d\n", target(), task )
start_time=gettimeofday_us()
prev_time_us=gettimeofday_us()
}
probe timer.profile {
if( task_state( task ) == 0 ) {
running += gettimeofday_us() - prev_time_us
} else if( task_state( task ) == 1 ) {
interruptible += gettimeofday_us() - prev_time_us
} else if( task_state( task ) == 2 ) {
uninterruptible += gettimeofday_us() - prev_time_us
}
prev_time_us=gettimeofday_us()
}
probe scheduler.cpu_on {
if( pid() == target() ) {
start_cpu_time=gettimeofday_us()
slices++
}
}
probe scheduler.cpu_off {
if( pid() == target() ) {
if( start_cpu_time != 0 ) {
on_cpu_time += gettimeofday_us()-start_cpu_time
}
}
}
probe end{
printf("Pid: %d, running total %d, running cpu %d, running
queue %d, inter %d, uninter %d, total time %d (%d), slices %d,
ave/slice %d\n", target(), running, on_cpu_time, running-on_cpu_time,
interruptible, uninterruptible, gettimeofday_us()-start_time,
running+interruptible+uninterruptible, slices, on_cpu_time/slices)
}
--end--