1*c29d5175Schristos #!/usr/sbin/dtrace -Zs 2*c29d5175Schristos /* 3*c29d5175Schristos * rb_malloc.d - Ruby operations and libc malloc statistics. 4*c29d5175Schristos * Written for the Ruby DTrace provider. 5*c29d5175Schristos * 6*c29d5175Schristos * $Id: rb_malloc.d,v 1.1.1.1 2015/09/30 22:01:09 christos Exp $ 7*c29d5175Schristos * 8*c29d5175Schristos * WARNING: This script is not 100% accurate; This prints libc malloc() byte 9*c29d5175Schristos * distributions by "recent" Ruby operation, which we hope will be usually 10*c29d5175Schristos * relevant. This is an experimental script that may be improved over time. 11*c29d5175Schristos * 12*c29d5175Schristos * USAGE: rb_malloc.d { -p PID | -c cmd } # hit Ctrl-C to end 13*c29d5175Schristos * 14*c29d5175Schristos * FIELDS: 15*c29d5175Schristos * 1 Filename of the Ruby program 16*c29d5175Schristos * 2 Type of operation (method/objnew/startup) 17*c29d5175Schristos * 3 Name of operation 18*c29d5175Schristos * 19*c29d5175Schristos * Filename and method names are printed if available. 20*c29d5175Schristos * 21*c29d5175Schristos * COPYRIGHT: Copyright (c) 2007 Brendan Gregg. 22*c29d5175Schristos * 23*c29d5175Schristos * CDDL HEADER START 24*c29d5175Schristos * 25*c29d5175Schristos * The contents of this file are subject to the terms of the 26*c29d5175Schristos * Common Development and Distribution License, Version 1.0 only 27*c29d5175Schristos * (the "License"). You may not use this file except in compliance 28*c29d5175Schristos * with the License. 29*c29d5175Schristos * 30*c29d5175Schristos * You can obtain a copy of the license at Docs/cddl1.txt 31*c29d5175Schristos * or http://www.opensolaris.org/os/licensing. 32*c29d5175Schristos * See the License for the specific language governing permissions 33*c29d5175Schristos * and limitations under the License. 34*c29d5175Schristos * 35*c29d5175Schristos * CDDL HEADER END 36*c29d5175Schristos * 37*c29d5175Schristos * 09-Sep-2007 Brendan Gregg Created this. 38*c29d5175Schristos */ 39*c29d5175Schristos 40*c29d5175Schristos #pragma D option quiet 41*c29d5175Schristos 42*c29d5175Schristos self string filename; 43*c29d5175Schristos 44*c29d5175Schristos dtrace:::BEGIN 45*c29d5175Schristos { 46*c29d5175Schristos printf("Tracing... Hit Ctrl-C to end.\n"); 47*c29d5175Schristos } 48*c29d5175Schristos 49*c29d5175Schristos ruby$target:::function-entry 50*c29d5175Schristos { 51*c29d5175Schristos self->file = basename(copyinstr(arg2)); 52*c29d5175Schristos self->type = "method"; 53*c29d5175Schristos self->name = strjoin(strjoin(copyinstr(arg0), "::"), copyinstr(arg1)); 54*c29d5175Schristos } 55*c29d5175Schristos 56*c29d5175Schristos ruby$target:::object-create-start 57*c29d5175Schristos { 58*c29d5175Schristos self->file = basename(copyinstr(arg1)); 59*c29d5175Schristos self->type = "objnew"; 60*c29d5175Schristos self->name = copyinstr(arg0); 61*c29d5175Schristos } 62*c29d5175Schristos 63*c29d5175Schristos pid$target:libc:malloc:entry 64*c29d5175Schristos /self->file != NULL/ 65*c29d5175Schristos { 66*c29d5175Schristos @mallocs[self->file, self->type, self->name] = quantize(arg0); 67*c29d5175Schristos } 68*c29d5175Schristos 69*c29d5175Schristos pid$target:libc:malloc:entry 70*c29d5175Schristos /self->file == NULL/ 71*c29d5175Schristos { 72*c29d5175Schristos @mallocs["ruby", "startup", "-"] = quantize(arg0); 73*c29d5175Schristos } 74*c29d5175Schristos 75*c29d5175Schristos 76*c29d5175Schristos dtrace:::END 77*c29d5175Schristos { 78*c29d5175Schristos printf("Ruby malloc byte distributions by recent Ruby operation,\n"); 79*c29d5175Schristos printa(" %s, %s, %s %@d\n", @mallocs); 80*c29d5175Schristos } 81