3 # topsyscall - display top syscalls by syscall name.
4 # Written using DTrace (Solaris 10 3/05).
6 # This program continually prints a report of the top system calls,
7 # and refreshes the display every 1 second or as specified at the
10 # $Id: topsyscall 3 2007-08-01 10:50:08Z brendan $
12 # USAGE: topsyscall [-Cs] [interval [count]]
14 # -C # don't clear the screen
15 # -s # print per second values
18 # load avg load averages, see uptime(1)
19 # syscalls total syscalls in this interval
20 # syscalls/s syscalls per second
21 # SYSCALL system call name
22 # COUNT total syscalls in this interval
23 # COUNT/s syscalls per second
25 # INSPIRATION: top(1) by William LeFebvre
27 # COPYRIGHT: Copyright (c) 2005, 2006 Brendan Gregg.
31 # The contents of this file are subject to the terms of the
32 # Common Development and Distribution License, Version 1.0 only
33 # (the "License"). You may not use this file except in compliance
36 # You can obtain a copy of the license at Docs/cddl1.txt
37 # or http://www.opensolaris.org/os/licensing.
38 # See the License for the specific language governing permissions
39 # and limitations under the License.
43 # 13-Jun-2005 Brendan Gregg Created this.
44 # 20-Apr-2006 " " Last update.
47 ##############################
48 # --- Process Arguments ---
52 count=-1; interval=1; opt_persec=0; opt_clear=1
55 while getopts Chs name
61 USAGE: topsyscall [-s] [interval [count]]
62 -C # don't clear the screen
63 -s # print per second values
65 topsyscall # default, 1 second updates
66 topsyscall 5 # 5 second updates
71 shift $(( $OPTIND - 1 ))
74 if [[ "$1" > 0 ]]; then
77 if [[ "$1" > 0 ]]; then
80 if (( opt_clear )); then
88 #################################
89 # --- Main Program, DTrace ---
92 #pragma D option quiet
93 #pragma D option destructive
96 inline int OPT_clear = '$opt_clear';
97 inline int OPT_persec = '$opt_persec';
98 inline int INTERVAL = '$interval';
99 inline int COUNTER = '$count';
100 inline int SCREEN = 20;
101 inline string CLEAR = "'$clearstr'";
108 printf("Tracing... Please wait.\n");
111 /* record syscall event */
114 @Name[probefunc] = count();
128 /* fetch load averages */
129 this->load1a = `hp_avenrun[0] / 65536;
130 this->load5a = `hp_avenrun[1] / 65536;
131 this->load15a = `hp_avenrun[2] / 65536;
132 this->load1b = ((`hp_avenrun[0] % 65536) * 100) / 65536;
133 this->load5b = ((`hp_avenrun[1] % 65536) * 100) / 65536;
134 this->load15b = ((`hp_avenrun[2] % 65536) * 100) / 65536;
137 OPT_clear ? printf("%s", CLEAR) : 1;
139 /* print load average */
140 printf("%Y, load average: %d.%02d, %d.%02d, %d.%02d",
141 walltimestamp, this->load1a, this->load1b, this->load5a,
142 this->load5b, this->load15a, this->load15b);
144 /* calculate per second values if needed */
145 OPT_persec ? normalize(@Total, INTERVAL) : 1;
146 OPT_persec ? normalize(@Name, INTERVAL) : 1;
148 /* print syscall count */
149 printf(" %s: ", OPT_persec ? "syscalls/s" : "syscalls");
150 printa("%@d\n",@Total);
153 trunc(@Name, SCREEN);
154 printf("\n %-25s %12s\n", "SYSCALL",
155 OPT_persec ? "COUNT/s" : "COUNT");
156 printa(" %-25s %@12d\n", @Name);
159 /* reset variables */