blob: b600dc957ca4dba795e96b9d57bebeecd5545b8e [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Chrome #include Analysis</title>
<!--Generated by analyze_includes.py. Provides the 'data' object.-->
<script src="include-analysis.js"></script>
<style>
tr td { text-align: right; }
tr td:nth-child(1) { text-align: left; }
tr td:nth-child(2) { text-align: left; }
tbody tr:hover { background-color: #dddddd; }
th { position: sticky; top: 0; background-color: #ffffff }
th:nth-child(n+2) { cursor: pointer; }
th.highlighted { background-color: #dddddd }
#filterResults { font-weight: bold }
</style>
</head>
<body>
<h1>Chrome #include Analysis (go/chrome-includes) Beta</h1>
<p>Build target: <span id="buildTarget">x</span> (Linux). Revision: <span id="buildRevision">x</span>. Analyzed on: <span id="analysisDate">x</span>.</p>
<p>Number of translation units: <span id="numRoots">x</span>. Total build size (sum of expanded translation unit sizes): <span id="totBuildSize">x</span> bytes.</p>
<p>Number of files: <span id="numFiles">x</span>. Total file size: <span id="totFileSize">x</span> bytes.</p>
<hr>
<p>
<label for="filter">Filter: (regex, includes:&lt;file&gt;, or includedBy:&lt;file&gt;)</label>
<input type="text" id="filter" name="filter" size="60" onKeyUp="if (event.keyCode == 13) document.getElementById('apply').click()">
<button onClick="changeState({filter: document.getElementById('filter').value})" id="apply">Apply</button>
<button onClick="changeState({filter: ''})">Clear</button>
<span id="filterResults"></span>
</p>
<table border="1">
<thead>
<tr>
<th>#</th>
<th id="filename" onclick="changeState({sort:, 'filename'})">Filename</th>
<th id="isize" colspan="2" onclick="changeState({sort: 'isize'})" title="The size of the individual file. Also shown as percentage of the total file size.">Individual Size (B) &#9432;</th>
<th id="tsize" colspan="2" onclick="changeState({sort: 'tsize'})" title="The size of the file and all the files it includes, directly and indirectly. Also shown as percentage of the total build size.">Expanded Size (B) &#9432;</th>
<th id="asize" colspan="2" onclick="changeState({sort: 'asize'})" title="The size added by this file being part of the build. In other words, if this file were empty and had no includes, how much smaller would the build be. Also shown as percentage of the total build size.">Added Size (B) &#9432;</th>
<th id="prevalence" colspan="2" onclick="changeState({sort: 'prevalence'})" title="Number of translation units that this file is part of. Also shown as percentage of the number of translation units.">Occurrences &#9432;</th>
<th id="includedby" onclick="changeState({sort: 'includedby'})" title="In how many files this file is included directly. Click the number to see the files.">Directly Included In &#9432;</th>
<th id="includes" onclick="changeState({sort: 'includes'})" title="How many files this file includes directly. Click the number to see the files.">Direct Includes &#9432;</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<hr>
<p>File size does not correlate perfectly with compile time, but can serve as a rough guide to what files are slow to compile.</p>
<p>Analysis by <a href="https://source.chromium.org/chromium/chromium/src/+/HEAD:tools/clang/scripts/analyze_includes.py">analyze_includes.py</a>.</p>
<script>
"use strict";
function sum(arr) {
return arr.reduce((a, b) => a + b, 0);
}
const numberFormat = new Intl.NumberFormat('en-US');
function fmt(num) {
return numberFormat.format(num);
}
function regexEscape(str) {
str = str.replaceAll('+', '\\+');
str = str.replaceAll('.', '\\.');
return str;
}
const totFileSize = sum(data.sizes);
const totBuildSize = sum(data.roots.map(r => data.tsizes[r]));
const numRoots = data.roots.length;
document.getElementById('buildTarget').textContent = data.target;
document.getElementById('buildRevision').innerHTML =
`<a href="https://crrev.com/${data.revision}">${data.revision}</a>`;
document.getElementById('analysisDate').textContent = data.date;
document.getElementById('numRoots').textContent = fmt(numRoots);
document.getElementById('totBuildSize').textContent = fmt(totBuildSize);
document.getElementById('numFiles').textContent = fmt(data.files.length);
document.getElementById('totFileSize').textContent = fmt(totFileSize);
function buildRow(i, rank) {
return `
<tr>
<td><a href="#${changedStateHash({filter: '^' + regexEscape(data.files[i] + '$')})}" title="Filter on this file.">${rank + 1}</a></td>
<td><a href="https://source.chromium.org/chromium/chromium/src/+/HEAD:${data.files[i]}">${data.files[i]}</a></td>
<td>${fmt(data.sizes[i])}</td> <td>${(100 * data.sizes[i] / totFileSize).toFixed(2)}&nbsp;%</td>
<td>${fmt(data.tsizes[i])}</td> <td>${(100 * data.tsizes[i] / totBuildSize).toFixed(2)}&nbsp;%</td>
<td>${fmt(data.asizes[i])}</td> <td>${(100 * data.asizes[i] / totBuildSize).toFixed(2)}&nbsp;%</td>
<td>${fmt(data.prevalence[i])}</td> <td>${(100 * data.prevalence[i] / numRoots).toFixed(2)}&nbsp;%</td>
<td><a href="#${changedStateHash({filter: 'includes:' + data.files[i], sort: 'filename'})}">${fmt(data.included_by[i].length)}</a></td>
<td><a href="#${changedStateHash({filter: 'includedby:' + data.files[i], sort: 'filename'})}">${fmt(data.includes[i].length)}</a></td>
</tr>
`;
}
function clearTable() {
const tbody = document.querySelector('tbody');
tbody.parentNode.removeChild(tbody);
document.getElementById('filterResults').innerHTML = '';
}
function intersect(arr1, arr2) {
let s2 = new Set(arr2);
return arr1.filter(x => s2.has(x));
}
function buildTable() {
clearTable();
let fileNums = [...Array(data.files.length).keys()];
const state = getState();
let filter = state.get('filter');
document.getElementById('filter').value = filter;
if (filter !== '') {
let match;
// Handle includes: operator.
const includesOp = new RegExp(' *includes:([^ ]*) *');
while (match = filter.match(includesOp)) {
const include = match[1];
const fileNum = data.files.findIndex(n => n === include);
fileNums = intersect(fileNums, data.included_by[fileNum]);
filter = filter.replace(includesOp, '');
}
// Handle includedby: operator.
const includedByOp = new RegExp(' *includedby:([^ ]*) *');
while (match = filter.match(includedByOp)) {
const filename = match[1];
const fileNum = data.files.findIndex(n => n === filename);
fileNums = intersect(fileNums, data.includes[fileNum]);
filter = filter.replace(includedByOp, '');
}
const re = new RegExp(filter);
fileNums = fileNums.filter(i => data.files[i].match(re));
document.getElementById('filterResults').innerHTML =
`${fmt(fileNums.length)} result${fileNums.length == 1 ? '' : 's'}.`;
}
const sortFuncs = {
filename: (i, j) => data.files[i].localeCompare(data.files[j]),
isize: (i, j) => data.sizes[j] - data.sizes[i],
tsize: (i, j) => data.tsizes[j] - data.tsizes[i],
prevalence: (i, j) => data.prevalence[j] - data.prevalence[i],
includedby: (i, j) => data.included_by[j].length - data.included_by[i].length,
includes: (i, j) => data.includes[j].length - data.includes[i].length,
asize: (i, j) => data.asizes[j] - data.asizes[i],
};
document.querySelectorAll('th').forEach(th => th.classList.remove('highlighted'));
document.getElementById(state.get('sort')).classList.add('highlighted');
fileNums.sort(sortFuncs[state.get('sort')]);
const limit = Math.min(1000, fileNums.length);
fileNums = fileNums.slice(0, limit);
const tbody = document.createElement('tbody');
tbody.innerHTML = fileNums.map(buildRow).join('');
document.querySelector('table').appendChild(tbody);
}
function getState() {
let params = new URLSearchParams(window.location.hash.substring(1));
if (!params.has('filter'))
params.set('filter', '');
if (!params.has('sort'))
params.set('sort', 'asize');
return params;
}
function changedStateHash(changes) {
let s = getState();
for (const [key, value] of Object.entries(changes)) {
s.set(key, value);
}
return s.toString();
}
function changeState(changes) {
window.location.hash = changedStateHash(changes);
}
window.onhashchange = buildTable;
buildTable();
</script>
</body>
</html>