155714Skris#!/usr/sbin/dtrace -Zs
255714Skris/*
355714Skris * tcl_who.d - trace Tcl calls by process using DTrace.
455714Skris *           Written for the Tcl DTrace provider.
555714Skris *
655714Skris * $Id: tcl_who.d 63 2007-10-04 04:34:38Z brendan $
755714Skris *
855714Skris * This traces activity from all Tcl processes on the system with DTrace
955714Skris * provider support (tcl8.4.16).
1055714Skris *
1155714Skris * USAGE: tcl_who.d 		# hit Ctrl-C to end
1255714Skris *
1355714Skris * FIELDS:
1455714Skris *		PID		Process ID of Tcl
1555714Skris *		UID		User ID of the owner
1655714Skris *		CALLS		Number of calls made (proc + cmd)
1755714Skris *		ARGS		Process name and arguments
1855714Skris *
1955714Skris * Calls is a measure of activity, and is a count of the procedures and
2055714Skris * commands that Tcl called.
2155714Skris *
2255714Skris * The argument list is truncated at 55 characters (up to 80 is easily
2355714Skris * available). To easily read the full argument list, use other system tools;
2455714Skris * on Solaris use "pargs PID".
2555714Skris *
2655714Skris * COPYRIGHT: Copyright (c) 2007 Brendan Gregg.
2755714Skris *
2855714Skris * CDDL HEADER START
2955714Skris *
3055714Skris *  The contents of this file are subject to the terms of the
3155714Skris *  Common Development and Distribution License, Version 1.0 only
3255714Skris *  (the "License").  You may not use this file except in compliance
3355714Skris *  with the License.
3455714Skris *
3555714Skris *  You can obtain a copy of the license at Docs/cddl1.txt
3655714Skris *  or http://www.opensolaris.org/os/licensing.
3755714Skris *  See the License for the specific language governing permissions
3855714Skris *  and limitations under the License.
3955714Skris *
4055714Skris * CDDL HEADER END
4155714Skris *
4255714Skris * 09-Sep-2007	Brendan Gregg	Created this.
4355714Skris */
4455714Skris
4555714Skris#pragma D option quiet
4655714Skris
4755714Skrisdtrace:::BEGIN
4855714Skris{
4955714Skris	printf("Tracing... Hit Ctrl-C to end.\n");
5055714Skris}
5155714Skris
5255714Skristcl*:::proc-entry,
5355714Skristcl*:::cmd-entry
5455714Skris{
5555714Skris	@calls[pid, uid, curpsinfo->pr_psargs] = count();
5655714Skris}
5755714Skris
5855714Skrisdtrace:::END
5959191Skris{
6055714Skris	printf("   %6s %6s %6s %-55s\n", "PID", "UID", "CALLS", "ARGS");
6155714Skris	printa("   %6d %6d %@6d %-55.55s\n", @calls);
6255714Skris}
6355714Skris