1N/A#!/usr/sbin/dtrace -Zs
1N/A/*
1N/A * sh_stat.d - Bourne shell operation stats using DTrace.
1N/A * Written for the sh DTrace provider.
1N/A *
1N/A * $Id: sh_stat.d 52 2007-09-24 04:28:01Z brendan $
1N/A *
1N/A * This traces activity from all sh processes on the system that are running
1N/A * with sh provider support.
1N/A *
1N/A * USAGE: sh_stat.d [interval [count]]
1N/A *
1N/A * FIELDS:
1N/A * EXEC/s Bourne shells executed per second, including
1N/A * those without sh provider support
1N/A * FUNC/s Functions called, per second
1N/A * BLTIN/s Builtins called, per second
1N/A * SUB-SH/s Sub-shells called, per second
1N/A * CMD/s External commands called, per second
1N/A *
1N/A * The numbers are counts for the interval specified. The default interval
1N/A * is 1 second.
1N/A *
1N/A * If you see a count in "EXECS" but not in the other columns, then sh
1N/A * scripts may be running without the DTrace sh provider. See Shell/Readme.
1N/A *
1N/A * Filename and function names are printed if available.
1N/A *
1N/A * COPYRIGHT: Copyright (c) 2007 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 * 09-Sep-2007 Brendan Gregg Created this.
1N/A */
1N/A
1N/A#pragma D option quiet
1N/A#pragma D option defaultargs
1N/A
1N/Ainline int SCREEN = 21;
1N/A
1N/Adtrace:::BEGIN
1N/A{
1N/A execs = funcs = builtins = subs = cmds = 0;
1N/A lines = SCREEN + 1;
1N/A interval = $1 ? $1 : 1;
1N/A counts = $2 ? $2 : -1;
1N/A secs = interval;
1N/A first = 1;
1N/A}
1N/A
1N/Aprofile:::tick-1sec
1N/A{
1N/A secs--;
1N/A}
1N/A
1N/A/*
1N/A * Print Header
1N/A */
1N/Adtrace:::BEGIN,
1N/Aprofile:::tick-1sec
1N/A/first || (secs == 0 && lines > SCREEN)/
1N/A{
1N/A printf("%-20s %8s %8s %8s %8s %8s\n", "TIME", "EXEC/s", "FUNCS/s",
1N/A "BLTINS/s", "SUB-SH/s", "CMD/s");
1N/A lines = 0;
1N/A first = 0;
1N/A}
1N/A
1N/A/*
1N/A * Tally Data
1N/A */
1N/Aproc:::exec-success
1N/A/execname == "sh"/
1N/A{
1N/A execs++;
1N/A}
1N/A
1N/Ash*:::function-entry
1N/A{
1N/A funcs++;
1N/A}
1N/A
1N/Ash*:::builtin-entry
1N/A{
1N/A builtins++;
1N/A}
1N/A
1N/Ash*:::subshell-entry
1N/A/arg0 != 0/
1N/A{
1N/A subs++;
1N/A}
1N/A
1N/Ash*:::command-entry
1N/A{
1N/A cmds++;
1N/A}
1N/A
1N/A/*
1N/A * Print Output
1N/A */
1N/Aprofile:::tick-1sec
1N/A/secs == 0/
1N/A{
1N/A printf("%-20Y %8d %8d %8d %8d %8d\n", walltimestamp, execs / interval,
1N/A funcs / interval, builtins / interval, subs / interval,
1N/A cmds / interval);
1N/A execs = funcs = builtins = subs = cmds = 0;
1N/A secs = interval;
1N/A lines++;
1N/A counts--;
1N/A}
1N/A
1N/A/*
1N/A * End
1N/A */
1N/Aprofile:::tick-1sec
1N/A/counts == 0/
1N/A{
1N/A exit(0);
1N/A}