|
| 1 | +import { ViewColumn } from "vscode"; |
| 2 | + |
| 3 | +import type { CodeQLCliServer } from "../codeql-cli/cli"; |
| 4 | +import type { App } from "../common/app"; |
| 5 | +import { redactableError } from "../common/errors"; |
| 6 | +import type { |
| 7 | + FromComparePerformanceViewMessage, |
| 8 | + ToComparePerformanceViewMessage, |
| 9 | +} from "../common/interface-types"; |
| 10 | +import type { Logger } from "../common/logging"; |
| 11 | +import { showAndLogExceptionWithTelemetry } from "../common/logging"; |
| 12 | +import { extLogger } from "../common/logging/vscode"; |
| 13 | +import type { WebviewPanelConfig } from "../common/vscode/abstract-webview"; |
| 14 | +import { AbstractWebview } from "../common/vscode/abstract-webview"; |
| 15 | +import { telemetryListener } from "../common/vscode/telemetry"; |
| 16 | +import type { HistoryItemLabelProvider } from "../query-history/history-item-label-provider"; |
| 17 | +import { PerformanceOverviewScanner } from "../log-insights/performance-comparison"; |
| 18 | +import { scanLog } from "../log-insights/log-scanner"; |
| 19 | +import type { ResultsView } from "../local-queries"; |
| 20 | + |
| 21 | +export class ComparePerformanceView extends AbstractWebview< |
| 22 | + ToComparePerformanceViewMessage, |
| 23 | + FromComparePerformanceViewMessage |
| 24 | +> { |
| 25 | + constructor( |
| 26 | + app: App, |
| 27 | + public cliServer: CodeQLCliServer, // TODO: make private |
| 28 | + public logger: Logger, |
| 29 | + public labelProvider: HistoryItemLabelProvider, |
| 30 | + private resultsView: ResultsView, |
| 31 | + ) { |
| 32 | + super(app); |
| 33 | + } |
| 34 | + |
| 35 | + async showResults(fromJsonLog: string, toJsonLog: string) { |
| 36 | + const panel = await this.getPanel(); |
| 37 | + panel.reveal(undefined, false); |
| 38 | + |
| 39 | + // Close the results viewer as it will have opened when the user clicked the query in the history view |
| 40 | + // (which they must do as part of the UI interaction for opening the performance view). |
| 41 | + // The performance view generally needs a lot of width so it's annoying to have the result viewer open. |
| 42 | + this.resultsView.hidePanel(); |
| 43 | + |
| 44 | + await this.waitForPanelLoaded(); |
| 45 | + |
| 46 | + // TODO: try processing in (async) parallel once readJsonl is streaming |
| 47 | + const fromPerf = await scanLog( |
| 48 | + fromJsonLog, |
| 49 | + new PerformanceOverviewScanner(), |
| 50 | + ); |
| 51 | + const toPerf = await scanLog(toJsonLog, new PerformanceOverviewScanner()); |
| 52 | + |
| 53 | + // TODO: filter out irrelevant common predicates before transfer? |
| 54 | + |
| 55 | + await this.postMessage({ |
| 56 | + t: "setPerformanceComparison", |
| 57 | + from: fromPerf.getData(), |
| 58 | + to: toPerf.getData(), |
| 59 | + }); |
| 60 | + } |
| 61 | + |
| 62 | + protected getPanelConfig(): WebviewPanelConfig { |
| 63 | + return { |
| 64 | + viewId: "comparePerformanceView", |
| 65 | + title: "Compare CodeQL Performance", |
| 66 | + viewColumn: ViewColumn.Active, |
| 67 | + preserveFocus: true, |
| 68 | + view: "compare-performance", |
| 69 | + }; |
| 70 | + } |
| 71 | + |
| 72 | + protected onPanelDispose(): void {} |
| 73 | + |
| 74 | + protected async onMessage( |
| 75 | + msg: FromComparePerformanceViewMessage, |
| 76 | + ): Promise<void> { |
| 77 | + switch (msg.t) { |
| 78 | + case "viewLoaded": |
| 79 | + this.onWebViewLoaded(); |
| 80 | + break; |
| 81 | + |
| 82 | + case "telemetry": |
| 83 | + telemetryListener?.sendUIInteraction(msg.action); |
| 84 | + break; |
| 85 | + |
| 86 | + case "unhandledError": |
| 87 | + void showAndLogExceptionWithTelemetry( |
| 88 | + extLogger, |
| 89 | + telemetryListener, |
| 90 | + redactableError( |
| 91 | + msg.error, |
| 92 | + )`Unhandled error in performance comparison view: ${msg.error.message}`, |
| 93 | + ); |
| 94 | + break; |
| 95 | + } |
| 96 | + } |
| 97 | +} |
0 commit comments