3 * js_cputime.d - measure JavaScript on-CPU times for types of operation.
4 * Written for the JavaScript DTrace provider.
6 * $Id: js_cputime.d 63 2007-10-04 04:34:38Z brendan $
8 * This traces JavaScript activity from all browsers running on the system with
9 * JavaScript provider support.
11 * USAGE: js_cputime.d # hit Ctrl-C to end
14 * FILE Filename of the JavaScript program
15 * TYPE Type of call (func/obj-new/gc/total)
17 * TOTAL Total on-CPU time for calls (us)
19 * Filename and function 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
44 printf("Tracing... Hit Ctrl-C to end.\n");
47 javascript*:::function-entry
50 self->exclude[self->depth] = 0;
51 self->function[self->depth] = vtimestamp;
54 javascript*:::function-return
55 /self->function[self->depth]/
57 this->oncpu_incl = vtimestamp - self->function[self->depth];
58 this->oncpu_excl = this->oncpu_incl - self->exclude[self->depth];
59 self->function[self->depth] = 0;
60 self->exclude[self->depth] = 0;
61 this->file = basename(copyinstr(arg0));
62 this->name = copyinstr(arg2);
64 @num[this->file, "func", this->name] = count();
65 @num["-", "total", "-"] = count();
66 @types_incl[this->file, "func", this->name] = sum(this->oncpu_incl);
67 @types_excl[this->file, "func", this->name] = sum(this->oncpu_excl);
68 @types_excl["-", "total", "-"] = sum(this->oncpu_excl);
71 self->exclude[self->depth] += this->oncpu_incl;
74 javascript*:::object-create-start
76 self->object = vtimestamp;
79 javascript*:::object-create-done
82 this->oncpu = vtimestamp - self->object;
84 this->file = basename(copyinstr(arg0));
85 this->name = copyinstr(arg1);
87 @num[this->file, "obj-new", this->name] = count();
88 @num["-", "total", "-"] = count();
89 @types[this->file, "obj-new", this->name] = sum(this->oncpu);
90 @types["-", "total", "-"] = sum(this->oncpu);
92 self->exclude[self->depth] += this->oncpu;
98 printf(" %-20s %-10s %-32s %8s\n", "FILE", "TYPE", "NAME", "COUNT");
99 printa(" %-20.20s %-10s %-32s %@8d\n", @num);
101 normalize(@types, 1000);
102 printf("\nElapsed times (us),\n");
103 printf(" %-20s %-10s %-32s %8s\n", "FILE", "TYPE", "NAME", "TOTAL");
104 printa(" %-20.20s %-10s %-32s %@8d\n", @types);
106 normalize(@types_excl, 1000);
107 printf("\nExclusive function on-CPU times (us),\n");
108 printf(" %-20s %-10s %-32s %8s\n", "FILE", "TYPE", "NAME", "TOTAL");
109 printa(" %-20.20s %-10s %-32s %@8d\n", @types_excl);
111 normalize(@types_incl, 1000);
112 printf("\nInclusive function on-CPU times (us),\n");
113 printf(" %-20s %-10s %-32s %8s\n", "FILE", "TYPE", "NAME", "TOTAL");
114 printa(" %-20.20s %-10s %-32s %@8d\n", @types_incl);