/* * procsystime - print process system call time details. Written using * DTrace (Solaris 10 3/05). * * 22-Sep-2005, ver 1.10 * * Macro arguments: Process ID defaults to 0 (all PIDs) * Process Name defaults to "" (all processes) * Command run and examine target command * * The elapsed times are interesting, to help identify syscalls that * take some time to complete (during which the process may have slept). * CPU time helps us identify syscalls that are consuming CPU cycles to * run. * * FIELDS: * SYSCALL System call name * TIME (ns) Total time, nanoseconds * COUNT Number of occurrences * * COPYRIGHT: Copyright (c) 2005 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. * * You can obtain a copy of the license at Docs/cddl1.txt or * http://www.opensolaris.org/os/licensing. See the License for the * specific language governing permissions and limitations under the * License. * * CDDL HEADER END * * Author: Brendan Gregg [Sydney, Australia] * 27-Apr-2005 Brendan Gregg Created this. * 08-Jun-2005 " " Added command option. * 22-Sep-2005 " " Allowed systemwide tracing. * 08-Jan-2007 Tom Erickson Adapted for use with Chime. */ inline string NAME = $$1; inline int PID = $2; inline int OPT_pid = (PID > 0); inline int OPT_name = (NAME != ""); inline int OPT_command = ($target > 0); inline int OPT_filter = (OPT_pid || OPT_name || OPT_command); dtrace:::BEGIN { self->start = 0; self->vstart = 0; } /* * Set start timestamp and counts */ syscall:::entry /((pid != $pid) && ((! OPT_filter) || (OPT_pid && pid == PID) || (OPT_name && execname == NAME) || (OPT_command && pid == $target)))/ { self->ok = 1; } syscall:::entry /self->ok/ { @Counts[probefunc] = count(); self->start = timestamp; self->vstart = vtimestamp; self->ok = 0; } /* * Calculate time deltas */ syscall:::return /self->start/ { this->elapsed = timestamp - self->start; @Elapsed[probefunc] = sum(this->elapsed); self->start = 0; } syscall:::return /self->vstart/ { this->cpu = vtimestamp - self->vstart; @CPU[probefunc] = sum(this->cpu); self->vstart = 0; }