sar-c.d revision 256281
1132718Skan#!/usr/sbin/dtrace -s
2169689Skan/*
390075Sobrien * sar-c.d - sar -c demo in DTrace.
490075Sobrien *           Written using DTrace (Solaris 10 3/05).
590075Sobrien *
690075Sobrien * This has been written to demonstrate fetching similar data as sar -c
790075Sobrien * from DTrace. This program is intended as a starting point for other
890075Sobrien * DTrace scripts, by beginning with familiar statistics.
990075Sobrien *
1090075Sobrien * $Id: sar-c.d 3 2007-08-01 10:50:08Z brendan $
1190075Sobrien *
1290075Sobrien * USAGE:	sar-c.d
1390075Sobrien *
1490075Sobrien * FIELDS:
1590075Sobrien *		scall/s		System calls
1690075Sobrien *		sread/s		reads
1790075Sobrien *		swrit/s		writes
18169689Skan *		fork/s		forks
19169689Skan *		exec/s		execs
2090075Sobrien *		rchar/s		read characters
21169689Skan *		wchar/s		write characters
22169689Skan *
23169689Skan * IDEA: David Rubio, who also wrote the original.
2490075Sobrien *
2590075Sobrien * NOTES:
2690075Sobrien *  As this program does not use Kstat, there is no summary since boot line.
2790075Sobrien *
2890075Sobrien * SEE ALSO:	sar(1)
2990075Sobrien *
3090075Sobrien * COPYRIGHT: Copyright (c) 2005 Brendan Gregg.
3190075Sobrien *
3290075Sobrien * CDDL HEADER START
3390075Sobrien *
3490075Sobrien *  The contents of this file are subject to the terms of the
3590075Sobrien *  Common Development and Distribution License, Version 1.0 only
3690075Sobrien *  (the "License").  You may not use this file except in compliance
3790075Sobrien *  with the License.
3890075Sobrien *
39132718Skan *  You can obtain a copy of the license at Docs/cddl1.txt
40169689Skan *  or http://www.opensolaris.org/os/licensing.
4190075Sobrien *  See the License for the specific language governing permissions
42169689Skan *  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
52inline int SCREEN = 21;
53
54/*
55 * Initialise variables
56 */
57dtrace:::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 */
67dtrace:::BEGIN,
68tick-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 */
80syscall:::entry    { scall++; }
81sysinfo:::sysread  { sread++; }
82sysinfo:::syswrite { swrit++; }
83sysinfo:::sysfork  { fork++;  }
84sysinfo:::sysvfork { fork++;  }
85sysinfo:::sysexec  { exec++;  }
86sysinfo:::readch   { rchar += arg0; }
87sysinfo:::writech  { wchar += arg0; }
88
89/*
90 * Print output line
91 */
92profile:::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