Node.js –prof – Profiling Node.JS Applications

This article will help you to find out more information about Node.js –prof, since the following Node.js tutorial sheds light on profiling Node.js applications.
 
                
			
			Calling something like “ulimit -n 8192” in your Node.js application runs a shell script before starting the service. Thus, running with Node.js –prof to generates the v8.log
| 1 | node --prof --prof_lazy app.js | 
Note that there are tools in /node/deps/v8/ that in combination with this command
| 1 | tools/linux-tick-processor path-of-v8.log | 
lead to the following results:
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | [Shared libraries]:   ticks  total  nonlib   name      3    0.0%    0.0%  .../libc-2.13.so [JavaScript]:   ticks  total  nonlib   name      1    0.0%    0.0%  Stub: InstanceofStub [C++]:   ticks  total  nonlib   name     1    0.0%    0.0%  __write     ... [GC]:   ticks  total  nonlib   name     15    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   ... | 
For a trace log use this one:
| 1 | strace -o trace.log -cf node app.js | 
If you need time, utilize the following command:
| 1 | time node app.js | 
Other Useful Tools
| 1 2 | dtrace -o stacks.out -n 'profile-97/execname == "node" && arg1/{  @[jstack(100, 8000)] = count(); } tick-60s { exit(0); }' | 
| 1 2 3 4 5 6 7 8 9 | var profiler = require('v8-profiler'); profiler.startProfiling('startup'); slowStartupFoo(); profiler.stopProfiling('startup'); profiler.takeSnapshot('beforeLeak'); leakyFoo(); profiler.takeSnapshot('afterLeak'); | 
| 1 | node --debug app.js | 
| 1 2 3 4 5 6 7 8 9 | var profiler = require('profiler'); // // <here be code you don't want to profile> // profiler.resume(); // // <performance critical code here> // profiler.pause(); | 
| 1 2 3 4 5 | var nodetime = require('nodetime'); nodetime.on('session', function(id) {  // do something with session id here }); nodetime.profile(); | 
| 1 | valgrind --tool=callgrind node app.js | 
- – a node.js-runnable v8.log processor
| 1 2 | $ node --prof yourprogram $ node-tick-processor | 
- – Stacktrace visualization tools
Profile a program:
| 1 | # dtrace -n 'profile-97/pid == $YOURPID/{ @[jstack(80, 8192)] = count(); }' -c "sleep 30" > dtrace.out | 
translate the DTrace output into a flame graph:
| 1 | # stackvis < dtrace.out > flamegraph.htm | 
 
                
								
			

 
            






