Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions packages/cli-hermes/src/profileHermes/downloadProfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ function execSyncWithLog(command: string) {
return execSync(command);
}

/**
* A wrapper that converts an object to JSON with 4 spaces for indentation.
*
* @param obj Any object that can be represented as JSON
* @returns A JSON string
*/
function jsonStringify(obj: any) {
return JSON.stringify(obj, undefined, 4);
}

/**
* Pull and convert a Hermes tracing profile to Chrome tracing profile
* @param ctx
Expand Down Expand Up @@ -123,11 +133,12 @@ export async function downloadProfile(
file,
'.cpuprofile',
)}-converted.json`;
fs.writeFileSync(
transformedFilePath,
JSON.stringify(events, undefined, 4),
'utf-8',
);

// Convert to JSON in chunks because JSON.stringify() will fail for large
// arrays with the error "RangeError: Invalid string length"
const out = events.map(jsonStringify).join(',');

fs.writeFileSync(transformedFilePath, '[' + out + ']', 'utf-8');
logger.success(
`Successfully converted to Chrome tracing format and pulled the file to ${transformedFilePath}`,
);
Expand Down