1*c29d5175Schristos #!/usr/sbin/dtrace -Zs 2*c29d5175Schristos /* 3*c29d5175Schristos * py_mallocstk.d - Python libc malloc analysis with full stack traces. 4*c29d5175Schristos * Written for the Python DTrace provider. 5*c29d5175Schristos * 6*c29d5175Schristos * $Id: py_mallocstk.d,v 1.1.1.1 2015/09/30 22:01:09 christos Exp $ 7*c29d5175Schristos * 8*c29d5175Schristos * USAGE: py_mallocstk.d { -p PID | -c cmd } # hit Ctrl-C to end 9*c29d5175Schristos * 10*c29d5175Schristos * COPYRIGHT: Copyright (c) 2007 Brendan Gregg. 11*c29d5175Schristos * 12*c29d5175Schristos * CDDL HEADER START 13*c29d5175Schristos * 14*c29d5175Schristos * The contents of this file are subject to the terms of the 15*c29d5175Schristos * Common Development and Distribution License, Version 1.0 only 16*c29d5175Schristos * (the "License"). You may not use this file except in compliance 17*c29d5175Schristos * with the License. 18*c29d5175Schristos * 19*c29d5175Schristos * You can obtain a copy of the license at Docs/cddl1.txt 20*c29d5175Schristos * or http://www.opensolaris.org/os/licensing. 21*c29d5175Schristos * See the License for the specific language governing permissions 22*c29d5175Schristos * and limitations under the License. 23*c29d5175Schristos * 24*c29d5175Schristos * CDDL HEADER END 25*c29d5175Schristos * 26*c29d5175Schristos * 09-Sep-2007 Brendan Gregg Created this. 27*c29d5175Schristos */ 28*c29d5175Schristos 29*c29d5175Schristos #pragma D option quiet 30*c29d5175Schristos 31*c29d5175Schristos /* tune as desired, */ 32*c29d5175Schristos #pragma D option jstackframes=64 33*c29d5175Schristos #pragma D option jstackstrsize=1024 34*c29d5175Schristos 35*c29d5175Schristos dtrace:::BEGIN 36*c29d5175Schristos { 37*c29d5175Schristos printf("Tracing... Hit Ctrl-C to end.\n"); 38*c29d5175Schristos } 39*c29d5175Schristos 40*c29d5175Schristos pid$target:libc:malloc:entry 41*c29d5175Schristos { 42*c29d5175Schristos @mallocs[jstack()] = quantize(arg0); 43*c29d5175Schristos } 44*c29d5175Schristos 45*c29d5175Schristos dtrace:::END 46*c29d5175Schristos { 47*c29d5175Schristos printf("\nPython malloc byte distributions by stack trace,\n\n"); 48*c29d5175Schristos printa(@mallocs); 49*c29d5175Schristos } 50