From a0d9045e552301e40efdef3cd0fcb88cd91bc960 Mon Sep 17 00:00:00 2001 From: Jared Pochtar Date: Fri, 26 Jun 2015 16:34:07 -0700 Subject: [PATCH] document that profiles are jsonable to `.cpuprofile` files --- readme.md | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/readme.md b/readme.md index bc559a2..55152c4 100644 --- a/readme.md +++ b/readme.md @@ -2,7 +2,7 @@ [![Build status](https://ci.appveyor.com/api/projects/status/hhgloy5smkl5i8fd/branch/master?svg=true)](https://ci.appveyor.com/project/3y3/v8-profiler/branch/master) [![npm version](https://badge.fury.io/js/v8-profiler.svg)](http://badge.fury.io/js/v8-profiler) -v8-profiler provides [node](http://github.com/ry/node) bindings for the v8 +v8-profiler provides [node](http://github.com/ry/node) bindings for the v8 profiler and integration with [node-inspector](http://github.com/dannycoates/node-inspector) ## Installation @@ -18,9 +18,16 @@ profiler and integration with [node-inspector](http://github.com/dannycoates/nod var snapshot = profiler.takeSnapshot([name]) //takes a heap snapshot profiler.startProfiling([name]) //begin cpu profiling + // ... do your program's work ... var cpuProfile = profiler.stopProfiling([name]) //finish cpu profiling ## node-inspector -Cpu profiles can be viewed and heap snapshots may be taken and viewed from the -profiles panel. +CPU profiles can be viewed and heap snapshots may be taken and viewed from the +profiles panel. The profiles returned are JSONable objects in the `.cpuprofile` +format that node-inspector's `Profiles` panel loads. + + var serialized = JSON.stringify(cpuProfile, null, 2); + require('fs').writeFileSync('myprogram.cpuprofile', serialized, 'utf8'); + +The `myprogram.cpuprofile` file written can then be loaded into the profiles panel and viewed as a flamechart.