Skip to content

Commit cd998c4

Browse files
authored
Merge pull request #3820 from github/esbena/parallel-log-parsing
Hackathon: Parallel evaluator summary log parsing
2 parents cf29df5 + bdbcd01 commit cd998c4

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

extensions/ql-vscode/src/compare-performance/compare-performance-view.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { statSync } from "fs";
12
import path from "path";
23
import { ViewColumn } from "vscode";
34
import type { CodeQLCliServer } from "../codeql-cli/cli";
@@ -12,6 +13,7 @@ import { showAndLogExceptionWithTelemetry } from "../common/logging";
1213
import { extLogger } from "../common/logging/vscode";
1314
import type { WebviewPanelConfig } from "../common/vscode/abstract-webview";
1415
import { AbstractWebview } from "../common/vscode/abstract-webview";
16+
import { withProgress } from "../common/vscode/progress";
1517
import { telemetryListener } from "../common/vscode/telemetry";
1618
import type { ResultsView } from "../local-queries";
1719
import { scanLog } from "../log-insights/log-scanner";
@@ -54,12 +56,22 @@ export class ComparePerformanceView extends AbstractWebview<
5456

5557
await this.waitForPanelLoaded();
5658

57-
// TODO: try processing in (async) parallel once readJsonl is streaming
58-
const fromPerf = await scanLog(
59-
fromJsonLog,
60-
new PerformanceOverviewScanner(),
61-
);
62-
const toPerf = await scanLog(toJsonLog, new PerformanceOverviewScanner());
59+
function scanLogWithProgress(log: string, logDescription: string) {
60+
const bytes = statSync(log).size;
61+
return withProgress(
62+
async (progress) =>
63+
scanLog(log, new PerformanceOverviewScanner(), progress),
64+
65+
{
66+
title: `Scanning evaluator log ${logDescription} (${(bytes / 1024 / 1024).toFixed(1)} MB)`,
67+
},
68+
);
69+
}
70+
71+
const [fromPerf, toPerf] = await Promise.all([
72+
scanLogWithProgress(fromJsonLog, "1/2"),
73+
scanLogWithProgress(toJsonLog, "2/2"),
74+
]);
6375

6476
// TODO: filter out irrelevant common predicates before transfer?
6577

extensions/ql-vscode/src/log-insights/log-scanner.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import type { SummaryEvent } from "./log-summary";
2-
import { readJsonlFile } from "../common/jsonl-reader";
31
import type { Disposable } from "../common/disposable-object";
2+
import { readJsonlFile } from "../common/jsonl-reader";
3+
import type { ProgressCallback } from "../common/vscode/progress";
4+
import type { SummaryEvent } from "./log-summary";
45

56
/**
67
* Callback interface used to report diagnostics from a log scanner.
@@ -114,15 +115,22 @@ export class EvaluationLogScannerSet {
114115
}
115116

116117
/**
117-
* Scan the evaluator summary log using the given scanner. For conveience, returns the scanner.
118+
* Scan the evaluator summary log using the given scanner. For convenience, returns the scanner.
118119
*
119120
* @param jsonSummaryLocation The file path of the JSON summary log.
120121
* @param scanner The scanner to process events from the log
121122
*/
122123
export async function scanLog<T extends EvaluationLogScanner>(
123124
jsonSummaryLocation: string,
124125
scanner: T,
126+
progress?: ProgressCallback,
125127
): Promise<T> {
128+
progress?.({
129+
// XXX all scans have step 1 - the backing progress tracker allows increments instead of steps - but for now we are happy with a tiny UI that says what is happening
130+
message: `Scanning ...`,
131+
step: 1,
132+
maxStep: 2,
133+
});
126134
await readJsonlFile<SummaryEvent>(jsonSummaryLocation, async (obj) => {
127135
scanner.onEvent(obj);
128136
});

0 commit comments

Comments
 (0)