Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
benchmark: Make flamegraphs a bit more useful
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Dec 29, 2012
1 parent ecdde7d commit 7550e31
Showing 1 changed file with 49 additions and 32 deletions.
81 changes: 49 additions & 32 deletions benchmark/http-flamegraph.sh
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -58,42 +58,59 @@ done


kill $nodepid kill $nodepid


echo 'Pluck off all the stacks that only happen once.' echo 'Turn the stacks into a svg'
stackvis dtrace flamegraph-svg < "$name".src > "$name".raw.svg


echo 'Prune tiny stacks out of the graph'
node -e ' node -e '
var infile = process.argv[1];
var outfile = process.argv[2];
var output = "";
var fs = require("fs"); var fs = require("fs");
var data = fs.readFileSync("'"$name"'.src", "utf8").split(/\n/); var input = fs.readFileSync(infile, "utf8");
var out = fs.createWriteStream("'"$name"'.out");
function write(l) { input = input.split("id=\"details\" > </text>");
out.write(l + "\n"); var head = input.shift() + "id=\"details\" > </text>";
} input = input.join("id=\"details\" > </text>");
write(data[0]);
write(data[1]); var tail = "</svg>";
write(data[2]); input = input.split("</svg>")[0];
var stack = []; var minyKept = Infinity;
var i = 4; var minyOverall = Infinity;
var saw2 = false var rects = input.trim().split(/\n/).filter(function(rect) {
for (; i < data.length && !saw2; i++) { var my = rect.match(/y="([0-9\.]+)"/);
if (data[i] === " 2") {
stack.forEach(function(line) { if (!my)
write(line); return false;
}); var y = +my[1];
write(data[i]); if (!y)
saw2 = true; return false;
} else if (data[i] === " 1") { minyOverall = Math.min(minyOverall, y);
stack = [];
} else { // pluck off everything that will be less than one pixel.
stack.push(data[i]); var mw = rect.match(/width="([0-9\.]+)"/)
if (mw) {
var width = +mw[1];
if (!(width >= 1))
return false;
} }
} minyKept = Math.min(minyKept, y);
return true;
for (; i < data.length; i++) });
write(data[i]);
' // move everything up to the top of the page.

var ydiff = minyKept - minyOverall;
echo 'Turn the stacks into a svg' rects = rects.map(function(rect) {
stackvis dtrace flamegraph-svg < "$name".out > "$name".svg var my = rect.match(/y="([0-9\.]+)"/);
var y = +my[1];
var newy = y - ydiff;
rect = rect.replace(/y="([0-9\.]+)"/, "y=\"" + newy + "\"");
return rect;
});
fs.writeFileSync(outfile, head + "\n" + rects.join("\n") + "\n" + tail);
' "$name".raw.svg "$name".svg


echo '' echo ''
echo 'done. Results in '"$name"'.svg' echo 'done. Results in '"$name"'.svg'

0 comments on commit 7550e31

Please sign in to comment.