1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276
|
<html>
<head>
<meta charset="UTF-8">
<style type="text/css">
div.histo {
visibility: hidden
}
</style>
<!--Load the AJAX API-->
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
(function() {
var out$ = typeof exports != 'undefined' && exports || this;
var doctype = '<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">';
function inlineImages(callback) {
var images = document.querySelectorAll('svg image');
var left = images.length;
if (left == 0) {
callback();
}
for (var i = 0; i < images.length; i++) {
(function(image) {
if (image.getAttribute('xlink:href')) {
var href = image.getAttribute('xlink:href').value;
if (/^http/.test(href) && !(new RegExp('^' + window.location.host).test(href))) {
throw new Error("Cannot render embedded images linking to external hosts.");
}
}
var canvas = document.createElement('canvas');
var ctx = canvas.getContext('2d');
var img = new Image();
img.src = image.getAttribute('xlink:href');
img.onload = function() {
canvas.width = img.width;
canvas.height = img.height;
ctx.drawImage(img, 0, 0);
image.setAttribute('xlink:href', canvas.toDataURL('image/png'));
left--;
if (left == 0) {
callback();
}
}
})(images[i]);
}
}
function styles(dom) {
var css = "";
var sheets = document.styleSheets;
for (var i = 0; i < sheets.length; i++) {
var rules = sheets[i].cssRules;
if (rules != null) {
for (var j = 0; j < rules.length; j++) {
var rule = rules[j];
if (typeof(rule.style) != "undefined") {
css += rule.selectorText + " { " + rule.style.cssText + " }\n";
}
}
}
}
var s = document.createElement('style');
s.setAttribute('type', 'text/css');
s.innerHTML = "<![CDATA[\n" + css + "\n]]>";
var defs = document.createElement('defs');
defs.appendChild(s);
return defs;
}
out$.svgAsDataUri = function(el, scaleFactor, cb) {
scaleFactor = scaleFactor || 1;
inlineImages(function() {
var outer = document.createElement("div");
var clone = el.cloneNode(true);
var width = parseInt(
clone.getAttribute('width')
|| clone.style.width
|| out$.getComputedStyle(el).getPropertyValue('width')
);
var height = parseInt(
clone.getAttribute('height')
|| clone.style.height
|| out$.getComputedStyle(el).getPropertyValue('height')
);
var xmlns = "http://www.w3.org/2000/xmlns/";
clone.setAttribute("version", "1.1");
clone.setAttributeNS(xmlns, "xmlns", "http://www.w3.org/2000/svg");
clone.setAttributeNS(xmlns, "xmlns:xlink", "http://www.w3.org/1999/xlink");
clone.setAttribute("width", width * scaleFactor);
clone.setAttribute("height", height * scaleFactor);
clone.setAttribute("viewBox", "0 0 " + width + " " + height);
outer.appendChild(clone);
clone.insertBefore(styles(clone), clone.firstChild);
var svg = doctype + outer.innerHTML;
var uri = 'data:image/svg+xml;base64,' + window.btoa(unescape(encodeURIComponent(svg)));
if (cb) {
cb(uri);
}
});
}
out$.saveSvgAsPng = function(el, name, scaleFactor) {
out$.svgAsDataUri(el, scaleFactor, function(uri) {
var image = new Image();
image.src = uri;
image.onload = function() {
var canvas = document.createElement('canvas');
canvas.width = image.width;
canvas.height = image.height;
var context = canvas.getContext('2d');
context.drawImage(image, 0, 0);
var a = document.createElement('a');
a.download = name;
a.href = canvas.toDataURL('image/png');
document.body.appendChild(a);
a.click();
}
});
}
})();
</script>
<script type="text/javascript">
if (window.File && window.FileReader && window.FileList && window.Blob) {
// Great success! All the File APIs are supported.
} else {
alert('The File APIs are not fully supported in this browser.');
}
// Load the Visualization API and the piechart package.
google.load('visualization', '1.0', {'packages':['corechart']});
// Global data series
var dataSeries_g = [];
function drawChart() {
if (dataSeries_g.length == 0) {
return;
}
var data = google.visualization.arrayToDataTable(dataSeries_g);
var ticks =
[{v:1,f:'0%'},
{v:10,f:'90%'},
{v:100,f:'99%'},
{v:1000,f:'99.9%'},
{v:10000,f:'99.99%'},
{v:100000,f:'99.999%'},
{v:1000000,f:'99.9999%'}];
var options = {
title: 'Histogram',
width: 800,
height: 480,
hAxis: {title: 'Percentile', minValue: 0, logScale: true, ticks:ticks },
vAxis: {title: 'Latency (µs)', minValue: 0 },
legend: {position: 'bottom'}
};
var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
// add tooptips with correct percentile text to data:
var columns = [0];
for (var i = 1; i < data.getNumberOfColumns(); i++) {
columns.push(i);
columns.push({
type: 'string',
properties: {
role: 'tooltip'
},
calc: (function (j) {
return function (dt, row) {
var percentile = 100.0 - (100.0/dt.getValue(row, 0));
return dt.getColumnLabel(j) + ': ' +
percentile.toPrecision(6) +
'\%\'ile = ' + dt.getValue(row, j) + ' usec'
}
})(i)
});
}
var view = new google.visualization.DataView(data);
view.setColumns(columns);
chart.draw(view, options);
}
</script>
<script type="text/javascript">
function appendDataSeries(histo, name, dataSeries) {
var series;
var seriesCount;
if (dataSeries.length == 0) {
series = [ ['X', name] ];
seriesCount = 1;
} else {
series = dataSeries;
series[0].push(name);
seriesCount = series[0].length - 1;
}
var lines = histo.split("\n");
var seriesIndex = 1;
for (var i = 0; i < lines.length; i++) {
var line = lines[i].trim();
var values = line.trim().split(/[ ]+/);
if (line[0] != '#' && values.length == 4) {
var y = parseFloat(values[0]);
var x = parseFloat(values[3]);
if (!isNaN(x) && !isNaN(y)) {
if (seriesIndex >= series.length) {
series.push([x]);
}
while (series[seriesIndex].length < seriesCount) {
series[seriesIndex].push(null);
}
series[seriesIndex].push(y);
seriesIndex++;
}
}
}
while (seriesIndex < series.length) {
series[seriesIndex].push(null);
seriesIndex++;
}
return series;
}
function loadFile(event) {
var files = event.target.files;
for (var i = 0, f; f = files[i]; i++) {
var reader = new FileReader();
reader.onload = (function(theFile) {
return function(e) {
var data = e.target.result;
dataSeries_g = appendDataSeries(data, theFile.name, dataSeries_g);
drawChart();
};
})(f);
reader.readAsText(f);
}
}
function doExport(event) {
saveSvgAsPng(document.querySelector('svg'), 'Histogram');
}
</script>
</head>
<body>
<!--Div that will hold the pie chart-->
<div id="chart_div">Please select a histogram file</div>
<input type='file' onchange='loadFile(event)' multiple>
<button type='button' onclick='doExport(event)'>Export Image</button>
</body>
</html>
|