The chromeProfileToCallgrind function converts a Chrome CPU profile object into a Callgrind-compatible text format. This is useful for visualizing Chrome performance data in tools like KCachegrind.
Parameters
profile (Object): The Chrome CPU profile object containing nodes, startTime, and endTime.outStream (Writable Stream): A Node.js writable stream where the Callgrind formatted text will be written.copy (Boolean, optional): If true (default), the function performs a deep clone of the profile object to avoid mutating the original input. If false, the original profile object is modified to include calculated timing data.
Output Format
The function writes a Callgrind file structure to the outStream, including:
events: ms hits header.- A
summary line with total time and total hit count. - Function entries (
fl, fn) followed by their self-time and hit count. - Call frame information (
cfi, cfn) for child calls.
const { chromeProfileToCallgrind } = require('./index');
const fs = require('fs');
const profile = JSON.parse(fs.readFileSync('chrome_profile.json', 'utf8'));
const outStream = fs.createWriteStream('output.callgrind');
// Convert the profile and write to the stream
chromeProfileToCallgrind(profile, outStream, true);