]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - cddl/contrib/dtracetoolkit/Ruby/rb_malloc.d
Copy head (r256279) to stable/10 as part of the 10.0-RELEASE cycle.
[FreeBSD/stable/10.git] / cddl / contrib / dtracetoolkit / Ruby / rb_malloc.d
1 #!/usr/sbin/dtrace -Zs
2 /*
3  * rb_malloc.d - Ruby operations and libc malloc statistics.
4  *               Written for the Ruby DTrace provider.
5  *
6  * $Id: rb_malloc.d 20 2007-09-12 09:28:22Z brendan $
7  *
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.
11  *
12  * USAGE: rb_malloc.d { -p PID | -c cmd }       # hit Ctrl-C to end
13  *
14  * FIELDS:
15  *              1               Filename of the Ruby program
16  *              2               Type of operation (method/objnew/startup)
17  *              3               Name of operation
18  *
19  * Filename and method names are printed if available.
20  *
21  * COPYRIGHT: Copyright (c) 2007 Brendan Gregg.
22  *
23  * CDDL HEADER START
24  *
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
28  *  with the License.
29  *
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.
34  *
35  * CDDL HEADER END
36  *
37  * 09-Sep-2007  Brendan Gregg   Created this.
38  */
39
40 #pragma D option quiet
41
42 self string filename;
43
44 dtrace:::BEGIN
45 {
46         printf("Tracing... Hit Ctrl-C to end.\n");
47 }
48
49 ruby$target:::function-entry
50 {
51         self->file = basename(copyinstr(arg2));
52         self->type = "method";
53         self->name = strjoin(strjoin(copyinstr(arg0), "::"), copyinstr(arg1));
54 }
55
56 ruby$target:::object-create-start
57 {
58         self->file = basename(copyinstr(arg1));
59         self->type = "objnew";
60         self->name = copyinstr(arg0);
61 }
62
63 pid$target:libc:malloc:entry
64 /self->file != NULL/
65 {
66         @mallocs[self->file, self->type, self->name] = quantize(arg0);
67 }
68
69 pid$target:libc:malloc:entry
70 /self->file == NULL/
71 {
72         @mallocs["ruby", "startup", "-"] = quantize(arg0);
73 }
74
75
76 dtrace:::END
77 {
78         printf("Ruby malloc byte distributions by recent Ruby operation,\n");
79         printa("   %s, %s, %s %@d\n", @mallocs);
80 }