3 * rb_malloc.d - Ruby operations and libc malloc statistics.
4 * Written for the Ruby DTrace provider.
6 * $Id: rb_malloc.d 20 2007-09-12 09:28:22Z brendan $
8 * WARNING: This script is not 100% accurate; This prints libc malloc() byte
9 * distributions by "recent" Ruby operation, which we hope will be usually
10 * relevant. This is an experimental script that may be improved over time.
12 * USAGE: rb_malloc.d { -p PID | -c cmd } # hit Ctrl-C to end
15 * 1 Filename of the Ruby program
16 * 2 Type of operation (method/objnew/startup)
19 * Filename and method names are printed if available.
21 * COPYRIGHT: Copyright (c) 2007 Brendan Gregg.
25 * The contents of this file are subject to the terms of the
26 * Common Development and Distribution License, Version 1.0 only
27 * (the "License"). You may not use this file except in compliance
30 * You can obtain a copy of the license at Docs/cddl1.txt
31 * or http://www.opensolaris.org/os/licensing.
32 * See the License for the specific language governing permissions
33 * and limitations under the License.
37 * 09-Sep-2007 Brendan Gregg Created this.
40 #pragma D option quiet
46 printf("Tracing... Hit Ctrl-C to end.\n");
49 ruby$target:::function-entry
51 self->file = basename(copyinstr(arg2));
52 self->type = "method";
53 self->name = strjoin(strjoin(copyinstr(arg0), "::"), copyinstr(arg1));
56 ruby$target:::object-create-start
58 self->file = basename(copyinstr(arg1));
59 self->type = "objnew";
60 self->name = copyinstr(arg0);
63 pid$target:libc:malloc:entry
66 @mallocs[self->file, self->type, self->name] = quantize(arg0);
69 pid$target:libc:malloc:entry
72 @mallocs["ruby", "startup", "-"] = quantize(arg0);
78 printf("Ruby malloc byte distributions by recent Ruby operation,\n");
79 printa(" %s, %s, %s %@d\n", @mallocs);