topsyscall revision 1
1N/A# topsyscall - display top syscalls by syscall name. 1N/A# Written using DTrace (Solaris 10 3/05). 1N/A# This program continually prints a report of the top system calls, 1N/A# and refreshes the display every 1 second or as specified at the 1N/A# $Id: topsyscall 3 2007-08-01 10:50:08Z brendan $ 1N/A# USAGE: topsyscall [-Cs] [interval [count]] 1N/A# -C # don't clear the screen 1N/A# -s # print per second values 1N/A# load avg load averages, see uptime(1) 1N/A# syscalls total syscalls in this interval 1N/A# syscalls/s syscalls per second 1N/A# SYSCALL system call name 1N/A# COUNT total syscalls in this interval 1N/A# COUNT/s syscalls per second 1N/A# INSPIRATION: top(1) by William LeFebvre 1N/A# COPYRIGHT: Copyright (c) 2005, 2006 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# 13-Jun-2005 Brendan Gregg Created this. 1N/A# 20-Apr-2006 " " Last update. 1N/A############################## 1N/A# --- Process Arguments --- 1N/A### Default variables 1N/A USAGE: topsyscall [-s] [interval [count]] 1N/A -C # don't clear the screen 1N/A -s # print per second values 1N/A topsyscall # default, 1 second updates 1N/A topsyscall 5 # 5 second updates 1N/Ashift $(( $OPTIND - 1 )) 1N/Aif [[ "$1" > 0 ]]; then 1N/Aif [[ "$1" > 0 ]]; then 1N/Aif (( opt_clear )); then 1N/A################################# 1N/A# --- Main Program, DTrace --- 1N/A/usr/sbin/dtrace -n ' 1N/A #pragma D option quiet 1N/A #pragma D option destructive 1N/A inline int OPT_clear = '$opt_clear'; 1N/A inline int OPT_persec = '$opt_persec'; 1N/A inline int INTERVAL = '$interval'; 1N/A inline int COUNTER = '$count'; 1N/A inline int SCREEN = 20; 1N/A inline string CLEAR = "'$clearstr'"; 1N/A printf("Tracing... Please wait.\n"); 1N/A /* record syscall event */ 1N/A @Name[probefunc] = count(); 1N/A /* fetch load averages */ 1N/A this->load1a = `hp_avenrun[0] / 65536; 1N/A this->load5a = `hp_avenrun[1] / 65536; 1N/A this->load15a = `hp_avenrun[2] / 65536; 1N/A this->load1b = ((`hp_avenrun[0] % 65536) * 100) / 65536; 1N/A this->load5b = ((`hp_avenrun[1] % 65536) * 100) / 65536; 1N/A this->load15b = ((`hp_avenrun[2] % 65536) * 100) / 65536; 1N/A OPT_clear ? printf("%s", CLEAR) : 1; 1N/A /* print load average */ 1N/A printf("%Y, load average: %d.%02d, %d.%02d, %d.%02d", 1N/A walltimestamp, this->load1a, this->load1b, this->load5a, 1N/A this->load5b, this->load15a, this->load15b); 1N/A /* calculate per second values if needed */ 1N/A OPT_persec ? normalize(@Total, INTERVAL) : 1; 1N/A OPT_persec ? normalize(@Name, INTERVAL) : 1; 1N/A /* print syscall count */ 1N/A printf(" %s: ", OPT_persec ? "syscalls/s" : "syscalls"); 1N/A printa("%@d\n",@Total); 1N/A trunc(@Name, SCREEN); 1N/A printf("\n %-25s %12s\n", "SYSCALL", 1N/A OPT_persec ? "COUNT/s" : "COUNT"); 1N/A printa(" %-25s %@12d\n", @Name); 1N/A /* reset variables */ 1N/A * Cleanup for Ctrl-C