【问题标题】:node-inspector/v8-profiler not starting profiling or creating v8 log filenode-inspector/v8-profiler 未开始分析或创建 v8 日志文件
【发布时间】:2014-04-07 17:06:21
【问题描述】:

我有以下 nodejs 代码

var profiler = require("v8-profiler");

profiler.startProfiling("FooBar");

doSomethingAsync(function() {
  profiler.stopProfiling("FooBar");
});

我运行这个:

$ time node --prof --prof_lazy test/performance/performance-test.js

但是我没有得到 v8.log 文件。

我在安装与this issue with node-profiler 相关的 v8-profiler 软件包时确实遇到了一些问题。我使用 MacPorts,g++ 默认为 /opt/local/bin/g++(我也使用 MacPorts 提供的 nodejs 包)我设法通过使用 XCode 附带的 g++ 解决了 -arch 错误

$ CXX="xcrun g++" npm install v8-profiler

这可能是一个红鲱鱼,但值得一提的是,生成的 v8-profiler 二进制对象不适用于我的 nodejs 安装。

$ node --version
v0.10.22

$ npm --version
1.3.15

【问题讨论】:

    标签: node.js node-inspector


    【解决方案1】:

    如果要获取 v8.log 文件,需要添加 --log 选项。

    $ node --prof --prof_lazy --log test/performance/performance-test.js
    

    但是,当您使用 v8-profiler 时,日志文件不包含分析数据。我猜这是因为profiler.stopProfiling() 将分析数据返回给调用者。查看项目README中的示例:

    profiler.startProfiling([name])                   //begin cpu profiling
    var cpuProfile = profiler.stopProfiling([name])   //finish cpu profiling
    

    还有另一个模块允许您手动启动/停止分析器,同时将分析数据写入 v8.log:node-profiler。我没有设法用 Node v0.8 或 v0.10 编译它,您可能想在项目的问题跟踪器中填写问题。

    【讨论】:

    • 我在阅读 README 时显然脑子里放了一个屁 @miroslav-bajtos,因为我没有建立从 stopProfiling 返回分析数据的连接。如果我想检查数据,是否有将结果转储到文件或将其加载到节点检查器中的示例?我尝试使用 node-profiler,但它不喜欢 Node v0.10 的输出,我会提出一个问题。
    • 我一直在使用github.com/sidorares/node-tick 处理v8.log,因为node-profiler 提供的nprof 工具不处理v0.10 输出。
    • 我不知道。你可以试试 bugger,它允许你从 devtools GUI 启动/停止/检查分析器。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-08-16
    • 1970-01-01
    • 2017-06-09
    • 2013-03-11
    • 2014-02-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多