The Open Anzo Project

Semantic Application Middleware

Anzo.js Profiling API

Anzo.js includes support for timing JavaScript operations. Anzo.js integrates the Jiffy-web profiling tool so all of the tools that work with Jiffy-web can be used with the anzo.profiling API.

Timing Measurements

The anzo.profiling API gives methods for recording elapsed time measurements in JavaScript. Those measurements can be later viewed using a Firebug extension or uploaded to a server and analyzed.

A simple example of taking measurements.

anzo.profiling.mark("ReadingInitData");
// do some work...
anzo.profiling.measure("DoneLoadingInitData", "ReadingInitData");
// do some more work...
anzo.profiling.measure("DoneParsingInitData", "ReadingInitData");

Using The API

To use the profiling API, you must do three things:

  1. Load the jiffy.js file.
  2. Include the anzo.profiling module
  3. Call measurement methods

Loading the jiffy.js file

Inside you application HTML somewhere, you need to add a script tag reference to the jiffy.js file.

<html>
<head>
  <script type="text/javascript">
    JiffyOptions = {
        SEND_MEASURES : false,
        BROWSER_EVENTS : {}
    }
  </script>
  <script type="text/javascript" src="/anzo/profiling/jiffy.js"></script>
  ...
</head>
<body>
...
</body>
</html>

WARNING: If you forget to do this or this step doesn't work, the anzo.profiling API will still have stub methods that won't do anything.

You can set all of the various Jiffy options by creating the JiffyOptions and JiffyParams global variables before loading the jiffy.js file. See the Jiffy documentation for more information. For experimenting and quick profiling, it is useful to set the SEND_MEASURES option to false. That turns off the Jiffy functionality which sends measurement data to a server. This way you can keep the measurements on the client and view them using the Jiffy Firebug extension.

Including the anzo.profiling module

Inside your code, use dojo.require to load the anzo.profiling API.

<html>
<head>
  ...
  <script type="text/javascript" src="/anzo/profiling/jiffy.js"></script>
  <script type="text/javascript">
    dojo.require("anzo.profiling");
  </script>
</head>
<body>
...
</body>
</html>

Call measurement methods

Now you can measure elapsed time between your operations.

<html>
<head>
  ...
  <script type="text/javascript" src="/anzo/profiling/jiffy.js"></script>
  <script type="text/javascript">
    dojo.require("anzo.profiling");

    // do stuff...

    anzo.profiling.mark("ReadingInitData");
    // do some work...
    anzo.profiling.measure("DoneLoadingInitData", "ReadingInitData");
    // do some more work...
    anzo.profiling.measure("DoneParsingInitData", "ReadingInitData");
  </script>
</head>
<body>
...
</body>
</html>

Turning Off Profiling

The profiling statements can be left in your code and profiling can be disabled. If you don't load the jiffy.js file then the anzo.profiling methods will still exist but they will be completely empty stubs. That way most of the overhead to the calls goes away while letting you avoid having to change your code between production and testing.

You can also use the Jiffy option, USE_JIFFY, to disable the system.

Viewing the Measurements

The Jiffy Firebug extension is a useful tool to view the measurements.

Also, the Jiffy-web tools have some visualization tools for viewing results that are in a database.

Attachments

Copyright © 2007 - 2009 OpenAnzo.org