Skip to content

Commit c05e445

Browse files
henrymercerCopilot
andcommitted
Report tools download durations on both download paths
The streaming path reported no timings at all, so we have no data for the path that most runs take. It now reports a total duration, which is also populated on the download-then-extract path. That path additionally reports the extraction duration, which was previously computed but only logged. `downloadDurationMs` keeps its existing meaning of time spent downloading alone, so existing telemetry stays comparable. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 628ce334-991a-4578-9c1b-93d2e96bbddb
1 parent 486fec2 commit c05e445

3 files changed

Lines changed: 35 additions & 11 deletions

File tree

‎src/setup-codeql.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ test.serial(
234234
codeqlFolder: "codeql",
235235
statusReport: {
236236
downloadDurationMs: 200,
237+
totalDurationMs: 300,
237238
},
238239
toolsVersion: LINKED_CLI_VERSION.cliVersion,
239240
});
@@ -286,6 +287,7 @@ test.serial(
286287
codeqlFolder: "codeql",
287288
statusReport: {
288289
downloadDurationMs: 200,
290+
totalDurationMs: 300,
289291
},
290292
toolsVersion: expectedVersion,
291293
});

‎src/tools-download.test.ts‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { withTmpDir } from "./util";
1515
setupTests(test);
1616

1717
test.serial(
18-
"downloadAndExtract reports the duration when downloading before extracting",
18+
"downloadAndExtract reports the durations when downloading before extracting",
1919
async (t) => {
2020
await withTmpDir(async (tmpDir) => {
2121
const archivePath = path.join(tmpDir, "codeql-bundle.tar.gz");
@@ -34,6 +34,8 @@ test.serial(
3434
);
3535

3636
t.assert(Number.isInteger(statusReport.downloadDurationMs));
37+
t.assert(Number.isInteger(statusReport.extractionDurationMs));
38+
t.assert(Number.isInteger(statusReport.totalDurationMs));
3739
});
3840
},
3941
);
@@ -67,6 +69,7 @@ test.serial(
6769
);
6870

6971
t.assert(Number.isInteger(statusReport.downloadDurationMs));
72+
t.assert(Number.isInteger(statusReport.totalDurationMs));
7073
t.true(request.isDone());
7174
t.false(extractTarZst.called);
7275
t.true(downloadTool.calledOnce);
@@ -76,7 +79,7 @@ test.serial(
7679
);
7780

7881
test.serial(
79-
"downloadAndExtract omits the download duration when streaming extraction",
82+
"downloadAndExtract reports only the total duration when streaming extraction",
8083
async (t) => {
8184
await withTmpDir(async (tmpDir) => {
8285
sinon.stub(process, "platform").value("linux");
@@ -106,7 +109,9 @@ test.serial(
106109
getRunnerLogger(true),
107110
);
108111

109-
t.deepEqual(statusReport, {});
112+
t.assert(Number.isInteger(statusReport.totalDurationMs));
113+
t.is(statusReport.downloadDurationMs, undefined);
114+
t.is(statusReport.extractionDurationMs, undefined);
110115
t.false(downloadTool.called);
111116
t.true(extractTarZst.calledOnce);
112117
t.true(request.isDone());

‎src/tools-download.ts‎

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,21 @@ const STREAMING_STALL_TIMEOUT_MS = 5 * 60 * 1000; // 5 minutes
3131
const TOOLCACHE_TOOL_NAME = "CodeQL";
3232

3333
export type ToolsDownloadStatusReport = {
34+
/**
35+
* Time spent downloading the bundle, in milliseconds. Not populated when the bundle is downloaded
36+
* and extracted concurrently, since the two cannot be told apart.
37+
*/
3438
downloadDurationMs?: number;
39+
/**
40+
* Time spent extracting the bundle, in milliseconds. Not populated when the bundle is downloaded
41+
* and extracted concurrently, since the two cannot be told apart.
42+
*/
43+
extractionDurationMs?: number;
44+
/**
45+
* Total time taken to make the bundle available on disk, in milliseconds. This includes any time
46+
* spent on a streaming attempt that failed and fell back to downloading before extracting.
47+
*/
48+
totalDurationMs: number;
3549
};
3650

3751
export async function downloadAndExtract(
@@ -47,11 +61,12 @@ export async function downloadAndExtract(
4761
`Downloading CodeQL tools from ${codeqlURL} . This may take a while.`,
4862
);
4963

64+
const startTime = performance.now();
65+
5066
try {
5167
if (compressionMethod === "zstd" && process.platform === "linux") {
5268
logger.info(`Streaming the extraction of the CodeQL bundle.`);
5369

54-
const toolsInstallStart = performance.now();
5570
await downloadAndExtractZstdWithStreaming(
5671
codeqlURL,
5772
dest,
@@ -61,16 +76,14 @@ export async function downloadAndExtract(
6176
logger,
6277
);
6378

64-
const combinedDurationMs = Math.round(
65-
performance.now() - toolsInstallStart,
66-
);
79+
const totalDurationMs = Math.round(performance.now() - startTime);
6780
logger.info(
6881
`Finished downloading and extracting CodeQL bundle to ${dest} (${formatDuration(
69-
combinedDurationMs,
82+
totalDurationMs,
7083
)}).`,
7184
);
7285

73-
return {};
86+
return { totalDurationMs };
7487
}
7588
} catch (e) {
7689
core.warning(
@@ -98,7 +111,7 @@ export async function downloadAndExtract(
98111
)}).`,
99112
);
100113

101-
let extractionDurationMs: number;
114+
let extractionDurationMs: number | undefined;
102115

103116
try {
104117
logger.info("Extracting CodeQL bundle.");
@@ -120,7 +133,11 @@ export async function downloadAndExtract(
120133
await cleanUpPath(archivedBundlePath, "CodeQL bundle archive", logger);
121134
}
122135

123-
return { downloadDurationMs };
136+
return {
137+
downloadDurationMs,
138+
extractionDurationMs,
139+
totalDurationMs: Math.round(performance.now() - startTime),
140+
};
124141
}
125142

126143
async function downloadAndExtractZstdWithStreaming(

0 commit comments

Comments
 (0)