rb_syscolors.d revision 267654
1198090Srdivacky#!/usr/sbin/dtrace -Zs 2198090Srdivacky/* 3198090Srdivacky * rb_syscolors.d - trace Ruby method flow plus syscalls, in color. 4198090Srdivacky * Written for the Ruby DTrace provider. 5198090Srdivacky * 6198090Srdivacky * $Id: rb_syscolors.d 27 2007-09-13 09:26:01Z brendan $ 7198090Srdivacky * 8198090Srdivacky * USAGE: rb_syscolors.d { -p PID | -c cmd } # hit Ctrl-C to end 9198090Srdivacky * 10198090Srdivacky * This watches Ruby method entries and returns, and indents child 11202375Srdivacky * function calls. 12198090Srdivacky * 13251662Sdim * FIELDS: 14202375Srdivacky * C CPU-id 15218893Sdim * PID Process ID 16198090Srdivacky * DELTA(us) Elapsed time from previous line to this line 17218893Sdim * FILE Filename of the Ruby program 18198090Srdivacky * LINE Line number of filename 19198090Srdivacky * TYPE Type of call (method/line/syscall) 20207618Srdivacky * NAME Ruby method or syscall name 21198090Srdivacky * 22198090Srdivacky * Filename and method names are printed if available. 23198090Srdivacky * 24202878Srdivacky * WARNING: Watch the first column carefully, it prints the CPU-id. If it 25202375Srdivacky * changes, then it is very likely that the output has been shuffled. 26239462Sdim * 27198090Srdivacky * COPYRIGHT: Copyright (c) 2007 Brendan Gregg. 28202878Srdivacky * 29202878Srdivacky * CDDL HEADER START 30198090Srdivacky * 31198090Srdivacky * The contents of this file are subject to the terms of the 32198090Srdivacky * Common Development and Distribution License, Version 1.0 only 33198090Srdivacky * (the "License"). You may not use this file except in compliance 34198090Srdivacky * with the License. 35263508Sdim * 36263508Sdim * You can obtain a copy of the license at Docs/cddl1.txt 37263508Sdim * or http://www.opensolaris.org/os/licensing. 38263508Sdim * See the License for the specific language governing permissions 39263508Sdim * and limitations under the License. 40263508Sdim * 41263508Sdim * CDDL HEADER END 42263508Sdim * 43263508Sdim * 09-Sep-2007 Brendan Gregg Created this. 44263508Sdim */ 45263508Sdim 46263508Sdim#pragma D option quiet 47263508Sdim#pragma D option switchrate=10 48263508Sdim 49263508Sdimself int depth; 50263508Sdim 51263508Sdimdtrace:::BEGIN 52263508Sdim{ 53263508Sdim /* 54263508Sdim * The following are terminal color escape sequences. 55263508Sdim * Change them to whatever you prefer, eg HTML font tags. 56263508Sdim */ 57263508Sdim color_ruby = "\033[2;35m"; /* violet, faint */ 58198090Srdivacky color_line = "\033[1;35m"; /* violet, bold */ 59251662Sdim color_syscall = "\033[2;32m"; /* green, faint */ 60251662Sdim color_off = "\033[0m"; /* default */ 61239462Sdim 62202878Srdivacky printf("%s %6s %10s %16s:%-4s %-8s -- %s\n", "C", "PID", "DELTA(us)", 63251662Sdim "FILE", "LINE", "TYPE", "NAME"); 64251662Sdim} 65251662Sdim 66251662Sdimruby$target:::function-entry, 67198090Srdivackyruby$target:::function-return, 68198090Srdivackyruby$target:::line, 69198090Srdivackysyscall:::entry, 70263508Sdimsyscall:::return 71263508Sdim/self->last == 0 && pid == $target/ 72221345Sdim{ 73198090Srdivacky self->last = timestamp; 74239462Sdim} 75218893Sdim 76218893Sdimruby$target:::function-entry 77198090Srdivacky{ 78218893Sdim this->delta = (timestamp - self->last) / 1000; 79198090Srdivacky this->name = strjoin(strjoin(copyinstr(arg0), "::"), copyinstr(arg1)); 80218893Sdim printf("%s%d %6d %10d %16s:%-4d %-8s %*s-> %s%s\n", color_ruby, 81198090Srdivacky cpu, pid, this->delta, basename(copyinstr(arg2)), arg3, "method", 82263508Sdim self->depth * 2, "", this->name, color_off); 83263508Sdim self->depth++; 84218893Sdim self->last = timestamp; 85198090Srdivacky} 86207618Srdivacky 87207618Srdivackyruby$target:::function-return 88207618Srdivacky{ 89239462Sdim this->delta = (timestamp - self->last) / 1000; 90207618Srdivacky this->name = strjoin(strjoin(copyinstr(arg0), "::"), copyinstr(arg1)); 91218893Sdim self->depth--; 92207618Srdivacky printf("%s%d %6d %10d %16s:%-4d %-8s %*s<- %s%s\n", color_ruby, 93263508Sdim cpu, pid, this->delta, basename(copyinstr(arg2)), arg3, "method", 94263508Sdim self->depth * 2, "", this->name, color_off); 95218893Sdim self->last = timestamp; 96207618Srdivacky} 97218893Sdim 98218893Sdimruby$target:::line 99218893Sdim{ 100207618Srdivacky this->delta = (timestamp - self->last) / 1000; 101218893Sdim printf("%s%d %6d %10d %16s:%-4d %-8s %*s-- %s\n", color_line, 102207618Srdivacky cpu, pid, this->delta, basename(copyinstr(arg0)), arg1, "line", 103218893Sdim self->depth * 2, "", color_off); 104207618Srdivacky self->last = timestamp; 105218893Sdim} 106207618Srdivacky 107239462Sdimsyscall:::entry 108207618Srdivacky/pid == $target/ 109218893Sdim{ 110207618Srdivacky this->delta = (timestamp - self->last) / 1000; 111218893Sdim printf("%s%d %6d %10d %16s:- %-8s %*s-> %s%s\n", color_syscall, 112207618Srdivacky cpu, pid, this->delta, "\"", "syscall", self->depth * 2, "", 113239462Sdim probefunc, color_off); 114207618Srdivacky self->depth++; 115198090Srdivacky self->last = timestamp; 116218893Sdim} 117218893Sdim 118218893Sdimsyscall:::return 119218893Sdim/pid == $target/ 120218893Sdim{ 121218893Sdim this->delta = (timestamp - self->last) / 1000; 122218893Sdim self->depth--; 123218893Sdim printf("%s%d %6d %10d %16s:- %-8s %*s<- %s%s\n", color_syscall, 124218893Sdim cpu, pid, this->delta, "\"", "syscall", self->depth * 2, "", 125218893Sdim probefunc, color_off); 126218893Sdim self->last = timestamp; 127218893Sdim} 128218893Sdim 129218893Sdimproc:::exit 130218893Sdim/pid == $target/ 131218893Sdim{ 132218893Sdim exit(0); 133218893Sdim} 134218893Sdim