2011-03-17 25 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()來測試純循環或不調用函數的代碼。