1235368Sgnn#!/usr/sbin/dtrace -Zs 2/* 3 * js_flow.d - snoop JavaScript execution showing function flow using DTrace. 4 * Written for the JavaScript DTrace provider. 5 * 6 * $Id: js_flow.d 63 2007-10-04 04:34:38Z brendan $ 7 * 8 * This traces activity from all browsers on the system that are running 9 * with JavaScript provider support. 10 * 11 * USAGE: js_flow.d # hit Ctrl-C to end 12 * 13 * FIELDS: 14 * C CPU-id 15 * TIME(us) Time since boot, us 16 * FILE Filename that this function belongs to 17 * FUNC Function name 18 * 19 * LEGEND: 20 * -> function entry 21 * <- function return 22 * 23 * Filename and function names are printed if available. 24 * 25 * WARNING: Watch the first column carefully, it prints the CPU-id. If it 26 * changes, then it is very likely that the output has been shuffled. 27 * 28 * COPYRIGHT: Copyright (c) 2007 Brendan Gregg. 29 * 30 * CDDL HEADER START 31 * 32 * The contents of this file are subject to the terms of the 33 * Common Development and Distribution License, Version 1.0 only 34 * (the "License"). You may not use this file except in compliance 35 * with the License. 36 * 37 * You can obtain a copy of the license at Docs/cddl1.txt 38 * or http://www.opensolaris.org/os/licensing. 39 * See the License for the specific language governing permissions 40 * and limitations under the License. 41 * 42 * CDDL HEADER END 43 * 44 * 09-Sep-2007 Brendan Gregg Created this. 45 */ 46 47#pragma D option quiet 48#pragma D option switchrate=10 49 50self int depth; 51 52dtrace:::BEGIN 53{ 54 printf("%3s %-16s %-22s -- %s\n", "C", "TIME(us)", "FILE", "FUNC"); 55} 56 57javascript*:::function-entry 58{ 59 printf("%3d %-16d %-22s %*s-> %s\n", cpu, timestamp / 1000, 60 basename(copyinstr(arg0)), self->depth * 2, "", copyinstr(arg2)); 61 self->depth++; 62} 63 64javascript*:::function-return 65{ 66 self->depth -= self->depth > 0 ? 1 : 0; 67 printf("%3d %-16d %-22s %*s<- %s\n", cpu, timestamp / 1000, 68 basename(copyinstr(arg0)), self->depth * 2, "", copyinstr(arg2)); 69} 70