Last active
March 14, 2023 17:06
-
-
Save hurryabit/c5748dae6115b0459935de9d796d7f65 to your computer and use it in GitHub Desktop.
Merge multiple profiles in Speedscope's JSON format into one file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 }, | |
})); |
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
Hi Martin,
I'm currently seeing an out-of-memory crash.
The size of the source json is 10GB.
Here is the dump: