Home | History | Annotate | Line # | Download | only in Bin
      1  1.1  christos #!/usr/bin/sh
      2  1.1  christos #
      3  1.1  christos # topsysproc - display top syscalls by process name.
      4  1.1  christos #              Written using DTrace (Solaris 10 3/05).
      5  1.1  christos #
      6  1.1  christos # This program continually prints a report of the number of system calls
      7  1.1  christos # by process name, and refreshes the display every 1 second or as specified
      8  1.1  christos # at the command line. Similar data can be fetched with "prstat -m".
      9  1.1  christos #
     10  1.1  christos # $Id: topsysproc,v 1.1.1.1 2015/09/30 22:01:07 christos Exp $
     11  1.1  christos #
     12  1.1  christos # USAGE:        topsysproc [interval]
     13  1.1  christos #
     14  1.1  christos # FIELDS:
     15  1.1  christos #		load avg   load averages, see uptime(1)
     16  1.1  christos #		syscalls   total number of syscalls in this interval
     17  1.1  christos #		PROCESS    process name
     18  1.1  christos #		COUNT      number of occurances in this interval
     19  1.1  christos #
     20  1.1  christos # NOTE: There may be several PIDs with the same process name.
     21  1.1  christos #
     22  1.1  christos # SEE ALSO:     prstat(1M)
     23  1.1  christos #
     24  1.1  christos # INSPIRATION:  top(1) by William LeFebvre
     25  1.1  christos #
     26  1.1  christos # COPYRIGHT: Copyright (c) 2005 Brendan Gregg.
     27  1.1  christos #
     28  1.1  christos # CDDL HEADER START
     29  1.1  christos #
     30  1.1  christos #  The contents of this file are subject to the terms of the
     31  1.1  christos #  Common Development and Distribution License, Version 1.0 only
     32  1.1  christos #  (the "License").  You may not use this file except in compliance
     33  1.1  christos #  with the License.
     34  1.1  christos #
     35  1.1  christos #  You can obtain a copy of the license at Docs/cddl1.txt
     36  1.1  christos #  or http://www.opensolaris.org/os/licensing.
     37  1.1  christos #  See the License for the specific language governing permissions
     38  1.1  christos #  and limitations under the License.
     39  1.1  christos #
     40  1.1  christos # CDDL HEADER END
     41  1.1  christos #
     42  1.1  christos # 13-Jun-2005	Brendan Gregg	Created this.
     43  1.1  christos # 20-Apr-2006	   "      "	Last update.
     44  1.1  christos #
     45  1.1  christos 
     46  1.1  christos #
     47  1.1  christos #  Check options
     48  1.1  christos #
     49  1.1  christos if [ "$1" = "-h" -o "$1" = "--help" ]; then
     50  1.1  christos 	cat <<-END
     51  1.1  christos 	USAGE: topsysproc [interval]
     52  1.1  christos 	   eg,
     53  1.1  christos 	       topsysproc            # default, 1 second updates
     54  1.1  christos 	       topsysproc 5          # 5 second updates
     55  1.1  christos 	END
     56  1.1  christos 	exit 1
     57  1.1  christos fi
     58  1.1  christos interval=1
     59  1.1  christos if [ "$1" -gt 0 ]; then
     60  1.1  christos 	interval=$1
     61  1.1  christos fi
     62  1.1  christos 
     63  1.1  christos #
     64  1.1  christos #  Run DTrace
     65  1.1  christos #
     66  1.1  christos /usr/sbin/dtrace -n '
     67  1.1  christos  #pragma D option quiet
     68  1.1  christos  #pragma D option destructive
     69  1.1  christos 
     70  1.1  christos  /* constants */
     71  1.1  christos  inline int INTERVAL = '$interval';
     72  1.1  christos  inline int SCREEN   = 20;
     73  1.1  christos 
     74  1.1  christos  /* variables */
     75  1.1  christos  dtrace:::BEGIN
     76  1.1  christos  {
     77  1.1  christos 	secs = 0;
     78  1.1  christos 	printf("Tracing... Please wait.\n");
     79  1.1  christos  }
     80  1.1  christos 
     81  1.1  christos  /* record syscall event */
     82  1.1  christos  syscall:::entry
     83  1.1  christos  {
     84  1.1  christos 	@Name[execname] = count();
     85  1.1  christos 	@Total = count();
     86  1.1  christos  }
     87  1.1  christos 
     88  1.1  christos  /* update screen */
     89  1.1  christos  profile:::tick-1sec
     90  1.1  christos  /++secs >= INTERVAL/
     91  1.1  christos  {
     92  1.1  christos         /* fetch load averages */
     93  1.1  christos         this->load1a  = `hp_avenrun[0] / 65536;
     94  1.1  christos         this->load5a  = `hp_avenrun[1] / 65536;
     95  1.1  christos         this->load15a = `hp_avenrun[2] / 65536;
     96  1.1  christos         this->load1b  = ((`hp_avenrun[0] % 65536) * 100) / 65536;
     97  1.1  christos         this->load5b  = ((`hp_avenrun[1] % 65536) * 100) / 65536;
     98  1.1  christos         this->load15b = ((`hp_avenrun[2] % 65536) * 100) / 65536;
     99  1.1  christos 
    100  1.1  christos 	/* clear screen */
    101  1.1  christos 	system("clear");
    102  1.1  christos 
    103  1.1  christos         /* print load average */
    104  1.1  christos         printf("%Y, load average: %d.%02d, %d.%02d, %d.%02d",
    105  1.1  christos             walltimestamp, this->load1a, this->load1b, this->load5a,
    106  1.1  christos             this->load5b, this->load15a, this->load15b);
    107  1.1  christos 
    108  1.1  christos 	/* print syscall count */
    109  1.1  christos 	printa("   syscalls: %@d\n",@Total);
    110  1.1  christos 
    111  1.1  christos 	/* print report */
    112  1.1  christos 	trunc(@Name, SCREEN);
    113  1.1  christos 	printf("\n   %-25s %12s\n", "PROCESS", "COUNT");
    114  1.1  christos 	printa("   %-25s %@12d\n", @Name);
    115  1.1  christos 
    116  1.1  christos 	/* reset variables */
    117  1.1  christos 	trunc(@Name);
    118  1.1  christos 	clear(@Total);
    119  1.1  christos 	secs = 0;
    120  1.1  christos  }
    121  1.1  christos '
    122