1193323Sed#!/usr/sbin/dtrace -Zs 2193323Sed/* 3193323Sed * py_syscalls.d - count Python function calls and syscalls using DTrace. 4193323Sed * Written for the Python DTrace provider. 5193323Sed * 6193323Sed * $Id: py_syscalls.d,v 1.1.1.1 2015/09/30 22:01:09 christos Exp $ 7193323Sed * 8193323Sed * USAGE: py_syscalls.d { -p PID | -c cmd } # hit Ctrl-C to end 9193323Sed * 10193323Sed * FIELDS: 11193323Sed * FILE Filename of the Python program 12193323Sed * TYPE Type of call (func/syscall) 13193323Sed * NAME Name of call 14193323Sed * COUNT Number of calls during sample 15193323Sed * 16234353Sdim * Filename and function names are printed if available. 17193323Sed * The filename for syscalls may be printed as "python", if the program 18193323Sed * was invoked using the form "python filename" rather than running the 19193323Sed * program with an interpreter line. 20193323Sed * 21193323Sed * COPYRIGHT: Copyright (c) 2007 Brendan Gregg. 22193323Sed * 23193323Sed * CDDL HEADER START 24193323Sed * 25239462Sdim * The contents of this file are subject to the terms of the 26239462Sdim * Common Development and Distribution License, Version 1.0 only 27193323Sed * (the "License"). You may not use this file except in compliance 28193323Sed * with the License. 29193323Sed * 30239462Sdim * You can obtain a copy of the license at Docs/cddl1.txt 31193323Sed * or http://www.opensolaris.org/os/licensing. 32193323Sed * See the License for the specific language governing permissions 33195340Sed * and limitations under the License. 34212904Sdim * 35239462Sdim * CDDL HEADER END 36193323Sed * 37239462Sdim * 09-Sep-2007 Brendan Gregg Created this. 38239462Sdim */ 39239462Sdim 40193323Sed#pragma D option quiet 41218893Sdim 42218893Sdimdtrace:::BEGIN 43218893Sdim{ 44193323Sed printf("Tracing... Hit Ctrl-C to end.\n"); 45198090Srdivacky} 46193323Sed 47193323Sedpython$target:::function-entry 48198090Srdivacky{ 49239462Sdim @calls[basename(copyinstr(arg0)), "func", copyinstr(arg1)] = count(); 50239462Sdim} 51239462Sdim 52239462Sdimsyscall:::entry 53193323Sed/pid == $target/ 54193323Sed{ 55193323Sed @calls[basename(execname), "syscall", probefunc] = count(); 56193323Sed} 57218893Sdim 58193323Seddtrace:::END 59193323Sed{ 60193323Sed printf("\nCalls for PID %d,\n\n", $target); 61193323Sed printf(" %-32s %-10s %-22s %8s\n", "FILE", "TYPE", "NAME", "COUNT"); 62198090Srdivacky printa(" %-32s %-10s %-22s %@8d\n", @calls); 63239462Sdim} 64218893Sdim