Reputation: 381
I would love to be able to start and stop the CPU Profiler in the Chrome developer window by making a javascript call. Something like:
chrome.cpuprofiler.start();
//do expensive operation
chrome.cpuprofiler.stop();
Right now, the best I can do is:
Click "start profiling".
//do expensive operation
Click "stop profiling".
Is there even a shortcut key for this?
Upvotes: 38
Views: 6368
Reputation: 1546
You can!
An example:
if (window.console && window.console.profile) {
console.profile("label for profile");
// insert code to profile here,
// all function calls will be profiled
console.profileEnd();
}
It also works on Safari, and with Firebug in Firefox.
Note: You can't use profile to time code that does not make a function call: if your code above is simply a for loop then the profiler won't find anything to profile. Use console.time()
and console.timeEnd()
to benchmark pure loops or code that does not call a function.
Upvotes: 63