#!/usr/bin/sh # # topsyscall - display top system call type. # Written using DTrace (Solaris 10 3/05). # # This program continually prints a report of the top system calls, # and refreshes the display every 1 second or as specified at the # command line. # # 13-Jun-2005, ver 0.80 # # USAGE: topsyscall [interval] # # FIELDS: # # load avg load averages, see uptime(1) # syscalls total number of syscalls in this interval # SYSCALL system call name # COUNT number of occurances in this interval # # SEE ALSO: prstat(1M) # # INSPIRATION: top(1) by William LeFebvre # # Standard Disclaimer: This is freeware, use at your own risk. # # 13-Jun-2005 Brendan Gregg Created this. # # # Check options # if [ "$1" = "-h" -o "$1" = "--help" ]; then cat <<-END USAGE: topsyscall [interval] eg, topsyscall # default, 1 second updates topsyscall 5 # 5 second updates END exit 1 fi interval=1 if [ "$1" -gt 0 ]; then interval=$1 fi # # Run DTrace # /usr/sbin/dtrace -n ' #pragma D option quiet #pragma D option destructive /* constants */ inline int INTERVAL = '$interval'; inline int SCREEN = 20; /* variables */ dtrace:::BEGIN { secs = 0; printf("Sampling... Please wait.\n"); } /* record syscall event */ syscall:::entry { @Name[probefunc] = count(); @Total = count(); } /* update screen */ profile:::tick-1sec /++secs >= INTERVAL/ { /* fetch load averages */ this->load1a = `hp_avenrun[0] / 65536; this->load5a = `hp_avenrun[1] / 65536; this->load15a = `hp_avenrun[2] / 65536; this->load1b = ((`hp_avenrun[0] % 65536) * 100) / 65536; this->load5b = ((`hp_avenrun[1] % 65536) * 100) / 65536; this->load15b = ((`hp_avenrun[2] % 65536) * 100) / 65536; /* clear screen */ system("clear"); /* print load average */ printf("%Y, load average: %d.%02d, %d.%02d, %d.%02d", walltimestamp, this->load1a, this->load1b, this->load5a, this->load5b, this->load15a, this->load15b); /* print syscall count */ printa(" syscalls: %@d\n",@Total); /* print report */ trunc(@Name, SCREEN); printf("\n %-25s %12s\n", "SYSCALL", "COUNT"); printa(" %-25s %@12d\n", @Name); /* reset variables */ trunc(@Name); clear(@Total); secs = 0; } '