Ticket #1827 (new enhancement)

Opened 21 months ago

Last modified 5 months ago

[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

Attachments

step_profiler.patch (11.3 kB) - added by robert.coup@… 21 months ago.
initial patch
step_profiler.2.patch (5.7 kB) - added by robert.coup@… 21 months ago.
initial patch
step_profiler.3.patch (5.7 kB) - added by robert.coup@… 18 months ago.
New patch where start() returns an object with methods.

Change History

Changed 21 months ago by robert.coup@…

initial patch

Changed 21 months ago by robert.coup@…

initial patch

Changed 21 months ago by robert.coup@…

everything is repeated in the first patch (TortoiseSVN has 'issues' sometimes), so use the 2nd 'initial' one :)

Changed 20 months ago by alex

  • status changed from new to assigned
  • owner changed from anonymous to alex

might it be a better API to return a "stepping" object that would allow you to remove some of the redundancy in the step calls? I like the idea...I kinda wonder if it could be rolled into the current profiling code without many changes or if they're too different. I'd hate to not have a unified API location for it.

Changed 20 months ago by robert.coup@…

might it be a better API to return a "stepping" object that would allow you to remove some of the redundancy in the step calls?

That was my initial plan, but passing things through attached event handlers and callbacks is not neccessarily fun, so I deliberately went with the global registry. For cases like that people (me) are much less inclined to profile if they have to pass objects around through half a dozen methods.

But for simple cases, it does make sense. Maybe a hybrid where the calls return an object which you can then call step() on again - but its just a reference to the global profile?

Changed 20 months ago by alex

  • milestone set to 0.5

Changed 18 months ago by robert.coup@…

Ok, new patch.

start() now returns an object you can call step(), print(), toArray(), and reset() on. The same profile is still accessible from the global methods.

Tests have been updated to suit (not that I can run them in the harness because 'ant test' hangs after umpteen failures in other code).

Changed 18 months ago by robert.coup@…

New patch where start() returns an object with methods.

Changed 18 months ago by robert.coup@…

I kinda wonder if it could be rolled into the current profiling code without many changes or if they're too different. I'd hate to not have a unified API location for it.

Any suggestions on this? The current dojo profile code enables you to run a function a lot of times and then prints the results.

For tying into functions and seeing where time is spent there is the Firebug profiler, but seeing that getComputedStyle() is using 50% of the time unfortunately doesn't help find where.

This is the 3rd tool in my arsenal for finding which blocks of code to focus on and run the other tools against.

Changed 12 months ago by alex

  • milestone changed from 0.9 to 1.1

Changed 5 months ago by dylan

  • component changed from General to Dojox
  • milestone changed from 1.1 to 1.2

This probably makes sense in a dojox package as it does provide capabilities that you don't get with Firebug. Robert, what are your plans currently for this?

Changed 5 months ago by rcoup

  • owner changed from alex to rcoup
  • status changed from assigned to new

I have actually ported it to 1.x already so I'll package it a bit more nicely for dojox. Is there anything from the 0.4 dojo.profile stuff that should be ported as well?

Ideas on a package name? dojox.profile? dojox.devtools?

Changed 5 months ago by dylan

I think the other stuff was pretty redundant with what Firebug provides, but if you feel otherwise, feel free to port that as well.

I was always a bit annoyed with dojo.profile because it was confusing because of dojo's build system profiles.

How about dojox.performance? devtools seems fine to me as well.

Changed 5 months ago by guest

As a developer working on legacy "IE only" applications, Firebug is not an option. I would love to see some performance testing tools in dojo. I realize this is an edge case, but just know there are people out here that would love some of firebug's goodness in a cross browser way.

Changed 5 months ago by dylan

@guest: firebug lite which ships with dojo does help with some of this, but yes, we need to pick up where it leaves off.

Note: See TracTickets for help on using tickets.