1N/A# sampleproc - sample processes on the CPUs. 1N/A# Written using DTrace (Solaris 10 3/05). 1N/A# This program samples which process is on each CPU, at a particular 1N/A# configurable rate. This can be used as an estimate for which process 1N/A# is consuming the most CPU time. 1N/A# $Id: sampleproc 8 2007-08-06 05:55:26Z brendan $ 1N/A# USAGE: sampleproc [hertz] # hit Ctrl-C to end sample 1N/A# COMMAND Command name 1N/A# COUNT Number of samples 1N/A# PERCENT Percent of CPU usage 1N/A# PORTIONS: 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# 09-Jun-2005 Brendan Gregg Created this. 1N/A# 09-Jul-2005 " " Last update. 1N/A USAGE: sampleproc [hertz] 1N/A sampleproc # defaults to 100 hertz 1N/A sampleproc 1000 # 1000 hertz 1N/A### Process arguments 1N/Aif (( $# == 0 )); then 1N/Aelif (( $# == 1 )); then 1N/A if [[ "$hertz" = *[a-zA-Z]* ]]; then 1N/A print "ERROR2: $hertz hertz is invalid." >&2 1N/A if (( hertz > 5000 )); then 1N/A print "ERROR3: $hertz hertz is too fast (max 5000)." >&2 1N/A if (( hertz < 1 )); then 1N/A print "ERROR4: $hertz hertz is too low (min 1)." >&2 1N/A/usr/sbin/dtrace -n ' 1N/A #pragma D option quiet 1N/A printf("Sampling at %d hertz... Hit Ctrl-C to end.\n",$1); 1N/A self->start = timestamp; 1N/A profile:::profile-$1 1N/A @Proc[pid, execname] = count(); 1N/A @BigProc[pid, execname] = sum(1000); /* dont ask */ 1N/A this->end = timestamp; 1N/A printf("%5s %-20s %10s\n", "PID", "CMD", "COUNT"); 1N/A printa("%5d %-20s %10@d\n", @Proc); 1N/A ((`ncpus_online * $1 * (this->end - self->start))/100000000)); 1N/A printf("\n%5s %-20s %10s\n", "PID", "CMD", "PERCENT"); 1N/A printa("%5d %-20s %10@d\n", @BigProc);