Home | History | Annotate | Line # | Download | only in System
      1 #!/usr/sbin/dtrace -s
      2 /*
      3  * sar-c.d - sar -c demo in DTrace.
      4  *           Written using DTrace (Solaris 10 3/05).
      5  *
      6  * This has been written to demonstrate fetching similar data as sar -c
      7  * from DTrace. This program is intended as a starting point for other
      8  * DTrace scripts, by beginning with familiar statistics.
      9  *
     10  * $Id: sar-c.d,v 1.1.1.1 2015/09/30 22:01:09 christos Exp $
     11  *
     12  * USAGE:	sar-c.d
     13  *
     14  * FIELDS:
     15  *		scall/s		System calls
     16  *		sread/s		reads
     17  *		swrit/s		writes
     18  *		fork/s		forks
     19  *		exec/s		execs
     20  *		rchar/s		read characters
     21  *		wchar/s		write characters
     22  *
     23  * IDEA: David Rubio, who also wrote the original.
     24  *
     25  * NOTES:
     26  *  As this program does not use Kstat, there is no summary since boot line.
     27  *
     28  * SEE ALSO:	sar(1)
     29  *
     30  * COPYRIGHT: Copyright (c) 2005 Brendan Gregg.
     31  *
     32  * CDDL HEADER START
     33  *
     34  *  The contents of this file are subject to the terms of the
     35  *  Common Development and Distribution License, Version 1.0 only
     36  *  (the "License").  You may not use this file except in compliance
     37  *  with the License.
     38  *
     39  *  You can obtain a copy of the license at Docs/cddl1.txt
     40  *  or http://www.opensolaris.org/os/licensing.
     41  *  See the License for the specific language governing permissions
     42  *  and limitations under the License.
     43  *
     44  * CDDL HEADER END
     45  *
     46  * 12-Jun-2005  Brendan Gregg   Created this.
     47  * 12-Jun-2005	   "      "	Last update.
     48  */
     49 
     50 #pragma D option quiet
     51 
     52 inline int SCREEN = 21;
     53 
     54 /*
     55  * Initialise variables
     56  */
     57 dtrace:::BEGIN
     58 {
     59 	scall = 0; sread = 0; swrit = 0; fork = 0; exec = 0;
     60 	rchar = 0; wchar = 0;
     61 	lines = SCREEN + 1;
     62 }
     63 
     64 /*
     65  * Print header
     66  */
     67 dtrace:::BEGIN,
     68 tick-1sec
     69 /lines++ > SCREEN/
     70 {
     71 	printf("%-20s %7s %7s %7s %7s %7s %8s %8s\n",
     72 	    "Time", "scall/s", "sread/s", "swrit/s", "fork/s",
     73 	    "exec/s", "rchar/s", "wchar/s");
     74 	lines = 0;
     75 }
     76 
     77 /*
     78  * Probe events
     79  */
     80 syscall:::entry    { scall++; }
     81 sysinfo:::sysread  { sread++; }
     82 sysinfo:::syswrite { swrit++; }
     83 sysinfo:::sysfork  { fork++;  }
     84 sysinfo:::sysvfork { fork++;  }
     85 sysinfo:::sysexec  { exec++;  }
     86 sysinfo:::readch   { rchar += arg0; }
     87 sysinfo:::writech  { wchar += arg0; }
     88 
     89 /*
     90  * Print output line
     91  */
     92 profile:::tick-1sec
     93 {
     94 	/* print line */
     95 	printf("%20Y %7d %7d %7d %4d.00 %4d.00 %8d %8d\n",
     96 	    walltimestamp, scall, sread, swrit, fork, exec, rchar, wchar);
     97 
     98 	/* clear counters */
     99 	scall = 0; sread = 0; swrit = 0; fork = 0; exec = 0;
    100 	rchar = 0; wchar = 0;
    101 }
    102