Closed slutske22 closed 2 years ago
Thanks for your feedback, I'll take a look at this issue.
This is because chrome made changes to the serialization format of .cpuprofile
, and this is not a bug.
The old format (which v8-profiler-next
generate) is like:
{
head: { ...call frame tree },
startTime: xxxx,
endTime: xxxx,
samples: [],
timestamps: []
}
And the new format is like:
{
nodes: [ ... flattern call frame tree ],
startTime: xxxx,
endTime: xxxx,
samples: [],
timeDeltas: []
}
It seems that chrome devtools is compatible with both old and new formats, but the vscode is not. That is why .cpuprofile
generated by v8-profiler-next
looks empty in vscode.
I plan to add a config to decide which serialization format will be generated.
Install the latest v8-profiler-next
(>= v1.5.0), and set generateType
before profiling :
const v8Profiler = require('v8-profiler-next');
// default value is 0
// 0: default old format, 1: new format
v8Profiler.setGenerateType(1);
v8Profiler.startProfiling();
const profile = v8Profiler.stopProfiling(title);
If do not set generateType
, the previous .cpuprofile
format will be used by default.
It works! Amazing! Thank you so much for addressing this, and so fast!
Hi and thanks for this great tool!
I am able to use this library to generate .cpuprofile files programmatically. Here's some code on how I'm doing it
This code successfully creates a .cpuprofile file in the specified directory. If I open this file with chrome devtools, it reads as expected:
However, I'd like to work with vscode instead of relying on chrome. When I open this file with vscode, its empty:
I can create a .cpuprofile manually within the vscode debugger following instructions from Can I profile NodeJS Applications using Visual Studio Code?. That .cpuprofile file opens as expected in both chrome and vscode. Here's what it looks like in vscode (light theme)
What might be the problem with the .cpuprofile files generated by this library that they don't open properly in vscode?
Is this an issue with this library, or is there some inconsistencies between vscode and chrome as far as reading .cpuprofile files?
Versions I'm working with:
Mac OS Catalina, 10.15.6 Chrome Version 95.0.4638.69 (Official Build) (x86_64) VSCode 1.61.1 Node 14.16.0