3 * pl_malloc.d - Perl libc malloc analysis.
4 * Written for the Perl DTrace provider.
6 * $Id: pl_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 Perl subroutine, then that subroutine is
11 * identified as responsible; else the caller of malloc() is identified as
12 * responsible - which will be a function from the Perl engine.
14 * USAGE: pl_malloc.d { -p PID | -c cmd } # hit Ctrl-C to end
16 * Filename and subroutine 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 perl$target:::sub-entry
46 self->file = basename(copyinstr(arg1));
47 self->name = copyinstr(arg0);
50 perl$target:::sub-return
56 pid$target:libc:malloc:entry
59 @malloc_sub_size[self->file, self->name] = sum(arg0);
60 @malloc_sub_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("\nPerl malloc byte distributions by engine caller,\n\n");
74 printa(" %A, total bytes = %@d %@d\n", @malloc_lib_size,
77 printf("\nPerl malloc byte distributions by Perl file and ");
78 printf("subroutine,\n\n");
79 printa(" %s, %s, bytes total = %@d %@d\n", @malloc_sub_size,