【问题标题】:Start and Stop Profiling from Javascript in Chrome在 Chrome 中从 Javascript 开始和停止分析
【发布时间】:2013-11-11 12:46:32
【问题描述】:

我希望能够通过调用 javascript 来在 Chrome 开发者窗口中启动和停止 CPU Profiler。比如:

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

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

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

这个有快捷键吗?

【问题讨论】:

    标签: javascript google-chrome


    【解决方案1】:

    你可以!

    一个例子:

       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。

    注意:您不能使用 profile 来对不进行函数调用的代码进行计时:如果上面的代码只是一个 for 循环,那么 profiler 将找不到任何要分析的内容。使用 console.time()console.timeEnd() 对不调用函数的纯循环或代码进行基准测试。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-12-29
      • 1970-01-01
      • 1970-01-01
      • 2023-03-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多