Skip to content

Commit 412338c

Browse files
esbenaasgerf
authored andcommitted
feat: parallel log scanning
1 parent ccf2dc6 commit 412338c

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 { ViewColumn } from "vscode";
23

34
import type { App } from "../common/app";
@@ -11,6 +12,7 @@ import { showAndLogExceptionWithTelemetry } from "../common/logging";
1112
import { extLogger } from "../common/logging/vscode";
1213
import type { WebviewPanelConfig } from "../common/vscode/abstract-webview";
1314
import { AbstractWebview } from "../common/vscode/abstract-webview";
15+
import { withProgress } from "../common/vscode/progress";
1416
import { telemetryListener } from "../common/vscode/telemetry";
1517
import type { HistoryItemLabelProvider } from "../query-history/history-item-label-provider";
1618
import { PerformanceOverviewScanner } from "../log-insights/performance-comparison";
@@ -41,12 +43,22 @@ export class ComparePerformanceView extends AbstractWebview<
4143

4244
await this.waitForPanelLoaded();
4345

44-
// TODO: try processing in (async) parallel once readJsonl is streaming
45-
const fromPerf = await scanLog(
46-
fromJsonLog,
47-
new PerformanceOverviewScanner(),
48-
);
49-
const toPerf = await scanLog(toJsonLog, new PerformanceOverviewScanner());
46+
function scanLogWithProgress(log: string, logDescription: string) {
47+
const bytes = statSync(log).size;
48+
return withProgress(
49+
async (progress) =>
50+
scanLog(log, new PerformanceOverviewScanner(), progress),
51+
52+
{
53+
title: `Scanning evaluator log ${logDescription} (${(bytes / 1024 / 1024).toFixed(1)} MB)`,
54+
},
55+
);
56+
}
57+
58+
const [fromPerf, toPerf] = await Promise.all([
59+
scanLogWithProgress(fromJsonLog, "1/2"),
60+
scanLogWithProgress(toJsonLog, "2/2"),
61+
]);
5062

5163
await this.postMessage({
5264
t: "setPerformanceComparison",

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)