DTrace-ing JavaScript

Arr! Me hearties! I be highly impressed to see that prime landlubber Brendan Gregg be applying the power of DTrace t’ JavaScript. For those o’ ye scurvy dogs that dunno, DTrace be this marvellous thing on Solaris that traces kernel calls. Apparently it be for more than that, though; see Brandan trace the JavaScript code

function padZero(i)
{
        if (i < 10) return "0" + i
        return i
}

function startTime()
{
        var now = new Date
        var time = padZero(now.getHours()) + ":" +
            padZero(now.getMinutes()) + ":" +
            padZero(now.getSeconds());
        document.getElementById('clock').innerHTML = "time: " + time + ""
        var timeout = setTimeout('startTime()', 1000)
}

and be gettin’ the followin’ output:

 FILE                   FUNC                          CALLS
 clock.html             getElementById                    9
 clock.html             getHours                          9
 clock.html             getMinutes                        9
 clock.html             getSeconds                        9
 clock.html             setTimeout                        9
 clock.html             startTime                         9
 clock.html             padZero                          27

as well as much more complex output t’ be seen below. Every day I be amazed at DTrace, and now I be even more amazed as it be useful for work that I actually do. Avast!

More in the discussion (powered by webmentions)

  • (no mentions, yet.)