简体   繁体   English

Google Chrome开发人员工具 - 分析结果文件格式

[英]Google Chrome developer tools - Profiling results file format

I'm wondering is there any (un)official spec to .cpuprofile file format, which is generated when JavaScript profiling is used in Chromium-based browser's developer tools. 我想知道是否有任何(非)官方规范的.cpuprofile文件格式,这是在基于Chromium的浏览器开发人员工具中使用JavaScript分析时生成的。

It is plain-text JSON so it is easy to get call tree data but I don't understand how to get timing information for each function. 它是纯文本JSON,因此很容易获得调用树数据,但我不明白如何获取每个函数的时序信息。

Also I'm interested in hit count for every function. 我也对每个功能的命中数感兴趣。

According to the documentation provided by @artm , the output can be analyzed with kcachegrind . 根据@artm提供文档 ,可以使用kcachegrind分析输出。 What you need to do in order to load a Chrome .cpuprofile file into this is to convert it to callgrind format. 要将Chrome .cpuprofile文件加载到此文件中,您需要做的是将其转换为callgrind格式。

You don't mention your dev environment, so I can't say the best what the easiest way for you to go about this will be. 你没有提到你的开发环境,所以我不能说最好的方法是你最简单的方法。

The documentation mentions Google's perf tools and kcachegrind for this. 该文档提到了Google的perf工具和kcachegrind。 These tools need to be built manually and I don't have a convenient environment for doing that. 这些工具需要手动构建,我没有方便的环境。

Here is how I went about it on a Windows 8.1 machine with Node installed. 以下是我在安装了Node的Windows 8.1计算机上的使用方法。

  1. Install chrome2calltree for Node. 为Node安装chrome2calltree This command utility will convert your .cpuprofile to a callgrind format. 此命令实用程序将您的.cpuprofile转换为callgrind格式。

  2. Install QCacheGrind . 安装QCacheGrind This is a Windows pre-built port of kcachegrind that will let you visualize your callgrind formatted file. 这是一个Windows预构建的kcachegrind端口,可以让您可视化您的callgrind格式化文件。

  3. Convert your .cpuprofile: chrome2calltree -i test.cpuprofile -o callgrind.profile 转换你的.cpuprofile: chrome2calltree -i test.cpuprofile -o callgrind.profile

  4. Open your callgrind.profile with QCacheGrind. 使用QCacheGrind打开callgrind.profile。

This might not be a direct answer to your question , but this is really awesome. 这可能不是直接回答你的问题,但是是真的真棒。

usage is very simple: 用法很简单:

fireunit.profile(function(){
  document.getElementsByClassName("foo");
});

You'll get the following JavaScript object returned from fireunit.getProfile(): 您将从fireunit.getProfile()返回以下JavaScript对象:

{
  "time": 8.443,
  "calls": 611,
  "data":[
  {
    "name":"makeArray()",
    "calls":1,
    "percent":23.58,
    "ownTime":1.991,
    "time":1.991,
    "avgTime":1.991,
    "minTime":1.991,
    "maxTime":1.991,
    "fileName":"jquery.js (line 2059)"
  },
  // etc.
]}

Maybe it is notable but the JSON format of cpuprofile probably has changed recently, so it may not be a stable format. 也许这是值得注意的,但cpuprofile的JSON格式最近可能已经改变,所以它可能不是一个稳定的格式。 In Chromium 44 for example (older version from their build archives) it looked like this 例如,在Chromium 44中(来自其构建档案的旧版本),它看起来像这样

jq keys < chromium_44.cpuprofile
[
  "endTime",
  "head",
  "samples",
  "startTime",
  "timestamps"
]

In latest chrome 55 it is 最新的镀铬55是

jq keys < chrome_55.cpuprofile
[
  "endTime",
  "nodes",
  "samples",
  "startTime",
  "timeDeltas"
]

Just something to be wary of. 只是需要警惕的事情。 I have not seen much if any documentation on the format though 虽然我没有看到任何关于格式的文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM