* measuring time spend of a process
@ 2009-08-12 18:21 Frits Hoogland
0 siblings, 0 replies; only message in thread
From: Frits Hoogland @ 2009-08-12 18:21 UTC (permalink / raw)
To: systemtap
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--
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2009-08-12 18:21 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-08-12 18:21 measuring time spend of a process Frits Hoogland
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).