Commit 0956e587 authored by leszeks's avatar leszeks Committed by Commit bot

[tools] Manually write JSON in profile.js to avoid huge strings

In the tick processor, in cases where there are a lot of ticks (e.g.
long running programs), JSON.stringify could throw a range exception
because the created string is too large.

Instead of creating the entire JSON string in memory, we now write the
top-level parts of the JSON manually, writing out the ticks individually
instead of all together.

Review-Url: https://codereview.chromium.org/2754683002
Cr-Commit-Position: refs/heads/master@{#43973}
parent c0c55250
......@@ -969,10 +969,20 @@ JsonProfile.prototype.recordTick = function(time_ns, vmState, stack) {
};
JsonProfile.prototype.writeJson = function() {
var toplevel = {
code : this.codeEntries_,
functions : this.functionEntries_,
ticks : this.ticks_
};
write(JSON.stringify(toplevel));
// Write out the JSON in a partially manual way to avoid creating too-large
// strings in one JSON.stringify call when there are a lot of ticks.
write('{\n')
write(' "code": ' + JSON.stringify(this.codeEntries_) + ',\n');
write(' "functions": ' + JSON.stringify(this.functionEntries_) + ',\n');
write(' "ticks": [\n');
for (var i = 0; i < this.ticks_.length; i++) {
write(' ' + JSON.stringify(this.ticks_[i]));
if (i < this.ticks_.length - 1) {
write(',\n');
} else {
write('\n');
}
}
write(' ]\n');
write('}\n');
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment