Skip to content

Commit

Permalink
Make analyze resilient to malformed logs
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewiggins committed Nov 1, 2023
1 parent 570f5c0 commit 0fc963f
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions benches/scripts/analyze.js
Expand Up @@ -96,7 +96,7 @@ function logDifferences(key, results) {
/**
* @param {string} version
* @param {string[]} logPaths
* @param {(logs: TraceEvent[], logFilePath: string) => number} [getThreadId]
* @param {(logs: TraceEvent[], logFilePath: string) => number | null} [getThreadId]
* @param {(log: TraceEvent) => boolean} [trackEventsIn]
* @returns {Promise<Map<string, ResultStats>>}
*/
Expand All @@ -108,6 +108,10 @@ async function getStatsFromLogs(version, logPaths, getThreadId, trackEventsIn) {
const logs = JSON.parse(await readFile(logPath, 'utf8'));

let tid = getThreadId ? getThreadId(logs, logPath) : null;
if (tid == null) {
console.warn(`Could not find threadId for ${logPath}. Skipping...`);
continue;
}

/** @type {Array<{ id: string; start: number; end: number; }>} Determine what durations to track events under */
const parentLogs = [];
Expand Down Expand Up @@ -245,18 +249,10 @@ async function getStatsFromLogs(version, logPaths, getThreadId, trackEventsIn) {
/**
* @param {import('./tracing').TraceEvent[]} logs
* @param {string} logFilePath
* @returns {number}
* @returns {number | null}
*/
function getDurationThread(logs, logFilePath) {
let log = logs.find(isDurationLog);

if (log == null) {
throw new Error(
`Could not find blink.user_timing log for "run-final" or "duration" in ${logFilePath}.`
);
} else {
return log.tid;
}
return logs.find(isDurationLog)?.tid ?? null;
}

/**
Expand Down

0 comments on commit 0fc963f

Please sign in to comment.