How do activate the V8 profiler?

105 views
Skip to first unread message

Danny Dorfman

unread,
Mar 18, 2015, 5:09:02 AM3/18/15
to v8-u...@googlegroups.com
Hello there,

I need to activate the V8 profiler programmatically, from my C++ application that runs V8.
I tried reading through this Wiki: https://code.google.com/p/v8-wiki/wiki/V8Profiler
but I'm afraid that it is not up-to-date. I could find no functions named V8::ResumeProfiler() or V8::PauseProfiler().
Is there any better source of information, or a working sample?

Regards,
Danny

Ben Noordhuis

unread,
Mar 18, 2015, 7:52:42 AM3/18/15
to v8-u...@googlegroups.com
In recent versions of V8, the CPU profiler is a property of the
isolate, i.e. isolate->GetCpuProfiler()->StartProfiling(title) and
ditto for the StopProfiling() method. You need to include
v8-profiler.h to get the definition of the CpuProfiler, CpuProfile and
CpuProfileNode classes.

Danny Dorfman

unread,
Mar 18, 2015, 7:58:57 AM3/18/15
to v8-u...@googlegroups.com
Thanks Ben! That's exactly what I was looking for.

Danny Dorfman

unread,
Mar 18, 2015, 11:43:20 AM3/18/15
to v8-u...@googlegroups.com
I have one more question, please: Once the profiler is done, where are the results collected?
How do I get them into an external file for analysis?

Ben Noordhuis

unread,
Mar 18, 2015, 12:22:46 PM3/18/15
to v8-u...@googlegroups.com
On Wed, Mar 18, 2015 at 4:43 PM, Danny Dorfman <wilder...@gmail.com> wrote:
> I have one more question, please: Once the profiler is done, where are the
> results collected?
> How do I get them into an external file for analysis?

You can walk the CpuProfile nodes and write them to disk in
.cpuprofile format, a JSON format that you can import in Chrome
DevTools. It's not documented but it's easy to figure out by looking
at .cpuprofile files written by DevTools.

I have to warn you though that V8 and Chrome are closely coupled with
respect to the file format: it changes frequently and it's not really
designed to be backward- or forward-compatible unless you go through
great contortions.

Our (i.e. StrongLoop's) strong-agent product can write a .cpuprofile
for node.js v0.10 that recent Chromes can understand; I'd link you to
it but it's not open source.
Reply all
Reply to author
Forward
0 new messages