从Chrome中的Javascript开始和停止分析

Roc*_*amo 35 javascript google-chrome

我希望能够通过javascript调用在Chrome开发人员窗口中启动和停止CPU Profiler.就像是:

chrome.cpuprofiler.start();  
//do expensive operation  
chrome.cpuprofiler.stop();
Run Code Online (Sandbox Code Playgroud)

现在,我能做的最好的事情是:

Click "start profiling".  
//do expensive operation  
Click "stop profiling".  
Run Code Online (Sandbox Code Playgroud)

还有一个快捷键吗?

mwo*_*ech 59

您可以!

一个例子:

   if (window.console && window.console.profile) {
     console.profile("label for profile");
     // insert code to profile here,
     // all function calls will be profiled
     console.profileEnd();
   }
Run Code Online (Sandbox Code Playgroud)

它也适用于Safari,以及Firefox中的Firebug.

注意:您不能使用配置文件来计算不进行函数调用的时间代码:如果上面的代码只是for循环,那么分析器将找不到任何要分析的内容.使用console.time()console.timeEnd() 标记纯循环或不调用函数的代码.