1 1.1 christos #!/usr/sbin/dtrace -Zs 2 1.1 christos /* 3 1.1 christos * py_who.d - trace Python function execution by process using DTrace. 4 1.1 christos * Written for the Python DTrace provider. 5 1.1 christos * 6 1.1 christos * $Id: py_who.d,v 1.1.1.1 2015/09/30 22:01:09 christos Exp $ 7 1.1 christos * 8 1.1 christos * This traces Python activity from all Python programs on the system that are 9 1.1 christos * running with Python provider support. 10 1.1 christos * 11 1.1 christos * USAGE: py_who.d # hit Ctrl-C to end 12 1.1 christos * 13 1.1 christos * FIELDS: 14 1.1 christos * PID Process ID of Python 15 1.1 christos * UID User ID of the owner 16 1.1 christos * FUNCS Number of function calls 17 1.1 christos * FILE Pathname of the Python program 18 1.1 christos * 19 1.1 christos * Filenames are printed if available. 20 1.1 christos * 21 1.1 christos * COPYRIGHT: Copyright (c) 2007 Brendan Gregg. 22 1.1 christos * 23 1.1 christos * CDDL HEADER START 24 1.1 christos * 25 1.1 christos * The contents of this file are subject to the terms of the 26 1.1 christos * Common Development and Distribution License, Version 1.0 only 27 1.1 christos * (the "License"). You may not use this file except in compliance 28 1.1 christos * with the License. 29 1.1 christos * 30 1.1 christos * You can obtain a copy of the license at Docs/cddl1.txt 31 1.1 christos * or http://www.opensolaris.org/os/licensing. 32 1.1 christos * See the License for the specific language governing permissions 33 1.1 christos * and limitations under the License. 34 1.1 christos * 35 1.1 christos * CDDL HEADER END 36 1.1 christos * 37 1.1 christos * 09-Sep-2007 Brendan Gregg Created this. 38 1.1 christos */ 39 1.1 christos 40 1.1 christos #pragma D option quiet 41 1.1 christos 42 1.1 christos dtrace:::BEGIN 43 1.1 christos { 44 1.1 christos printf("Tracing... Hit Ctrl-C to end.\n"); 45 1.1 christos } 46 1.1 christos 47 1.1 christos python*:::function-entry 48 1.1 christos { 49 1.1 christos @lines[pid, uid, copyinstr(arg0)] = count(); 50 1.1 christos } 51 1.1 christos 52 1.1 christos dtrace:::END 53 1.1 christos { 54 1.1 christos printf(" %6s %6s %6s %s\n", "PID", "UID", "FUNCS", "FILE"); 55 1.1 christos printa(" %6d %6d %@6d %s\n", @lines); 56 1.1 christos } 57