1N/A#!/usr/sbin/dtrace -s
1N/A/*
1N/A * sar-c.d - sar -c demo in DTrace.
1N/A * Written using DTrace (Solaris 10 3/05).
1N/A *
1N/A * This has been written to demonstrate fetching similar data as sar -c
1N/A * from DTrace. This program is intended as a starting point for other
1N/A * DTrace scripts, by beginning with familiar statistics.
1N/A *
1N/A * $Id: sar-c.d 3 2007-08-01 10:50:08Z brendan $
1N/A *
1N/A * USAGE: sar-c.d
1N/A *
1N/A * FIELDS:
1N/A * scall/s System calls
1N/A * sread/s reads
1N/A * swrit/s writes
1N/A * fork/s forks
1N/A * exec/s execs
1N/A * rchar/s read characters
1N/A * wchar/s write characters
1N/A *
1N/A * IDEA: David Rubio, who also wrote the original.
1N/A *
1N/A * NOTES:
1N/A * As this program does not use Kstat, there is no summary since boot line.
1N/A *
1N/A * SEE ALSO: sar(1)
1N/A *
1N/A * COPYRIGHT: Copyright (c) 2005 Brendan Gregg.
1N/A *
1N/A * CDDL HEADER START
1N/A *
1N/A * The contents of this file are subject to the terms of the
1N/A * Common Development and Distribution License, Version 1.0 only
1N/A * (the "License"). You may not use this file except in compliance
1N/A * with the License.
1N/A *
1N/A * You can obtain a copy of the license at Docs/cddl1.txt
1N/A * or http://www.opensolaris.org/os/licensing.
1N/A * See the License for the specific language governing permissions
1N/A * and limitations under the License.
1N/A *
1N/A * CDDL HEADER END
1N/A *
1N/A * 12-Jun-2005 Brendan Gregg Created this.
1N/A * 12-Jun-2005 " " Last update.
1N/A */
1N/A
1N/A#pragma D option quiet
1N/A
1N/Ainline int SCREEN = 21;
1N/A
1N/A/*
1N/A * Initialise variables
1N/A */
1N/Adtrace:::BEGIN
1N/A{
1N/A scall = 0; sread = 0; swrit = 0; fork = 0; exec = 0;
1N/A rchar = 0; wchar = 0;
1N/A lines = SCREEN + 1;
1N/A}
1N/A
1N/A/*
1N/A * Print header
1N/A */
1N/Adtrace:::BEGIN,
1N/Atick-1sec
1N/A/lines++ > SCREEN/
1N/A{
1N/A printf("%-20s %7s %7s %7s %7s %7s %8s %8s\n",
1N/A "Time", "scall/s", "sread/s", "swrit/s", "fork/s",
1N/A "exec/s", "rchar/s", "wchar/s");
1N/A lines = 0;
1N/A}
1N/A
1N/A/*
1N/A * Probe events
1N/A */
1N/Asyscall:::entry { scall++; }
1N/Asysinfo:::sysread { sread++; }
1N/Asysinfo:::syswrite { swrit++; }
1N/Asysinfo:::sysfork { fork++; }
1N/Asysinfo:::sysvfork { fork++; }
1N/Asysinfo:::sysexec { exec++; }
1N/Asysinfo:::readch { rchar += arg0; }
1N/Asysinfo:::writech { wchar += arg0; }
1N/A
1N/A/*
1N/A * Print output line
1N/A */
1N/Aprofile:::tick-1sec
1N/A{
1N/A /* print line */
1N/A printf("%20Y %7d %7d %7d %4d.00 %4d.00 %8d %8d\n",
1N/A walltimestamp, scall, sread, swrit, fork, exec, rchar, wchar);
1N/A
1N/A /* clear counters */
1N/A scall = 0; sread = 0; swrit = 0; fork = 0; exec = 0;
1N/A rchar = 0; wchar = 0;
1N/A}