Skip to content

Instantly share code, notes, and snippets.

@hurryabit
Last active March 14, 2023 17:06
Show Gist options
  • Save hurryabit/c5748dae6115b0459935de9d796d7f65 to your computer and use it in GitHub Desktop.
Save hurryabit/c5748dae6115b0459935de9d796d7f65 to your computer and use it in GitHub Desktop.
Merge multiple profiles in Speedscope's JSON format into one file
#!/usr/bin/env node
"use strict";
const fs = require("fs");
const SPEEDSCOPE_JSON_SCHEMA = "https://www.speedscope.app/file-format-schema.json";
const [node, prog, ...options] = process.argv;
if (options[options.length - 2] !== "-o") {
console.error(`Usage: ${node} ${prog} <INPUT-FILES> -o <OUTPUT-FILE>`);
process.exit(1);
}
const outputFile = options.pop();
options.pop();
const inputFiles = options;
const output = {
frameIndices: {},
frames: [],
profiles: [],
};
for (const inputFile of inputFiles) {
console.log(`Processing input from ${inputFile}...`);
const json = JSON.parse(fs.readFileSync(inputFile));
const input = {
frames: json.shared.frames,
profiles: json.profiles,
};
for (const profile of input.profiles) {
for (const event of profile.events) {
const frame = input.frames[event.frame].name;
let frameIndex = output.frameIndices[frame];
if (frameIndex === undefined) {
frameIndex = output.frames.length;
output.frames.push({ name: frame });
output.frameIndices[frame] = frameIndex;
}
event.frame = frameIndex;
}
output.profiles.push(profile);
}
}
console.log(`Writing output to ${outputFile}...`);
fs.writeFileSync(outputFile, JSON.stringify({
"$schema": SPEEDSCOPE_JSON_SCHEMA,
"activeProfileIndex": 0,
"exporter": "merge-speedscope-json",
"profiles": output.profiles,
"shared": { "frames": output.frames },
}));
@weining-da
Copy link

Here is how to reproduce this crash.
You'd need to pull from master in solution-spider repo to get the latest version of the makefiles.

make run-ft daml_profile_dir=/tmp/prof ftags=@SPD-8658 (/tmp/prof must exist)

It should emit around 3.2Gb json.

Then try to combine all the files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment