[tools] Add support to better load ClusterTelemetry results in callstats.html

- supporting appending new data instead of simply replacing the current set
- fix issue when not filtering out groups on initial loading

Change-Id: I77d508e644b247fa236ea64ef919639cac6ee425

NOTRY=true

Change-Id: I77d508e644b247fa236ea64ef919639cac6ee425
Reviewed-on: https://chromium-review.googlesource.com/451276
Commit-Queue: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: Jaroslav Sevcik <jarin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#43685}
This commit is contained in:
Camillo Bruni 2017-03-09 10:53:34 +01:00 committed by Commit Bot
parent 0f716acada
commit e9a25e287d

View File

@ -679,8 +679,9 @@ code is governed by a BSD-style license that can be found in the LICENSE file.
var impact = entry.getTimeImpact();
return impact < -1 || 1 < impact
}
return entry.getTimePercentImpact() > 0.1;
return entry.getTimePercentImpact() > 0.01;
});
entries = entries.slice(0, 50);
entries.sort((a, b) => {
var cmp = b.getTimePercentImpact() - a.getTimePercentImpact();
if (isCompareView || cmp.toFixed(1) == 0) {
@ -707,7 +708,7 @@ code is governed by a BSD-style license that can be found in the LICENSE file.
}
function showGraphs(page) {
var groups = page.groups.slice();
var groups = page.groups.filter(each => each.enabled);
// Sort groups by the biggest impact
groups.sort((a, b) => {
return b.getTimeImpact() - a.getTimeImpact();
@ -715,7 +716,7 @@ code is governed by a BSD-style license that can be found in the LICENSE file.
if (selectedGroup == undefined) {
selectedGroup = groups[0];
} else {
groups = groups.filter(each => each.enabled && each.name != selectedGroup.name);
groups = groups.filter(each => each.name != selectedGroup.name);
groups.unshift(selectedGroup);
}
showPageGraph(groups, page);
@ -843,18 +844,21 @@ code is governed by a BSD-style license that can be found in the LICENSE file.
height: height,
hAxis: {
minValue: 0,
textStyle: { fontSize: 14 }
},
animation:{
duration: 500,
duration: dataTable.getNumberOfRows() > 50 ? 0 : 500 ,
easing: 'out',
},
vAxis: {
textStyle: { fontSize: 14 }
},
tooltip: { textStyle: { fontSize: 14 }},
explorer: {
actions: ['dragToZoom', 'rightClickToReset'],
maxZoomIn: 0.01
},
legend: {position:'top', textStyle:{fontSize: '16px'}},
legend: {position:'top', maxLines: 1, textStyle: { fontSize: 14 }},
chartArea: {left:200, top:50, width:'98%', height:'80%'},
colors: groups.map(each => each.color)
};
@ -1080,19 +1084,28 @@ code is governed by a BSD-style license that can be found in the LICENSE file.
xhr.send();
}
function handleAppendFile() {
var files = document.getElementById("appendInput").files;
loadFiles(files, true);
}
function handleLoadFile() {
var files = document.getElementById("uploadInput").files;
loadFiles(files, false)
}
function loadFiles(files, append) {
var file = files[0];
var reader = new FileReader();
reader.onload = function(evt) {
handleLoadText(this.result);
handleLoadText(this.result, append);
}
reader.readAsText(file);
}
function handleLoadText(text) {
handleLoadJSON(JSON.parse(text));
function handleLoadText(text, append) {
handleLoadJSON(JSON.parse(text), append);
}
function getStateFromParams() {
@ -1106,6 +1119,56 @@ code is governed by a BSD-style license that can be found in the LICENSE file.
return result;
}
function handleLoadJSON(json, append) {
let isFirstLoad = pages === undefined;
json = fixClusterTelemetryResults(json);
json = fixSinglePageJSON(json);
if (append && !isFirstLoad) {
json = createUniqueVersions(json)
}
var state = getStateFromParams();
if (!append || isFirstLoad) {
pages = new Pages();
versions = Versions.fromJSON(json);
} else {
Versions.fromJSON(json).forEach(e => versions.add(e))
}
initialize()
if (isFirstLoad && !popHistoryState(state)) {
showEntry(selectedPage.total);
}
}
function fixClusterTelemetryResults(json) {
// Convert CT results to callstats compatible JSON
// Input:
// { PATH: { "pairs": { METRIC: { "count": XX, "time": XX }.. }}.. }
let firstEntry;
for (let key in json) {
firstEntry = json[key];
break;
}
// Return the original JSON if it is not a CT result.
if (firstEntry.pairs === undefined) return json;
// The results include already the group totals, remove them by filtering.
let groupNames = new Set(Array.from(Group.groups.values()).map(e => e.name));
let result = Object.create(null);
for (let file_name in json) {
let entries = [];
let file_data = json[file_name].pairs;
for (let name in file_data) {
if(name != "Total" && groupNames.has(name)) continue;
let entry = file_data[name];
let count = entry.count;
let time = entry.time;
entries.push([name, time, 0, 0, count, 0, 0]);
}
let domain = file_name.split("/").slice(-1)[0];
result[domain] = entries;
}
return {__proto__:null, ClusterTelemetry: result};
}
function fixSinglePageJSON(json) {
// Try to detect the single-version case, where we're missing the toplevel
// version object. The incoming JSON is of the form:
@ -1121,15 +1184,15 @@ code is governed by a BSD-style license that can be found in the LICENSE file.
return {"Default": json}
}
function handleLoadJSON(json) {
json = fixSinglePageJSON(json);
var state = getStateFromParams();
pages = new Pages();
versions = Versions.fromJSON(json);
initialize()
if (!popHistoryState(state)) {
showEntry(selectedPage.total);
var appendIndex = 0;
function createUniqueVersions(json) {
// Make sure all toplevel entries are unique namaes and added properly
appendIndex++;
let result = {__proto__:null}
for (let key in json) {
result[key+"_"+appendIndex] = json[key];
}
return result
}
function handleToggleGroup(event) {
@ -1802,8 +1865,13 @@ code is governed by a BSD-style license that can be found in the LICENSE file.
<h2>Data</h2>
<form name="fileForm">
<p>
<label for="uploadInput">Load File:</label>
<input id="uploadInput" type="file" name="files" onchange="handleLoadFile();" accept=".json">
</p>
<p>
<label for="appendInput">Append File:</label>
<input id="appendInput" type="file" name="files" onchange="handleAppendFile();" accept=".json">
</p>
</form>
</div>