You are currently viewing a snapshot of www.mozilla.org taken on April 21, 2008. Most of this content is highly out of date (some pages haven't been updated since the project began in 1998) and exists for historical purposes only. If there are any pages on this archive site that you think should be added back to www.mozilla.org, please file a bug.



While the profiler described here may still work, Venkman is now the preferred way to profile JavaScript. You don't need a special build to profile with Venkman. See the FAQ entry for more information.

javascript runtime profiler

What is it?

Runtime JavaScript profiler. Shows call paths w/ execution times, and number of compiles. (
syd, jband)

How do I build it?

Set environment variable:
  • Win32: XPC_TOOLS_SUPPORT=1 (Switch to MOZ_XPC_TOOLS_SUPPORT?)
  • Linux: Add --enable-xpctools to your configure line.
  • Mac: ? Probably needs a little build love.
then clobber and rebuild mozilla/js/src/xpconnect.

How do I run it?

Set the environment variable
MOZILLA_JS_PROFILER_OUTPUT to the filename you want data dumped to, run the build, and exit mozilla. Note, data collection will affect mozilla speed.

Interpreting profiler output

Here is a sample clause from a JS Profiler log file:
  chrome://global/content/strres.js
  [2,3] srGetStrBundleWithLocale() {27-46} {min 31, max 70 avg 50}
      [2,3] srGetStrBundle() {50-52} {min 37, max 76 avg 55}
      [2,2] () {1-162} {min 1, max 3 avg 2}
      [2,0] localeSwitching() {57-134}
      [2,3] srGetAppLocale() {5-23} {min 1, max 6 avg 3}
      [2,0] localeTo() {138-158}
      [2,0] selectLocale() {162-182}
The first line specifies the js file from which times were gathered. Each line below that is of the format:
  [A, B] C {D-E} F {G, H, I}
where:
  A -> The function compile count
  B -> The function call count
  C -> The function name
  D -> Base line number of the function in the JS file
  E -> Extent (last) line number of the function in the JS file
  F -> total size (net of malloc overhead) of JS function data structures
  G -> minimum time of execution in milliseconds
  H -> maximum time of execution, in milliseconds
  I -> average execution time of function, in milliseconds

  [#compiles, #calls] function {lines in file} {Tmin, Tmax, Tavg}
If the function call count (B) is zero, then times (F, G, and H) are not printed, this makes the output a bit easier to read.

Unnamed function (lambda) expressions (e.g. JS object methods) will be listed as "anonymous" functions.

Bugs/Issues

  • JS Profiler also doesn't appear to count loading/compilation time.
    Brendan notes that that XUL JS is compiled at load time (startup or first new window for a given XUL application), and never recompiled. So for profiling operations such as deleting 30 selected mail messages, compile time is 0. Also, JS compile time is better profiled with quantify, to show hotspots in the C code implementing the JS compiler (as opposed to script hotspots found by the JS profiler).
  • The collection code is rather primitive, so execution times will not be accurate for functions that executed recursively within themselves (syd).