1N/A#!/usr/sbin/dtrace -CZs
1N/A/*
1N/A * tcl_cputime.d - measure Tcl on-CPU times for different types of operation.
1N/A * Written for the Tcl DTrace provider.
1N/A *
1N/A * $Id: tcl_cputime.d 63 2007-10-04 04:34:38Z brendan $
1N/A *
1N/A * USAGE: tcl_cputime.d [top] # hit Ctrl-C to end
1N/A * eg,
1N/A * tcl_cputime.d # default, truncate to 10 lines
1N/A * tcl_cputime.d 25 # truncate each report section to 25 lines
1N/A *
1N/A * This traces activity from all Tcl processes on the system with DTrace
1N/A * provider support (tcl8.4.16).
1N/A *
1N/A * FIELDS:
1N/A * PID Process ID
1N/A * TYPE Type of call (proc/cmd/total)
1N/A * NAME Name of call
1N/A * TOTAL Total on-CPU time for calls (us)
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#define TOP 10 /* default output truncation */
1N/A#define B_FALSE 0
1N/A
1N/A#pragma D option quiet
1N/A#pragma D option defaultargs
1N/A
1N/Adtrace:::BEGIN
1N/A{
1N/A printf("Tracing... Hit Ctrl-C to end.\n");
1N/A top = $1 != 0 ? $1 : TOP;
1N/A}
1N/A
1N/Atcl*:::proc-entry
1N/A{
1N/A self->depth++;
1N/A self->exclude[self->depth] = 0;
1N/A self->proc[self->depth] = vtimestamp;
1N/A}
1N/A
1N/Atcl*:::proc-return
1N/A/self->proc[self->depth]/
1N/A{
1N/A this->oncpu_incl = vtimestamp - self->proc[self->depth];
1N/A this->oncpu_excl = this->oncpu_incl - self->exclude[self->depth];
1N/A self->proc[self->depth] = 0;
1N/A self->exclude[self->depth] = 0;
1N/A this->name = copyinstr(arg0);
1N/A
1N/A @num[pid, "proc", this->name] = count();
1N/A @num[0, "total", "-"] = count();
1N/A @types_incl[pid, "proc", this->name] = sum(this->oncpu_incl);
1N/A @types_excl[pid, "proc", this->name] = sum(this->oncpu_excl);
1N/A @types_excl[0, "total", "-"] = sum(this->oncpu_excl);
1N/A
1N/A self->depth--;
1N/A self->exclude[self->depth] += this->oncpu_incl;
1N/A}
1N/A
1N/Atcl*:::cmd-entry
1N/A{
1N/A self->depth++;
1N/A self->exclude[self->depth] = 0;
1N/A self->cmd[self->depth] = vtimestamp;
1N/A}
1N/A
1N/Atcl*:::cmd-return
1N/A/self->cmd[self->depth]/
1N/A{
1N/A this->oncpu_incl = vtimestamp - self->cmd[self->depth];
1N/A this->oncpu_excl = this->oncpu_incl - self->exclude[self->depth];
1N/A self->cmd[self->depth] = 0;
1N/A self->exclude[self->depth] = 0;
1N/A this->name = copyinstr(arg0);
1N/A
1N/A @num[pid, "cmd", this->name] = count();
1N/A @num[0, "total", "-"] = count();
1N/A @types_incl[pid, "cmd", this->name] = sum(this->oncpu_incl);
1N/A @types_excl[pid, "cmd", this->name] = sum(this->oncpu_excl);
1N/A @types_excl[0, "total", "-"] = sum(this->oncpu_excl);
1N/A
1N/A self->depth--;
1N/A self->exclude[self->depth] += this->oncpu_incl;
1N/A}
1N/A
1N/Adtrace:::END
1N/A{
1N/A trunc(@num, top);
1N/A printf("\nTop %d counts,\n", top);
1N/A printf(" %6s %-10s %-48s %8s\n", "PID", "TYPE", "NAME", "COUNT");
1N/A printa(" %6d %-10s %-48s %@8d\n", @num);
1N/A
1N/A trunc(@types_excl, top);
1N/A normalize(@types_excl, 1000);
1N/A printf("\nTop %d exclusive on-CPU times (us),\n", top);
1N/A printf(" %6s %-10s %-48s %8s\n", "PID", "TYPE", "NAME", "TOTAL");
1N/A printa(" %6d %-10s %-48s %@8d\n", @types_excl);
1N/A
1N/A trunc(@types_incl, top);
1N/A normalize(@types_incl, 1000);
1N/A printf("\nTop %d inclusive on-CPU times (us),\n", top);
1N/A printf(" %6s %-10s %-48s %8s\n", "PID", "TYPE", "NAME", "TOTAL");
1N/A printa(" %6d %-10s %-48s %@8d\n", @types_incl);
1N/A}