lib/flamegraph/flamegraph.html in flamegraph-0.0.1 vs lib/flamegraph/flamegraph.html in flamegraph-0.0.2

- old
+ new

@@ -1,10 +1,10 @@ <!DOCTYPE html> <html> <head> -<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script> -<script src="http://cdnjs.cloudflare.com/ajax/libs/d3/3.0.8/d3.min.js"></script> +<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> +<script src="//cdnjs.cloudflare.com/ajax/libs/d3/3.0.8/d3.min.js"></script> <meta charset=utf-8 /> <title>Flame Graph of Page</title> <style> .info {height: 40px;} .legend div { @@ -165,19 +165,25 @@ for (var i = 0; i < this.length; i++) o[this[i]] = 1 for (var e in o) a.push(e) return a } -var samplePercent = function(samples){ - return "(" + samples + +var samplePercent = function(samples, exclusive){ + var info = " (" + samples + " sample" + (samples == 1 ? "" : "s") + " - " + - ((samples / maxX) * 100).toFixed(2) + "%)"; + ((samples / maxX) * 100).toFixed(2) + "%) "; + if (exclusive) { + info += " (" + exclusive + + " exclusive - " + + ((exclusive / maxX) * 100).toFixed(2) + "%) "; + } + return info; } var mouseover = function(d) { var i = info[d.frame]; - $('.info').text( d.frame + " " + samplePercent(i.samples.length)); + $('.info').text( d.frame + " " + samplePercent(i.samples.length, d.topFrame ? d.topFrame.exclusiveCount : 0)); d3.selectAll(i.nodes) .attr('opacity',0.5); }; var mouseout = function(d) { @@ -209,10 +215,12 @@ return (c); } // assign some colors, analyze samples per gem var gemStats = {} +var topFrames = {} +var lastFrame = {frame: 'd52e04d-df28-41ed-a215-b6ec840a8ea5', x: -1} $.each(data, function(){ var gem = guessGem(this.frame); var stat = gemStats[gem]; @@ -223,12 +231,30 @@ stat.frames.push(this.frame); for(var j=0; j < this.width; j++){ stat.samples.push(this.x + j); } + // This assumes the traversal is in order + if (lastFrame.x != this.x) { + var topFrame = topFrames[lastFrame.frame] + if (!topFrame) { + topFrames[lastFrame.frame] = topFrame = {exclusiveCount: 0} + } + topFrame.exclusiveCount += 1; + lastFrame.topFrame = topFrame; + } + lastFrame = this; + }); +var topFrame = topFrames[lastFrame.frame] +if (!topFrame) { + topFrames[lastFrame.frame] = topFrame = {exclusiveCount: 0} +} +topFrame.exclusiveCount += 1; +lastFrame.topFrame = topFrame; + var totalGems = 0; $.each(gemStats, function(){totalGems++;}); var currentIndex = 0; @@ -319,7 +345,5 @@ </script> </body> </html> - -