1 1.1 christos #!/usr/sbin/dtrace -Zs 2 1.1 christos /* 3 1.1 christos * py_flowinfo.d - snoop Python function flow with info using DTrace. 4 1.1 christos * Written for the Python DTrace provider. 5 1.1 christos * 6 1.1 christos * $Id: py_flowinfo.d,v 1.1.1.1 2015/09/30 22:01:09 christos Exp $ 7 1.1 christos * 8 1.1 christos * This traces 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_flowinfo.d # hit Ctrl-C to end 12 1.1 christos * 13 1.1 christos * FIELDS: 14 1.1 christos * C CPU-id 15 1.1 christos * PID Process ID 16 1.1 christos * DELTA(us) Elapsed time from previous line to this line 17 1.1 christos * FILE Filename of the Python program 18 1.1 christos * LINE Line number of filename 19 1.1 christos * TYPE Type of call (func) 20 1.1 christos * FUNC Python function 21 1.1 christos * 22 1.1 christos * LEGEND: 23 1.1 christos * -> function entry 24 1.1 christos * <- function return 25 1.1 christos * 26 1.1 christos * Filename and function names are printed if available. 27 1.1 christos * 28 1.1 christos * WARNING: Watch the first column carefully, it prints the CPU-id. If it 29 1.1 christos * changes, then it is very likely that the output has been shuffled. 30 1.1 christos * 31 1.1 christos * COPYRIGHT: Copyright (c) 2007 Brendan Gregg. 32 1.1 christos * 33 1.1 christos * CDDL HEADER START 34 1.1 christos * 35 1.1 christos * The contents of this file are subject to the terms of the 36 1.1 christos * Common Development and Distribution License, Version 1.0 only 37 1.1 christos * (the "License"). You may not use this file except in compliance 38 1.1 christos * with the License. 39 1.1 christos * 40 1.1 christos * You can obtain a copy of the license at Docs/cddl1.txt 41 1.1 christos * or http://www.opensolaris.org/os/licensing. 42 1.1 christos * See the License for the specific language governing permissions 43 1.1 christos * and limitations under the License. 44 1.1 christos * 45 1.1 christos * CDDL HEADER END 46 1.1 christos * 47 1.1 christos * 09-Sep-2007 Brendan Gregg Created this. 48 1.1 christos */ 49 1.1 christos 50 1.1 christos #pragma D option quiet 51 1.1 christos #pragma D option switchrate=10 52 1.1 christos 53 1.1 christos self int depth; 54 1.1 christos 55 1.1 christos dtrace:::BEGIN 56 1.1 christos { 57 1.1 christos printf("%s %6s %10s %16s:%-4s %-8s -- %s\n", "C", "PID", "DELTA(us)", 58 1.1 christos "FILE", "LINE", "TYPE", "FUNC"); 59 1.1 christos } 60 1.1 christos 61 1.1 christos python*:::function-entry, 62 1.1 christos python*:::function-return 63 1.1 christos /self->last == 0/ 64 1.1 christos { 65 1.1 christos self->last = timestamp; 66 1.1 christos } 67 1.1 christos 68 1.1 christos python*:::function-entry 69 1.1 christos { 70 1.1 christos this->delta = (timestamp - self->last) / 1000; 71 1.1 christos printf("%d %6d %10d %16s:%-4d %-8s %*s-> %s\n", cpu, pid, this->delta, 72 1.1 christos basename(copyinstr(arg0)), arg2, "func", self->depth * 2, "", 73 1.1 christos copyinstr(arg1)); 74 1.1 christos self->depth++; 75 1.1 christos self->last = timestamp; 76 1.1 christos } 77 1.1 christos 78 1.1 christos python*:::function-return 79 1.1 christos { 80 1.1 christos this->delta = (timestamp - self->last) / 1000; 81 1.1 christos self->depth -= self->depth > 0 ? 1 : 0; 82 1.1 christos printf("%d %6d %10d %16s:%-4d %-8s %*s<- %s\n", cpu, pid, this->delta, 83 1.1 christos basename(copyinstr(arg0)), arg2, "func", self->depth * 2, "", 84 1.1 christos copyinstr(arg1)); 85 1.1 christos self->last = timestamp; 86 1.1 christos } 87