maaash.jp

what I create

profiling node.js

# build d8
cd ~/.nave/src/0.8.18/deps/v8
scons prof=on d8

# d8, linux-tick-processor にパスを通す
export PATH=~/.nave/src/0.8.18/deps/v8:~/.nave/src/0.8.18/deps/v8/tools:$PATH

# プロファイリングを取りたいところを限定するモジュール
# https://github.com/bnoordhuis/node-profiler
npm install profiler

# プロファイリング対象をいろいろオプション付きで実行
node –prof –prof_lazy –log –log_snapshot_positions 3.js

# すると v8.log ができる
# それを linux-tick-processor がレポートにしてくれる
linux-tick-processor > 3.js.log

# 元のコードはこんな
cat 3.js

1
2
3
4
5
6
7
8
9
10
11
12
var len = 10000
,   i = 0
, profiler = require('profiler')
;

profiler.resume();

while (++i <= len) {
    Date.now();
}

profiler.pause();

# プロファイリング結果はこんな
cat 3.js.log

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
Statistical profiling result from v8.log, (12 ticks, 12 unaccounted, 0 excluded).

 [Unknown]:
   ticks  total  nonlib   name
     12  100.0%

 [Shared libraries]:
   ticks  total  nonlib   name

 [JavaScript]:
   ticks  total  nonlib   name
     11   91.7%   91.7%  LazyCompile: *now native date.js:314
      1    8.3%    8.3%  LazyCompile: ~now native date.js:314

 [C++]:
   ticks  total  nonlib   name

 [GC]:
   ticks  total  nonlib   name
      0    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
     11   91.7%  LazyCompile: *now native date.js:314
     11  100.0%    Script: ~/home/*snip*/3.js
     11  100.0%      LazyCompile: ~Module._compile module.js:372
     11  100.0%        LazyCompile: ~Module._extensions..js module.js:465
     11  100.0%          LazyCompile: ~Module.load module.js:346
     11  100.0%            LazyCompile: Module._load module.js:275

      1    8.3%  LazyCompile: ~now native date.js:314
      1  100.0%    Script: ~/home/*snip*/3.js
      1  100.0%      LazyCompile: ~Module._compile module.js:372
      1  100.0%        LazyCompile: ~Module._extensions..js module.js:465
      1  100.0%          LazyCompile: ~Module.load module.js:346
      1  100.0%            LazyCompile: Module._load module.js:275

see: https://code.google.com/p/v8/wiki/V8Profiler

-–追記
以下も便利

https://github.com/c4milo/node-webkit-agent

Comments