1N/A# procsystime - print process system call time details. 1N/A# Written using DTrace (Solaris 10 3/05). 1N/A# $Id: procsystime 4 2007-08-01 11:01:38Z brendan $ 1N/A# USAGE: procsystime [-acehoT] [ -p PID | -n name | command ] 1N/A# -p PID # examine this PID 1N/A# -n name # examine this process name 1N/A# -a # print all details 1N/A# -c # print syscall counts 1N/A# -e # print elapsed times 1N/A# -o # print CPU times 1N/A# procsystime -p 1871 # examine PID 1871 1N/A# procsystime -n tar # examine processes called "tar" 1N/A# procsystime -aTn bash # print all details for bash shells 1N/A# procsystime df -h # run and examine "df -h" 1N/A# The elapsed times are interesting, to help identify syscalls that take 1N/A# some time to complete (during which the process may have slept). CPU time 1N/A# helps us identify syscalls that are consuming CPU cycles to run. 1N/A# SYSCALL System call name 1N/A# TIME (ns) Total time, nanoseconds 1N/A# COUNT Number of occurrences 1N/A# COPYRIGHT: Copyright (c) 2005 Brendan Gregg. 1N/A# The contents of this file are subject to the terms of the 1N/A# Common Development and Distribution License, Version 1.0 only 1N/A# (the "License"). You may not use this file except in compliance 1N/A# See the License for the specific language governing permissions 1N/A# and limitations under the License. 1N/A# Author: Brendan Gregg [Sydney, Australia] 1N/A# 27-Apr-2005 Brendan Gregg Created this. 1N/A# 08-Jun-2005 " " Added command option. 1N/A# 22-Sep-2005 " " Allowed systemwide tracing. 1N/A# 22-Sep-2005 " " Last update. 1N/A############################## 1N/A# --- Process Arguments --- 1N/A### Default variables 1N/A USAGE: procsystime [-aceho] [ -p PID | -n name | command ] 1N/A -p PID # examine this PID 1N/A -n name # examine this process name 1N/A -a # print all details 1N/A -e # print elapsed times 1N/A -c # print syscall counts 1N/A -o # print CPU times 1N/A procsystime -p 1871 # examine PID 1871 1N/A procsystime -n tar # examine processes called "tar" 1N/A procsystime -aTn bash # print all details for bash 1N/A procsystime df -h # run and examine "df -h" 1N/Ashift `expr $OPTIND - 1` 1N/Aif [ $opt_pid -eq 0 -a $opt_name -eq 0 -a "$*" != "" ]; then 1N/Aif [ $opt_elapsed -eq 0 -a $opt_cpu -eq 0 -a $opt_counts -eq 0 ]; then 1N/A################################# 1N/A# --- Main Program, DTrace --- 1N/A #pragma D option quiet 1N/A * Command line arguments 1N/A inline int OPT_elapsed = '$opt_elapsed'; 1N/A inline int OPT_cpu = '$opt_cpu'; 1N/A inline int OPT_counts = '$opt_counts'; 1N/A inline int OPT_filter = '$opt_filter'; 1N/A inline int OPT_pid = '$opt_pid'; 1N/A inline int OPT_name = '$opt_name'; 1N/A inline int OPT_totals = '$opt_totals'; 1N/A inline int OPT_command = '$opt_command'; 1N/A inline int PID = '$pid'; 1N/A inline string NAME = "'$pname'"; 1N/A inline string COMMAND = "'$command'"; 1N/A printf("Tracing... Hit Ctrl-C to end...\n"); 1N/A * Set start timestamp and counts 1N/A (OPT_pid && pid == PID) || 1N/A (OPT_name && execname == NAME) || 1N/A (OPT_command && pid == $target)/ 1N/A OPT_counts ? @Counts[probefunc] = count() : 1; 1N/A (OPT_counts && OPT_totals) ? @Counts["TOTAL:"] = count() : 1; 1N/A OPT_elapsed ? self->start = timestamp : 1; 1N/A OPT_cpu ? self->vstart = vtimestamp : 1; 1N/A * Calculate time deltas 1N/A this->elapsed = timestamp - self->start; 1N/A @Elapsed[probefunc] = sum(this->elapsed); 1N/A OPT_totals ? @Elapsed["TOTAL:"] = sum(this->elapsed) : 1; 1N/A this->cpu = vtimestamp - self->vstart; 1N/A @CPU[probefunc] = sum(this->cpu); 1N/A OPT_totals ? @CPU["TOTAL:"] = sum(this->cpu) : 1; 1N/A * Elapsed time report 1N/A printf("\nElapsed Times for "); 1N/A OPT_pid ? printf("PID %d,\n\n",PID) : 1; 1N/A OPT_name ? printf("processes %s,\n\n",NAME) : 1; 1N/A OPT_command ? printf("command %s,\n\n",COMMAND) : 1; 1N/A (! OPT_filter) ? printf("all processes,\n\n") : 1; 1N/A printf("%16s %18s\n","SYSCALL","TIME (ns)"); 1N/A printa("%16s %@18d\n",@Elapsed); 1N/A printf("\nCPU Times for "); 1N/A OPT_pid ? printf("PID %d,\n\n",PID) : 1; 1N/A OPT_name ? printf("processes %s,\n\n",NAME) : 1; 1N/A OPT_command ? printf("command %s,\n\n",COMMAND) : 1; 1N/A (! OPT_filter) ? printf("all processes,\n\n") : 1; 1N/A printf("%16s %18s\n","SYSCALL","TIME (ns)"); 1N/A printa("%16s %@18d\n",@CPU); 1N/A * Syscall count report 1N/A printf("\nSyscall Counts for "); 1N/A OPT_pid ? printf("PID %d,\n\n",PID) : 1; 1N/A OPT_name ? printf("processes %s,\n\n",NAME) : 1; 1N/A OPT_command ? printf("command %s,\n\n",COMMAND) : 1; 1N/A (! OPT_filter) ? printf("all processes,\n\n") : 1; 1N/A printf("%16s %18s\n","SYSCALL","COUNT"); 1N/A OPT_counts ? printa("%16s %@18d\n",@Counts) : 1; 1N/Aif [ $opt_command -eq 1 ]; then 1N/A /usr/sbin/dtrace -n "$dtrace" -x evaltime=exec -c "$command" >&2 1N/A /usr/sbin/dtrace -n "$dtrace" >&2