1235368Sgnn#!/usr/sbin/dtrace -Zs
2235368Sgnn/*
3235368Sgnn * pl_syscalls.d - count Perl subroutine calls and syscalls using DTrace.
4235368Sgnn *                 Written for the Perl DTrace provider.
5235368Sgnn *
6235368Sgnn * $Id: pl_syscalls.d 25 2007-09-12 09:51:58Z brendan $
7235368Sgnn *
8235368Sgnn * USAGE: pl_syscalls.d { -p PID | -c cmd }	# hit Ctrl-C to end
9235368Sgnn *
10235368Sgnn * FIELDS:
11235368Sgnn *		FILE		Filename of the Perl program
12235368Sgnn *		TYPE		Type of call (sub/syscall)
13235368Sgnn *		NAME		Name of call
14235368Sgnn *		COUNT		Number of calls during sample
15235368Sgnn *
16235368Sgnn * Filename and subroutine names are printed if available.
17235368Sgnn * The filename for syscalls may be printed as "perl", if the program
18235368Sgnn * was invoked using the form "perl filename" rather than running the
19235368Sgnn * program with an interpreter line.
20235368Sgnn *
21235368Sgnn * COPYRIGHT: Copyright (c) 2007 Brendan Gregg.
22235368Sgnn *
23235368Sgnn * CDDL HEADER START
24235368Sgnn *
25235368Sgnn *  The contents of this file are subject to the terms of the
26235368Sgnn *  Common Development and Distribution License, Version 1.0 only
27235368Sgnn *  (the "License").  You may not use this file except in compliance
28235368Sgnn *  with the License.
29235368Sgnn *
30235368Sgnn *  You can obtain a copy of the license at Docs/cddl1.txt
31235368Sgnn *  or http://www.opensolaris.org/os/licensing.
32235368Sgnn *  See the License for the specific language governing permissions
33235368Sgnn *  and limitations under the License.
34235368Sgnn *
35235368Sgnn * CDDL HEADER END
36235368Sgnn *
37235368Sgnn * 09-Sep-2007	Brendan Gregg	Created this.
38235368Sgnn */
39235368Sgnn
40235368Sgnn#pragma D option quiet
41235368Sgnn
42235368Sgnnself string filename;
43235368Sgnn
44235368Sgnndtrace:::BEGIN
45235368Sgnn{
46235368Sgnn	printf("Tracing... Hit Ctrl-C to end.\n");
47235368Sgnn}
48235368Sgnn
49235368Sgnnperl$target:::sub-entry
50235368Sgnn{
51235368Sgnn	@calls[basename(copyinstr(arg1)), "sub", copyinstr(arg0)] = count();
52235368Sgnn}
53235368Sgnn
54235368Sgnnsyscall:::entry
55235368Sgnn/pid == $target/
56235368Sgnn{
57235368Sgnn	@calls[basename(execname), "syscall", probefunc] = count();
58235368Sgnn}
59235368Sgnn
60235368Sgnndtrace:::END
61235368Sgnn{
62235368Sgnn	printf("\nCalls for PID %d,\n\n", $target);
63235368Sgnn	printf(" %-32s %-10s %-22s %8s\n", "FILE", "TYPE", "NAME", "COUNT");
64235368Sgnn	printa(" %-32s %-10s %-22s %@8d\n", @calls);
65235368Sgnn}
66