This is the mail archive of the
systemtap@sourceware.org
mailing list for the systemtap project.
Script run makes the system to hang
- From: beginner966 <nitin966 at gmail dot com>
- To: systemtap at sourceware dot org
- Date: Sun, 1 Mar 2009 03:11:00 -0800 (PST)
- Subject: Script run makes the system to hang
Hi all,
I had written this script to gather the time spent by a task in the
runqueue. It runs fine for 1-2 ms or so(short time I mean). But whenever I
try to run it without an exit() in timer function, my system hangs.
Please suggest some help regarding this matter as to how to make this script
run for infinite amount of time and provide useful statistics.
#!/usr/bin/env stap
/*
* Global variable declaration
*/
global runqueuetime
global runnabletime
global cputime
global oncputime
global tstamp
global names
global start
probe timer.ms(11)
{
exit();
}
probe kernel.function("finish_task_switch")
{
if($prev->state==0 && $prev->tgid)
runnabletime[$prev->tgid,$prev->pid]=gettimeofday_us();
}
probe kernel.mark("_ctx_switch_done")
{
if($arg6)
{
if($arg3)
names[$arg3]=$arg1;
names[$arg6]=$arg4;
if(!runnabletime[$arg6,$arg5])
runnabletime[$arg6,$arg5]=start;
ttime=gettimeofday_us();
runqueuetime[$arg6,$arg5] += ttime - runnabletime[$arg6,$arg5];
oncputime[$arg6,$arg5]=ttime;
}
}
/*
* Catch the transition from (task_struct *)p->state to TASK_RUNNING state;
Process added in runqueue or really running
*/
probe kernel.function("activate_task")
{
if($p->tgid)
runnabletime[$p->tgid,$p->pid]=gettimeofday_us();
}
/*
* Catch the transition from TASK->RUNNING to (task_struct *)p->state;
Process removed from CPU, in runqueue or some other state
*/
probe kernel.function("deactivate_task")
{
if($p->tgid)
{
if(!oncputime[$p->tgid,$p->pid])
oncputime[$p->tgid,$p->pid]=start;
cputime[$p->tgid,$p->pid] += gettimeofday_us() -
oncputime[$p->tgid,$p->pid];
}
}
/*
* Process has died and perfom the cleanup; Transition: (task_struct
*)p->state to Cleaned
*/
probe kernel.function("release_task").return
{
printf("%-15s %-6d %-6d %-15d
%-15d\n",names[$p->tgid],$p->tgid,$p->pid,cputime[$p->tgid,$p->pid],runqueuetime[$p->tgid,$p->pid]);
delete runqueuetime[$p->tgid,$p->pid];
delete cputime[$p->tgid,$p->pid];
}
probe timer.ms(5)
{
//start=gettimeofday_us();
tstamp=5;
printf("Cumulative statistics for processes on all CPUs for last %d msec :
\n",tstamp);
printf("\n\n\t%-15s %-6s %-6s %-15s
%-15s\n","Process","Pid","Tid","Cpu_Time(us)","Runqueue_Time(us)");
printf("\t%-15s %-6s %-6s %-15s
%-15s\n","-------","---","---","------------","-----------------");
tstamp=0;
foreach ([pid+,tid] in runqueuetime)
{
if(!pid)
{
//continue;
printf("\t%-15s %-6d %-6d %-15d
%-15d\n","Swapper",pid,tid,cputime[pid,tid],runqueuetime[pid,tid]);
}
else
{
printf("\t%-15s %-6d %-6d %-15d
%-15d\n",names[pid],pid,tid,cputime[pid,tid],runqueuetime[pid,tid]);
}
/*tstamp+=1;
if(tstamp==10)
break;*/
}
//delete cputime;
//delete runqueuetime;
//delete names;
printf("\n\n");
}
/*
* Take a process id from user and print its corresponding detail
*/
probe begin
{
start=gettimeofday_us();
print("Collecting data for all processes ... Press Ctrl-C to display
results and exit\n\n\n");
}
/*
* Perform clean up
*/
probe end
{
printf("\n\n");
delete cputime;
delete runqueuetime;
}
--
View this message in context: http://www.nabble.com/Script-run-makes-the-system-to-hang-tp22271687p22271687.html
Sent from the Sourceware - systemtap mailing list archive at Nabble.com.