这是一个node自带性能分析工具 ,使用的方法就是,在启动的时候带上—prof 参数,如下:
$ node --prof inde.js
然后,使用ab工具开始压测,结束之后会生成isolate-[hash].log文件;
开始分析
$ node --prof-process [刚才生成的isolate log 文件] > profile.txt
输出为profile.txt:
Statistical profiling result from isolate-0x102884000-14025-v8.log, (296 ticks, 4 unaccounted, 0 excluded).
[Shared libraries]:
ticks total nonlib name
6 2.0% /usr/lib/system/libsystem_pthread.dylib
6 2.0% /usr/lib/system/libsystem_kernel.dylib
2 0.7% /usr/lib/system/libsystem_malloc.dylib
1 0.3% /usr/lib/system/libmacho.dylib
1 0.3% /usr/lib/system/libcorecrypto.dylib
[JavaScript]:
ticks total nonlib name
...
[Summary]:
ticks total nonlib name
0 0.0% 0.0% JavaScript
276 93.2% 98.6% C++
24 8.1% 8.6% GC
16 5.4% Shared libraries
4 1.4% Unaccounted
[C++ entry points]:
ticks cpp total name
142 63.1% 48.0% T __ZN2v88internal21Builtin_HandleApiCallEiPmPNS0_7IsolateE
82 36.4% 27.7% T __ZN2v88internal40Builtin_CallSitePrototypeGetPromiseIndexEiPmPNS0_7IsolateE
1 0.4% 0.3% T __ZN2v88internal36Builtin_CallSitePrototypeGetFileNameEiPmPNS0_7IsolateE
...
从Summary和各个entry points中,我们可以进一步分析程序中到底哪一块占用了较多的CPU时间。不过这个有点难看。