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 * 12-Jun-2005, ver 0.90 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 */ 48 49#pragma D option quiet 50 51inline int SCREEN = 21; 52 53/* 54 * Initialise variables 55 */ 56dtrace:::BEGIN 57{ 58 scall = 0; sread = 0; swrit = 0; fork = 0; exec = 0; 59 rchar = 0; wchar = 0; 60 lines = SCREEN + 1; 61} 62 63/* 64 * Print header 65 */ 66dtrace:::BEGIN, 67tick-1sec 68/lines++ > SCREEN/ 69{ 70 printf("%-20s %7s %7s %7s %7s %7s %8s %8s\n", 71 "Time", "scall/s", "sread/s", "swrit/s", "fork/s", 72 "exec/s", "rchar/s", "wchar/s"); 73 lines = 0; 74} 75 76/* 77 * Probe events 78 */ 79syscall:::entry { scall++; } 80sysinfo:::sysread { sread++; } 81sysinfo:::syswrite { swrit++; } 82sysinfo:::sysfork { fork++; } 83sysinfo:::sysvfork { fork++; } 84sysinfo:::sysexec { exec++; } 85sysinfo:::readch { rchar += arg0; } 86sysinfo:::writech { wchar += arg0; } 87 88/* 89 * Print output line 90 */ 91profile:::tick-1sec 92{ 93 /* print line */ 94 printf("%20Y %7d %7d %7d %4d.00 %4d.00 %8d %8d\n", 95 walltimestamp, scall, sread, swrit, fork, exec, rchar, wchar); 96 97 /* clear counters */ 98 scall = 0; sread = 0; swrit = 0; fork = 0; exec = 0; 99 rchar = 0; wchar = 0; 100} 101