- 论坛徽章:
- 0
|
dtrace:::BEGIN
{
/* save start time */
start = timestamp;
/* this is time spent on shortlived
processes */
procs = 0;
/* print header */
printf("Sampling..
Hit Ctrl-C to stop.\n");
}
syscall::*fork*:entry
{
/* save start of fork */
self->fork = vtimestamp;
}
syscall::*fork*:return
/arg0 != 0 &&
self->fork/
{
/* record elapsed time for the fork syscall */
this->elapsed = vtimestamp -
self->fork;
procs +=
this->elapsed;
self->fork = 0;
}
syscall::*fork*:return
/arg0 == 0/
{
/* save start of child process */
self->start = vtimestamp;
/* memory cleanup */
self->fork = 0;
}
proc:::exit
/self->start/
{
/* record elapsed time for process execution
*/
this->elapsed = vtimestamp -
self->start;
procs +=
this->elapsed;
/* sum elapsed by process name and ppid */
@Times_exec[execname] =
sum(this->elapsed/1000000);
@Times_ppid[ppid] =
sum(this->elapsed/1000000);
/* memory cleanup */
self->start = 0;
}
dtrace:::END
{
/* print report */
this->total = timestamp - start;
printf("short
lived processes: %6d.%03d secs\n",
procs/1000000000,(procs%1000000000)/1000000);
printf("total
sample duration: %6d.%03d secs\n",
this->total/1000000000,(this->total%1000000000)/1000000);
printf("\nTotal time by
process name,\n");
printa("%18s
%@12d ms\n",@Times_exec);
printf("\nTotal time by
PPID,\n");
printa("%18d
%@12d ms\n",@Times_ppid);
}
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u3/91236/showart_1793887.html |
|