3 * py_malloc.d - Python libc malloc analysis.
4 * Written for the Python DTrace provider.
6 * $Id: py_malloc.d 19 2007-09-12 07:47:59Z brendan $
8 * This is an expiremental script to identify who is calling malloc() for
9 * memory allocation, and to print distribution plots of the requested bytes.
10 * If a malloc() occured while in a Python function, then that function is
11 * identified as responsible; else the caller of malloc() is identified as
12 * responsible - which will be a function from the Python engine.
14 * USAGE: py_malloc.d { -p PID | -c cmd } # hit Ctrl-C to end
16 * Filename and function names are printed if available.
18 * COPYRIGHT: Copyright (c) 2007 Brendan Gregg.
22 * The contents of this file are subject to the terms of the
23 * Common Development and Distribution License, Version 1.0 only
24 * (the "License"). You may not use this file except in compliance
27 * You can obtain a copy of the license at Docs/cddl1.txt
28 * or http://www.opensolaris.org/os/licensing.
29 * See the License for the specific language governing permissions
30 * and limitations under the License.
34 * 09-Sep-2007 Brendan Gregg Created this.
37 #pragma D option quiet
41 printf("Tracing... Hit Ctrl-C to end.\n");
44 python$target:::function-entry
46 self->file = basename(copyinstr(arg0));
47 self->name = copyinstr(arg1);
50 python$target:::function-return
56 pid$target:libc:malloc:entry
59 @malloc_func_size[self->file, self->name] = sum(arg0);
60 @malloc_func_dist[self->file, self->name] = quantize(arg0);
63 pid$target:libc:malloc:entry
66 @malloc_lib_size[usym(ucaller)] = sum(arg0);
67 @malloc_lib_dist[usym(ucaller)] = quantize(arg0);
73 printf("\nPython malloc byte distributions by engine caller,\n\n");
74 printa(" %A, total bytes = %@d %@d\n", @malloc_lib_size,
77 printf("\nPython malloc byte distributions by Python file and ");
78 printf("function,\n\n");
79 printa(" %s, %s, bytes total = %@d %@d\n", @malloc_func_size,