Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 28 additions & 5 deletions core/scripts/legacy-javascript/examine-latest-run.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,22 @@ import {readJson} from '../../test/test-utils.js';

const LATEST_RUN_DIR = path.join(LH_ROOT, 'latest-run');

/**
* @param {number} bytes
*/
function formatBytes(bytes) {
bytes = Math.floor(10 * bytes / 1024) / 10;
return `${bytes} KiB`;
}

async function main() {
/** @type {LH.Artifacts} */
const artifacts = readJson(`${LATEST_RUN_DIR}/artifacts.json`);
const devtoolsLog = readJson(`${LATEST_RUN_DIR}/defaultPass.devtoolslog.json`);
const trace = readJson(`${LATEST_RUN_DIR}/defaultPass.trace.json`);
const scripts = artifacts.Scripts;
artifacts.devtoolsLogs = {defaultPass: devtoolsLog};
artifacts.traces = {defaultPass: trace};
artifacts.DevtoolsLog = devtoolsLog;
artifacts.Trace = trace;

const auditResults = await LegacyJavascript.audit(artifacts, {
computedCache: new Map(),
Expand All @@ -49,16 +57,31 @@ async function main() {
return;
}

let totalWastedBytes = 0;
for (const item of items) {
totalWastedBytes += item.wastedBytes ?? 0;
}

console.log(colors.bold(`${items.length} signals found!`));
if (totalWastedBytes) {
console.log(colors.bold(`Wasted bytes: ${formatBytes(totalWastedBytes)}`));
}

for (const item of items) {
if (typeof item.url !== 'string') continue;

const script = scripts.find(s => s.url === item.url);
const signals = Array.isArray(item.signals) ? item.signals : [];
const locations = Array.isArray(item.locations) ? item.locations : [];
const signals = Array.isArray(item.subItems?.items) ?
item.subItems?.items.map(item => item.signal) :
[];
const locations = Array.isArray(item.subItems?.items) ?
item.subItems?.items.map(item => item.location) :
[];
const wastedBytes = item.wastedBytes ?? 0;

console.log('---------------------------------');
console.log(`URL: ${item.url}`);
console.log(`Wasted bytes: ${formatBytes(wastedBytes)}`);
console.log(`Signals: ${signals.length}`);
if (!script || !script.content) {
console.log('\nFailed to find script content! :/');
Expand All @@ -71,7 +94,7 @@ async function main() {
const signal = signals[i];
const location = locations[i];
if (typeof location !== 'object' || format.isIcuMessage(location) ||
location.type !== 'source-location') {
location.type !== 'source-location' || !signal) {
continue;
}

Expand Down
Loading