I originally posted this at http://blogs.sun.com/brendan/entry/javascript_provider_ver_2_0.
About 2 months ago I posted an update to the JavaScript DTrace provider to Bugzilla. In case you are interested and missed it, here are some details. The new additions were:
- The ability to identify anonymous functions (js_function-info)
- Access to function entry arguments (js_function-args)
- Access to function return value (js_function-rval)
I was finding that the JavaScript provider was only helping with about 4 problems out of 10 (still, better than nothing). The improvements that I added should take that to around 8 out of 10, so it is now proving to be really useful.
Here are some before and after screenshots, tracing a simple JavaScript clock (it's enough to demonstrate the features without bogging down in application specifics),
Old:
# ./js_funcflow.d C TIME FILE -- FUNC 1 2007 May 31 06:07:13 clock2.html -> startTime 1 2007 May 31 06:07:13 clock2.html -> getHours 1 2007 May 31 06:07:13 clock2.html <- getHours 1 2007 May 31 06:07:13 clocklib.js -> padLibZero 1 2007 May 31 06:07:13 clocklib.js <- padLibZero 1 2007 May 31 06:07:13 clock2.html -> getMinutes 1 2007 May 31 06:07:13 clock2.html <- getMinutes 1 2007 May 31 06:07:13 clocklib.js -> padLibZero 1 2007 May 31 06:07:13 clocklib.js <- padLibZero 1 2007 May 31 06:07:13 clock2.html -> getSeconds 1 2007 May 31 06:07:13 clock2.html <- getSeconds 1 2007 May 31 06:07:13 clocklib.js -> padLibZero 1 2007 May 31 06:07:13 clocklib.js <- padLibZero 1 2007 May 31 06:07:13 clock2.html -> getElementById 1 2007 May 31 06:07:13 clock2.html <- getElementById 1 2007 May 31 06:07:13 clock2.html -> setTimeout 1 2007 May 31 06:07:13 clock2.html <- setTimeout 1 2007 May 31 06:07:13 clock2.html <- startTime ^C
New:
# ./js_argflow.d C TIME FILE -- FUNC() 1 2007 May 31 06:07:34 clock2.html -> startTime() 1 2007 May 31 06:07:34 clock2.html -> getHours() 1 2007 May 31 06:07:34 clock2.html <- startTime:9 = 0x80000000 1 2007 May 31 06:07:34 clocklib.js -> padLibZero(0x6) 1 2007 May 31 06:07:34 clocklib.js <- padLibZero:3 = 0x955fd70 1 2007 May 31 06:07:34 clock2.html -> getMinutes() 1 2007 May 31 06:07:34 clock2.html <- startTime:10 = 0x80000000 1 2007 May 31 06:07:34 clocklib.js -> padLibZero(0x7) 1 2007 May 31 06:07:34 clocklib.js <- padLibZero:3 = 0x955fd50 1 2007 May 31 06:07:34 clock2.html -> getSeconds() 1 2007 May 31 06:07:34 clock2.html <- startTime:11 = 0x80000000 1 2007 May 31 06:07:34 clocklib.js -> padLibZero(0x22) 1 2007 May 31 06:07:34 clocklib.js <- padLibZero:4 = 0x22 1 2007 May 31 06:07:34 clock2.html -> getElementById() 1 2007 May 31 06:07:34 clock2.html <- startTime:12 = 0x80000000 1 2007 May 31 06:07:34 clock2.html -> setTimeout() 1 2007 May 31 06:07:34 clock2.html <- startTime:13 = 0x80000000 1 2007 May 31 06:07:34 clock2.html <- startTime:13 = 0x80000000 ^C
Now there is some visibility for function arguments and return values. If arguments are strings, it is possible to print them as such from DTrace.
Old:
# ./js_funccalls.d Tracing... Hit Ctrl-C to end. ^C FILE FUNC CALLS clock2.html getElementById 1 clock2.html getHours 1 clock2.html getMinutes 1 clock2.html getSeconds 1 clock2.html setTimeout 1 clock2.html startTime 1 clocklib.js padLibZero 3
New:
# ./js_funcinfo.d Tracing... Hit Ctrl-C to end. ^C BASE[FILE:LINE] FUNCNAME RUN[FILE:LINE] CALLS clock2.html:7 getElementById clock2.html:12 1 clock2.html:7 getHours clock2.html:9 1 clock2.html:7 getMinutes clock2.html:10 1 clock2.html:7 getSeconds clock2.html:11 1 clock2.html:7 setTimeout clock2.html:13 1 clock2.html:7 startTime clock2.html:13 1 clocklib.js:2 padLibZero clock2.html:10 1 clocklib.js:2 padLibZero clock2.html:11 1 clocklib.js:2 padLibZero clock2.html:9 1
The "BASE" info describes where that function was declared or first referred to; the "RUN" info describes where that function was executed. These details are especially useful for tracing anonymous functions.
The scripts used above can be downloaded in a tar file from the OpenSolaris DTrace JavaScript site.
There are a number of people at Sun and at Mozilla helping to put DTrace probes in Mozilla, not just for JavaScript, but also for tracing browser latencies at a level which is useful for developers. For more information see the OpenSolaris page, and on Bugzilla: 370906, 388564.