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