Ticket #1827 (new enhancement)
[patch][ccla] Step profiler
| Reported by: | robert.coup@… | Owned by: | rcoup |
|---|---|---|---|
| Priority: | normal | Milestone: | 1.2 |
| Component: | Dojox | Version: | 0.4 |
| Severity: | normal | Keywords: | |
| Cc: |
Description
Attached is code and tests for a step profiler, as dojo.profile.StepProfiler?. This is a global profiler which records the time since the previous step against the profile. You can then get results as an array or printed using dojo.debug.
Multiple profilers can be set up and act independently, and because the global profiler stores the data, a single profile can be 'stepped' in different functions without passing a variable around.
It is a really useful means of figuring out where time is spent in a process during development and testing.
It basically works as follows (there are more abilities but this is most of it):
function myFunc() {
// in this case our profile is called 'prof'
dojo.profile.StepProfiler.start("prof", "start");
... do something ...
dojo.profile.StepProfiler.start("prof", "step 1");
... do something ...
dojo.profile.StepProfiler.start("prof", "step 2");
... do something ...
dojo.profile.StepProfiler.start("prof", "step 3");
// print the results via dojo.debug
dojo.profile.StepProfiler.print("prof");
// get them as an array
var profileResults = dojo.profile.StepProfiler.toArray("prof");
// profileResults: [["start", 0], ["step 1", 8], ["step 2", 106], ["step 3", 1]]
}
printed results:
DEBUG: StepProfiler - prof: DEBUG: start: DEBUG: step 1: 8ms DEBUG: step 2: 106ms DEBUG: step 3: 1ms