/*
* shortlived.d - determine time spent by short lived processes.
* Written in DTrace (Solaris 10 3/05).
*
* $Id: shortlived.d 3 2007-08-01 10:50:08Z brendan $
*
* USAGE: shortlived.d # wait, then hit Ctrl-C
*
* Applications that run many short lived processes can cause load
* on the system that is difficult to identify - the processes
* aren't sampled in time by programs such as prstat. This program
* illustrates how much time was spent processing those extra
* processes, and a table of process name by total times for each.
*
* SEE ALSO: execsnoop
*
* Notes:
* - The measurements are minimum values, not all of the overheads
* caused by process generation and destruction are measured (DTrace
* can do so, but the script would become seriously complex).
* - The summary values are accurate, the by program and by PPID values
* are usually slightly smaller due to rounding errors.
*
* COPYRIGHT: Copyright (c) 2005, 2006 Brendan Gregg.
*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* See the License for the specific language governing permissions
* and limitations under the License.
*
* CDDL HEADER END
*
* 22-Apr-2005 Brendan Gregg Created this.
* 20-Apr-2006 " " Last update.
*/
/*
* Start
*/
{
/* save start time */
/* this is time spent on shortlived processes */
procs = 0;
/* print header */
printf("Tracing... Hit Ctrl-C to stop.\n");
}
/*
* Measure parent fork time
*/
{
/* save start of fork */
}
{
/* record elapsed time for the fork syscall */
}
/*
* Measure child processes time
*/
/arg0 == 0/
{
/* save start of child process */
/* memory cleanup */
}
{
/* record elapsed time for process execution */
/* sum elapsed by process name and ppid */
/* memory cleanup */
}
/*
* Print report
*/
{
printf("short lived processes: %6d.%03d secs\n",
printf("total sample duration: %6d.%03d secs\n",
printf("\nTotal time by process name,\n");
printf("\nTotal time by PPID,\n");
}