2011-03-17 26 views
33

我希望能够通过发出javascript调用来启动和停止Chrome浏览器开发人员窗口中的CPU Profiler。喜欢的东西:启动和停止从Chrome中的Javascript分析

chrome.cpuprofiler.start(); 
//do expensive operation 
chrome.cpuprofiler.stop(); 

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

Click "start profiling". 
//do expensive operation 
Click "stop profiling". 

有即使是在这个快捷键?

回答

55

你可以!

一个例子:

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

它也适用于Safari浏览器,并与Firefox中的Firebug。

注意:您不能使用配置文件时间代码,不进行函数调用:如果您的代码只是一个for循环,然后配置文件将找不到任何配置文件。使用console.time()console.timeEnd()来测试纯循环或不调用函数的代码。