1235368Sgnn#!/usr/sbin/dtrace -s 2235368Sgnn/* 3235368Sgnn * sar-c.d - sar -c demo in DTrace. 4235368Sgnn * Written using DTrace (Solaris 10 3/05). 5235368Sgnn * 6235368Sgnn * This has been written to demonstrate fetching similar data as sar -c 7235368Sgnn * from DTrace. This program is intended as a starting point for other 8235368Sgnn * DTrace scripts, by beginning with familiar statistics. 9235368Sgnn * 10235368Sgnn * $Id: sar-c.d 3 2007-08-01 10:50:08Z brendan $ 11235368Sgnn * 12235368Sgnn * USAGE: sar-c.d 13235368Sgnn * 14235368Sgnn * FIELDS: 15235368Sgnn * scall/s System calls 16235368Sgnn * sread/s reads 17235368Sgnn * swrit/s writes 18235368Sgnn * fork/s forks 19235368Sgnn * exec/s execs 20235368Sgnn * rchar/s read characters 21235368Sgnn * wchar/s write characters 22235368Sgnn * 23235368Sgnn * IDEA: David Rubio, who also wrote the original. 24235368Sgnn * 25235368Sgnn * NOTES: 26235368Sgnn * As this program does not use Kstat, there is no summary since boot line. 27235368Sgnn * 28235368Sgnn * SEE ALSO: sar(1) 29235368Sgnn * 30235368Sgnn * COPYRIGHT: Copyright (c) 2005 Brendan Gregg. 31235368Sgnn * 32235368Sgnn * CDDL HEADER START 33235368Sgnn * 34235368Sgnn * The contents of this file are subject to the terms of the 35235368Sgnn * Common Development and Distribution License, Version 1.0 only 36235368Sgnn * (the "License"). You may not use this file except in compliance 37235368Sgnn * with the License. 38235368Sgnn * 39235368Sgnn * You can obtain a copy of the license at Docs/cddl1.txt 40235368Sgnn * or http://www.opensolaris.org/os/licensing. 41235368Sgnn * See the License for the specific language governing permissions 42235368Sgnn * and limitations under the License. 43235368Sgnn * 44235368Sgnn * CDDL HEADER END 45235368Sgnn * 46235368Sgnn * 12-Jun-2005 Brendan Gregg Created this. 47235368Sgnn * 12-Jun-2005 " " Last update. 48235368Sgnn */ 49235368Sgnn 50235368Sgnn#pragma D option quiet 51235368Sgnn 52235368Sgnninline int SCREEN = 21; 53235368Sgnn 54235368Sgnn/* 55235368Sgnn * Initialise variables 56235368Sgnn */ 57235368Sgnndtrace:::BEGIN 58235368Sgnn{ 59235368Sgnn scall = 0; sread = 0; swrit = 0; fork = 0; exec = 0; 60235368Sgnn rchar = 0; wchar = 0; 61235368Sgnn lines = SCREEN + 1; 62235368Sgnn} 63235368Sgnn 64235368Sgnn/* 65235368Sgnn * Print header 66235368Sgnn */ 67235368Sgnndtrace:::BEGIN, 68235368Sgnntick-1sec 69235368Sgnn/lines++ > SCREEN/ 70235368Sgnn{ 71235368Sgnn printf("%-20s %7s %7s %7s %7s %7s %8s %8s\n", 72235368Sgnn "Time", "scall/s", "sread/s", "swrit/s", "fork/s", 73235368Sgnn "exec/s", "rchar/s", "wchar/s"); 74235368Sgnn lines = 0; 75235368Sgnn} 76235368Sgnn 77235368Sgnn/* 78235368Sgnn * Probe events 79235368Sgnn */ 80235368Sgnnsyscall:::entry { scall++; } 81235368Sgnnsysinfo:::sysread { sread++; } 82235368Sgnnsysinfo:::syswrite { swrit++; } 83235368Sgnnsysinfo:::sysfork { fork++; } 84235368Sgnnsysinfo:::sysvfork { fork++; } 85235368Sgnnsysinfo:::sysexec { exec++; } 86235368Sgnnsysinfo:::readch { rchar += arg0; } 87235368Sgnnsysinfo:::writech { wchar += arg0; } 88235368Sgnn 89235368Sgnn/* 90235368Sgnn * Print output line 91235368Sgnn */ 92235368Sgnnprofile:::tick-1sec 93235368Sgnn{ 94235368Sgnn /* print line */ 95235368Sgnn printf("%20Y %7d %7d %7d %4d.00 %4d.00 %8d %8d\n", 96235368Sgnn walltimestamp, scall, sread, swrit, fork, exec, rchar, wchar); 97235368Sgnn 98235368Sgnn /* clear counters */ 99235368Sgnn scall = 0; sread = 0; swrit = 0; fork = 0; exec = 0; 100235368Sgnn rchar = 0; wchar = 0; 101235368Sgnn} 102