1N/A#!/usr/bin/sh
1N/A#
1N/A# topsysproc - display top syscalls by process name.
1N/A# Written using DTrace (Solaris 10 3/05).
1N/A#
1N/A# This program continually prints a report of the number of system calls
1N/A# by process name, and refreshes the display every 1 second or as specified
1N/A# at the command line. Similar data can be fetched with "prstat -m".
1N/A#
1N/A# $Id: topsysproc 19 2007-09-12 07:47:59Z brendan $
1N/A#
1N/A# USAGE: topsysproc [interval]
1N/A#
1N/A# FIELDS:
1N/A# load avg load averages, see uptime(1)
1N/A# syscalls total number of syscalls in this interval
1N/A# PROCESS process name
1N/A# COUNT number of occurances in this interval
1N/A#
1N/A# NOTE: There may be several PIDs with the same process name.
1N/A#
1N/A# SEE ALSO: prstat(1M)
1N/A#
1N/A# INSPIRATION: top(1) by William LeFebvre
1N/A#
1N/A# COPYRIGHT: Copyright (c) 2005 Brendan Gregg.
1N/A#
1N/A# CDDL HEADER START
1N/A#
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# with the License.
1N/A#
1N/A# You can obtain a copy of the license at Docs/cddl1.txt
1N/A# or http://www.opensolaris.org/os/licensing.
1N/A# See the License for the specific language governing permissions
1N/A# and limitations under the License.
1N/A#
1N/A# CDDL HEADER END
1N/A#
1N/A# 13-Jun-2005 Brendan Gregg Created this.
1N/A# 20-Apr-2006 " " Last update.
1N/A#
1N/A
1N/A#
1N/A# Check options
1N/A#
1N/Aif [ "$1" = "-h" -o "$1" = "--help" ]; then
1N/A cat <<-END
1N/A USAGE: topsysproc [interval]
1N/A eg,
1N/A topsysproc # default, 1 second updates
1N/A topsysproc 5 # 5 second updates
1N/A END
1N/A exit 1
1N/Afi
1N/Ainterval=1
1N/Aif [ "$1" -gt 0 ]; then
1N/A interval=$1
1N/Afi
1N/A
1N/A#
1N/A# Run DTrace
1N/A#
1N/A/usr/sbin/dtrace -n '
1N/A #pragma D option quiet
1N/A #pragma D option destructive
1N/A
1N/A /* constants */
1N/A inline int INTERVAL = '$interval';
1N/A inline int SCREEN = 20;
1N/A
1N/A /* variables */
1N/A dtrace:::BEGIN
1N/A {
1N/A secs = 0;
1N/A printf("Tracing... Please wait.\n");
1N/A }
1N/A
1N/A /* record syscall event */
1N/A syscall:::entry
1N/A {
1N/A @Name[execname] = count();
1N/A @Total = count();
1N/A }
1N/A
1N/A /* update screen */
1N/A profile:::tick-1sec
1N/A /++secs >= INTERVAL/
1N/A {
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
1N/A /* clear screen */
1N/A system("clear");
1N/A
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
1N/A /* print syscall count */
1N/A printa(" syscalls: %@d\n",@Total);
1N/A
1N/A /* print report */
1N/A trunc(@Name, SCREEN);
1N/A printf("\n %-25s %12s\n", "PROCESS", "COUNT");
1N/A printa(" %-25s %@12d\n", @Name);
1N/A
1N/A /* reset variables */
1N/A trunc(@Name);
1N/A clear(@Total);
1N/A secs = 0;
1N/A }
1N/A'