startProfiling([name], [recsamples]) - start CPU profiling. name is optional argument, by default profile name will be constructed from his uid. recsamples is true by default.
stopProfiling([name]) - returns new CPU Profile instance. There is no strictly described behavior for usage without name argument.
setSamplingInterval([num]) - Changes default CPU profiler sampling interval to the specified number of microseconds. Default interval is 1000us. This method must be called when there are no profiles being recorded. If called without arguments it resets interval to default.
deleteAllProfiles() - works as described in name.
collectSample() - causes all active profiles to synchronously record the current callstack. Does not add a new top level sample, only adds more detail to the call graph.
Snapshot.getHeader() - provides short information about snapshot.
Snapshot.compare(snapshot) - creates HEAP diff for two snapshots.
Snapshot.delete() - removes snapshot from memory.
Snapshot.export([callback]) - provides simple export API for snapshot. callback(error, data) receives serialized snapshot as second argument. (Serialization is not equal to JSON.stringify result).
If callback will not be passed, export returns transform stream.
var fs = require('fs');var profiler = require('v8-profiler-node8');var snapshot1 = profiler.takeSnapshot();var snapshot2 = profiler.takeSnapshot();console.log(snapshot1.getHeader(), snapshot2.getHeader());console.log(snapshot1.compare(snapshot2));// Export snapshot to file filesnapshot1.export(function(error, result) { fs.writeFileSync('snapshot1.json', result); snapshot1.delete();});// Export snapshot to file stream
CPU Profile API
Profile.getHeader() - provides short information about profile.
Profile.delete() - removes profile from memory.
Profile.export([callback]) - provides simple export API for profile. callback(error, data) receives serialized profile as second argument. (Serialization is equal to JSON.stringify result).