1

我有以下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 文件。

我在使用 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
4

1 回答 1

1

--log如果要获取 v8.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 编译它,您可能想在项目的问题跟踪器中填写问题。

于 2014-04-07T09:06:21.397 回答