py_syscalls.d revision 267654
1119418Sobrien#!/usr/sbin/dtrace -Zs 269953Smsmith/* 369953Smsmith * py_syscalls.d - count Python function calls and syscalls using DTrace. 469953Smsmith * Written for the Python DTrace provider. 569953Smsmith * 669953Smsmith * $Id: py_syscalls.d 25 2007-09-12 09:51:58Z brendan $ 769953Smsmith * 869953Smsmith * USAGE: py_syscalls.d { -p PID | -c cmd } # hit Ctrl-C to end 969953Smsmith * 1069953Smsmith * FIELDS: 1169953Smsmith * FILE Filename of the Python program 1269953Smsmith * TYPE Type of call (func/syscall) 1369953Smsmith * NAME Name of call 1469953Smsmith * COUNT Number of calls during sample 1569953Smsmith * 1669953Smsmith * Filename and function names are printed if available. 1769953Smsmith * The filename for syscalls may be printed as "python", if the program 1869953Smsmith * was invoked using the form "python filename" rather than running the 1969953Smsmith * program with an interpreter line. 2069953Smsmith * 2169953Smsmith * COPYRIGHT: Copyright (c) 2007 Brendan Gregg. 2269953Smsmith * 2369953Smsmith * CDDL HEADER START 2469953Smsmith * 2569953Smsmith * The contents of this file are subject to the terms of the 2669953Smsmith * Common Development and Distribution License, Version 1.0 only 27119418Sobrien * (the "License"). You may not use this file except in compliance 28119418Sobrien * with the License. 29119418Sobrien * 3069953Smsmith * You can obtain a copy of the license at Docs/cddl1.txt 31149478Sps * or http://www.opensolaris.org/os/licensing. 3269953Smsmith * See the License for the specific language governing permissions 3369953Smsmith * and limitations under the License. 3469953Smsmith * 3569953Smsmith * CDDL HEADER END 3669953Smsmith * 3769953Smsmith * 09-Sep-2007 Brendan Gregg Created this. 3869953Smsmith */ 3969953Smsmith 4069953Smsmith#pragma D option quiet 4183975Srwatson 4269953Smsmithdtrace:::BEGIN 4369953Smsmith{ 4469953Smsmith printf("Tracing... Hit Ctrl-C to end.\n"); 4569953Smsmith} 4669953Smsmith 4769953Smsmithpython$target:::function-entry 4869953Smsmith{ 4969953Smsmith @calls[basename(copyinstr(arg0)), "func", copyinstr(arg1)] = count(); 5069953Smsmith} 5169953Smsmith 5269953Smsmithsyscall:::entry 5369953Smsmith/pid == $target/ 5469953Smsmith{ 55119285Simp @calls[basename(execname), "syscall", probefunc] = count(); 56119285Simp} 5769953Smsmith 5869953Smsmithdtrace:::END 5969953Smsmith{ 6069953Smsmith printf("\nCalls for PID %d,\n\n", $target); 6169953Smsmith printf(" %-32s %-10s %-22s %8s\n", "FILE", "TYPE", "NAME", "COUNT"); 6269953Smsmith printa(" %-32s %-10s %-22s %@8d\n", @calls); 6369953Smsmith} 6469953Smsmith