【问题标题】:How to access chrome profiling programmatically如何以编程方式访问 chrome 分析
【发布时间】:2012-08-05 09:56:02
【问题描述】:

寻找一些 chrome API(用于 chrome 扩展)让我以编程方式执行以下操作:- - 开始分析 - 结束分析 - 获取页面上所有 JS 所用时间列表

我可以在 Firefox 中达到同样的效果:

jsd = DebuggerService.getService(jsdIDebuggerService)
// start the profiling as
jsd.flags |= COLLECT_PROFILE_DATA;

// stop the profilinf as
jsd.flags &= ~COLLECT_PROFILE_DATA;

// get the details of how much time each JS function took
jsd.enumerateScripts({enumerateScript: function(script)
{
// script object has timings detail
}

即使是一些可以让我从开发人员工具栏中导出分析信息的 API 也会有所帮助

【问题讨论】:

    标签: javascript google-chrome google-chrome-extension profiling google-chrome-devtools


    【解决方案1】:

    您可以使用以下代码以编程方式在 google chrome 中分析脚本

    console.profile("MyProfile");
    // Enter name of script here
    console.profileEnd();
    

    “MyProfile”是要创建的配置文件的名称。

    来源:

    http://blog.codestars.eu/2011/profiling-with-webkit/

    您可以通过使用console.time()console.timeEnd()的组合来获得执行函数/代码sn-p的时间

    【讨论】:

    • 我可以通过这种方式启动/停止分析器,但是如何以编程方式获取分析数据,即哪个 JS 运行多长时间。
    • 您可以通过使用console.time()console.timeEnd()的组合来获得函数/代码sn-p执行的时间,相应地更新答案
    • 我认为他希望他的扩展能够分析页面上的 js 函数,而不是他自己的函数。
    • 在 console.profileEnd();您可以通过转到开发人员工具中的配置文件选项卡或使用命令 console.profiles() 以编程方式获取数据;
    • console.profiles() 似乎并不实际存在?
    猜你喜欢
    • 1970-01-01
    • 2015-09-03
    • 2020-05-05
    • 1970-01-01
    • 1970-01-01
    • 2012-01-26
    • 2016-09-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多