我正在使用Node.js 8.3。我使用node --prof server.js
来分析我的应用。我得到一些名称为 xxxx -v8.log。
我尝试使用https://www.npmjs.com/package/node-tick-processor和https://github.com/sidorares/node-tick来分析文件。我有兴趣看到CPU配置文件。
但输出是这样的,这不是很有帮助:
[Bottom up (heavy) profile]:
Note: percentage shows a share of a particular caller in the total
amount of its parent calls.
Callers occupying less than 2.0% are not shown.
ticks parent name
65591 59.5% /usr/lib/system/libsystem_kernel.dylib
42621 65.0% /usr/local/bin/node
16632 15.1% /usr/local/bin/node
5544 33.3% /usr/local/bin/node
5888 5.3% /usr/lib/system/libsystem_c.dylib
5875 99.8% /usr/local/bin/node
2702 2.4% /usr/lib/system/libsystem_pthread.dylib
2284 84.5% /usr/local/bin/node
[Top down (heavy) profile]:
Note: callees occupying less than 0.1% are not shown.
inclusive self name
ticks total ticks total
68106 61.7% 11088 10.1% /usr/local/bin/node
42617 38.6% 42617 38.6% /usr/lib/system/libsystem_kernel.dylib
5875 5.3% 5875 5.3% /usr/lib/system/libsystem_c.dylib
5548 5.0% 5538 5.0% /usr/local/bin/node
2284 2.1% 2284 2.1% /usr/lib/system/libsystem_pthread.dylib
337 0.3% 337 0.3% /usr/lib/system/libsystem_platform.dylib
303 0.3% 303 0.3% /usr/lib/system/libsystem_malloc.dylib
22970 20.8% 22970 20.8% /usr/lib/system/libsystem_kernel.dylib
418 0.4% 418 0.4% /usr/lib/system/libsystem_pthread.dylib
还有其他工具可以分析输出文件吗?我希望看到一些显示瓶颈功能或者至少为我找到行号的东西。我尝试了v8-profiler
,并且需要在Chrome开发工具上加载输出文件。但格式看起来不同。我不确定我是否仍然可以分析-v8.log
文件。
答案 0 :(得分:0)
您的工具使用绝对没问题。这里的问题是来自named
JS函数的CPU消耗的贡献太小而不能在繁重的配置文件中看到。请注意您的配置文件输出中的警告(不显示占用率低于0.1%的被调用者。)
考虑我的代码:
var x = 10;
function foo() {
while (true) {
x++;
}
}
foo();
这是教授的输出。正如您所看到的,脚本,函数及其行#出现,是主要的CPU用户。
[Unknown]:
ticks total nonlib name
13 0.3%
[Shared libraries]:
ticks total nonlib name
57 1.3% 0.0% /usr/local/bin/node
6 0.1% 0.0% /usr/lib/system/libsystem_kernel.dylib
2 0.0% 0.0% /usr/lib/system/libsystem_platform.dylib
1 0.0% 0.0% /usr/lib/system/libsystem_pthread.dylib
1 0.0% 0.0% /usr/lib/system/libsystem_c.dylib
[JavaScript]:
ticks total nonlib name
4177 98.1% 99.7% LazyCompile: *foo /Users/gireesh/a.js:2:13
1 0.0% 0.0% Stub: BinaryOpWithAllocationSiteStub
[C++]:
ticks total nonlib name
[GC]:
ticks total nonlib name
2 0.0%
[Bottom up (heavy) profile]:
Note: percentage shows a share of a particular caller in the total
amount of its parent calls.
Callers occupying less than 2.0% are not shown.
ticks parent name
4177 98.1% LazyCompile: *foo /Users/gireesh/a.js:2:13
4177 100.0% LazyCompile: *foo /Users/gireesh/a.js:2:13
4177 100.0% Function: ~<anonymous> /Users/gireesh/a.js:1:11
4177 100.0% Function: ~Module._compile module.js:526:37
4177 100.0% Function: ~Module._extensions..js module.js:578:37
4177 100.0% Function: ~Module.load module.js:494:33
希望这有帮助。