Seadragon.Profiler class

Version - Back to Seadragon Ajax Library

Overview

A utility class for profiling regular updates. Times the length of each update as well as the idle periods between updates. For both, tracks the minimum, average and maximum times. All times are in milliseconds.

Constructors

Signature Description
Seadragon.Profiler() Creates a Profiler.

Methods

General Accessors

Name and Signature Return Type Description
isMidUpdate() Boolean Returns true if an update has begun but has not yet ended.
getNumUpdates() Number Returns the number of updates that have been profiled.

Update Time Accessors

Name and Signature Return Type Description
getAvgUpdateTime() Number Returns the average length of each update.
getMinUpdateTime() Number Returns the length of the shortest update.
getMaxUpdateTime() Number Returns the length of the longest update.

Idle Time Accessors

Name and Signature Return Type Description
getAvgIdleTime() Number Returns the average length of each idle period between two updates.
getMinIdleTime() Number Returns the length of the shortest idle period between two updates.
getMaxIdleTime() Number Returns the length of the longest idle period between two updates.

Modifiers

Name and Signature Return Type Description
beginUpdate() - Signals to the Profiler that an update has begun.
endUpdate() - Signals to the Profiler that the last update has ended.
clearProfile() - Clears all previously tracked information.

Example Usage

The following code profiles an update function. The function is run on a timer, and the average update time is shown when a button is clicked.

var profiler = new Seadragon.Profiler(); var button = document.getElementById("show_profile_button"); function update() { profiler.beginUpdate(); ... profiler.endUpdate(); } window.setInterval(update, 50); Seadragon.Utils.addEvent(button, "click", function() { alert("Average update time = " + profiler.getAvgUpdateTime()); });

The following code shows a computed updates per second value.

function showProfile(profiler) { var period = profiler.getAvgUpdateTime() + profiler.getAvgIdleTime(); var freq = 1000 / period; // 1000 milliseconds in 1 second alert("Averaging " + freq + " updates per second over " + profiler.getNumUpdates() + " updates."); }