Skip to content

Instantly share code, notes, and snippets.

@fzyzcjy
Last active October 27, 2021 10:30
Show Gist options
  • Save fzyzcjy/23a5f426db0741a15239400c7d33cbb5 to your computer and use it in GitHub Desktop.
Save fzyzcjy/23a5f426db0741a15239400c7d33cbb5 to your computer and use it in GitHub Desktop.
Beautify simpleperf html report by coloring it
let HIGHLIGHT_CODE = 'vision_utils';
let style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = `
.tom-blue-bg { background: #03a9f410; }
.tom-green { background: #4caf5050; }
.tom-orange { background: #ff980050; }
`;
style.id = "tom-inject-css";
$("#tom-inject-css").remove();
document.getElementsByTagName('head')[0].appendChild(style);
let tbody = $(".google-visualization-table-table tbody")[3];
let infos = [];
let totalMax = 0;
for (let trIndex = 0; trIndex < tbody.children.length; ++trIndex) {
let tr = tbody.children[trIndex];
let [tdTotal, tdSelf, tdCode] = tr.children;
let total = parseFloat(tdTotal.textContent.replaceAll('%', ''));
let code = tdCode.textContent;
if (totalMax < total) totalMax = total;
infos.push({total, code});
}
for (let trIndex = 0; trIndex < tbody.children.length; ++trIndex) {
let tr = tbody.children[trIndex];
let info = infos[trIndex];
if (info.code.includes(HIGHLIGHT_CODE)) {
tr.classList.add('tom-blue-bg');
}
if (info.total > totalMax * 0.02) {
tr.classList.add('tom-green');
}
if (info.total > totalMax * 0.1) {
tr.classList.add('tom-orange');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment