Share elapsed-time rounding for bundle downloads

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Henry Mercer
2026-09-16 19:51:23 +01:00
parent 89606bbad1
commit f4fa111630
5 changed files with 63 additions and 31 deletions

56
lib/entry-points.js generated
View File

@@ -4305,7 +4305,7 @@ var require_util2 = __commonJS({
var { redirectStatusSet, referrerPolicySet: referrerPolicyTokens, badPortsSet } = require_constants3(); var { redirectStatusSet, referrerPolicySet: referrerPolicyTokens, badPortsSet } = require_constants3();
var { getGlobalOrigin } = require_global(); var { getGlobalOrigin } = require_global();
var { collectASequenceOfCodePoints, collectAnHTTPQuotedString, removeChars, parseMIMEType } = require_data_url(); var { collectASequenceOfCodePoints, collectAnHTTPQuotedString, removeChars, parseMIMEType } = require_data_url();
var { performance: performance7 } = require("node:perf_hooks"); var { performance: performance8 } = require("node:perf_hooks");
var { isBlobLike, ReadableStreamFrom, isValidHTTPToken, normalizedMethodRecordsBase } = require_util(); var { isBlobLike, ReadableStreamFrom, isValidHTTPToken, normalizedMethodRecordsBase } = require_util();
var assert = require("node:assert"); var assert = require("node:assert");
var { isUint8Array } = require("node:util/types"); var { isUint8Array } = require("node:util/types");
@@ -4464,7 +4464,7 @@ var require_util2 = __commonJS({
}; };
} }
function coarsenedSharedCurrentTime(crossOriginIsolatedCapability) { function coarsenedSharedCurrentTime(crossOriginIsolatedCapability) {
return coarsenTime(performance7.now(), crossOriginIsolatedCapability); return coarsenTime(performance8.now(), crossOriginIsolatedCapability);
} }
function createOpaqueTimingInfo(timingInfo) { function createOpaqueTimingInfo(timingInfo) {
return { return {
@@ -142119,7 +142119,7 @@ module.exports = __toCommonJS(entry_points_exports);
// src/analyze-action.ts // src/analyze-action.ts
var fs23 = __toESM(require("fs")); var fs23 = __toESM(require("fs"));
var import_path5 = __toESM(require("path")); var import_path5 = __toESM(require("path"));
var import_perf_hooks5 = require("perf_hooks"); var import_perf_hooks6 = require("perf_hooks");
var core17 = __toESM(require_core()); var core17 = __toESM(require_core());
// src/action-common.ts // src/action-common.ts
@@ -142201,6 +142201,7 @@ var fs = __toESM(require("fs"));
var fsPromises = __toESM(require("fs/promises")); var fsPromises = __toESM(require("fs/promises"));
var os = __toESM(require("os")); var os = __toESM(require("os"));
var path = __toESM(require("path")); var path = __toESM(require("path"));
var import_perf_hooks = require("perf_hooks");
var core2 = __toESM(require_core()); var core2 = __toESM(require_core());
var io = __toESM(require_io()); var io = __toESM(require_io());
@@ -145892,6 +145893,9 @@ async function bundleDb(config, language, codeql, dbName, { includeDiagnostics }
); );
return databaseBundlePath; return databaseBundlePath;
} }
function durationMsSince(startTime) {
return Math.round(import_perf_hooks.performance.now() - startTime);
}
async function delay(milliseconds, opts) { async function delay(milliseconds, opts) {
const { allowProcessExit } = opts || {}; const { allowProcessExit } = opts || {};
return new Promise((resolve14) => { return new Promise((resolve14) => {
@@ -148633,7 +148637,7 @@ var SarifScanOrder = [
// src/analyze.ts // src/analyze.ts
var fs17 = __toESM(require("fs")); var fs17 = __toESM(require("fs"));
var path16 = __toESM(require("path")); var path16 = __toESM(require("path"));
var import_perf_hooks4 = require("perf_hooks"); var import_perf_hooks5 = require("perf_hooks");
var io5 = __toESM(require_io()); var io5 = __toESM(require_io());
// src/autobuild.ts // src/autobuild.ts
@@ -148897,7 +148901,7 @@ function wrapCliConfigurationError(cliError) {
// src/config-utils.ts // src/config-utils.ts
var fs10 = __toESM(require("fs")); var fs10 = __toESM(require("fs"));
var path11 = __toESM(require("path")); var path11 = __toESM(require("path"));
var import_perf_hooks = require("perf_hooks"); var import_perf_hooks2 = require("perf_hooks");
var core10 = __toESM(require_core()); var core10 = __toESM(require_core());
// src/caching-utils.ts // src/caching-utils.ts
@@ -150523,9 +150527,9 @@ async function initActionState({
}; };
} }
async function downloadCacheWithTime(codeQL, languages, logger) { async function downloadCacheWithTime(codeQL, languages, logger) {
const start = import_perf_hooks.performance.now(); const start = import_perf_hooks2.performance.now();
const trapCaches = await downloadTrapCaches(codeQL, languages, logger); const trapCaches = await downloadTrapCaches(codeQL, languages, logger);
const trapCacheDownloadTime = import_perf_hooks.performance.now() - start; const trapCacheDownloadTime = import_perf_hooks2.performance.now() - start;
return { trapCaches, trapCacheDownloadTime }; return { trapCaches, trapCacheDownloadTime };
} }
async function loadUserConfig(actionState, configFile, workspacePath, apiDetails, tempDir) { async function loadUserConfig(actionState, configFile, workspacePath, apiDetails, tempDir) {
@@ -150929,10 +150933,10 @@ async function initConfig(actionState, inputs) {
} }
if (await features.getValue("ignore_generated_files" /* IgnoreGeneratedFiles */) && isDynamicWorkflow()) { if (await features.getValue("ignore_generated_files" /* IgnoreGeneratedFiles */) && isDynamicWorkflow()) {
try { try {
const generatedFilesCheckStartedAt = import_perf_hooks.performance.now(); const generatedFilesCheckStartedAt = import_perf_hooks2.performance.now();
const generatedFiles = await getGeneratedFiles(inputs.sourceRoot); const generatedFiles = await getGeneratedFiles(inputs.sourceRoot);
const generatedFilesDuration = Math.round( const generatedFilesDuration = Math.round(
import_perf_hooks.performance.now() - generatedFilesCheckStartedAt import_perf_hooks2.performance.now() - generatedFilesCheckStartedAt
); );
if (generatedFiles.length > 0) { if (generatedFiles.length > 0) {
config.computedConfig["paths-ignore"] ??= []; config.computedConfig["paths-ignore"] ??= [];
@@ -151216,7 +151220,7 @@ async function logGeneratedFilesTelemetry(config, duration, generatedFilesCount)
// src/setup-codeql.ts // src/setup-codeql.ts
var fs14 = __toESM(require("fs")); var fs14 = __toESM(require("fs"));
var path13 = __toESM(require("path")); var path13 = __toESM(require("path"));
var import_perf_hooks3 = require("perf_hooks"); var import_perf_hooks4 = require("perf_hooks");
var core12 = __toESM(require_core()); var core12 = __toESM(require_core());
var toolcache3 = __toESM(require_tool_cache()); var toolcache3 = __toESM(require_tool_cache());
var import_fast_deep_equal = __toESM(require_fast_deep_equal()); var import_fast_deep_equal = __toESM(require_fast_deep_equal());
@@ -151789,7 +151793,7 @@ function inferCompressionMethod(tarPath) {
var fs13 = __toESM(require("fs")); var fs13 = __toESM(require("fs"));
var os4 = __toESM(require("os")); var os4 = __toESM(require("os"));
var path12 = __toESM(require("path")); var path12 = __toESM(require("path"));
var import_perf_hooks2 = require("perf_hooks"); var import_perf_hooks3 = require("perf_hooks");
var core11 = __toESM(require_core()); var core11 = __toESM(require_core());
var import_http_client = __toESM(require_lib()); var import_http_client = __toESM(require_lib());
var toolcache2 = __toESM(require_tool_cache()); var toolcache2 = __toESM(require_tool_cache());
@@ -151802,7 +151806,7 @@ async function downloadAndExtract(codeqlURL, compressionMethod, dest, authorizat
logger.info( logger.info(
`Downloading CodeQL tools from ${codeqlURL} . This may take a while.` `Downloading CodeQL tools from ${codeqlURL} . This may take a while.`
); );
const startTime = import_perf_hooks2.performance.now(); const startTime = import_perf_hooks3.performance.now();
try { try {
if (compressionMethod === "zstd" && process.platform === "linux") { if (compressionMethod === "zstd" && process.platform === "linux") {
logger.info(`Streaming the extraction of the CodeQL bundle.`); logger.info(`Streaming the extraction of the CodeQL bundle.`);
@@ -151814,7 +151818,7 @@ async function downloadAndExtract(codeqlURL, compressionMethod, dest, authorizat
tarVersion, tarVersion,
logger logger
); );
const totalDurationMs = Math.round(import_perf_hooks2.performance.now() - startTime); const totalDurationMs = durationMsSince(startTime);
logger.info( logger.info(
`Finished downloading and extracting CodeQL bundle to ${dest} (${formatDuration( `Finished downloading and extracting CodeQL bundle to ${dest} (${formatDuration(
totalDurationMs totalDurationMs
@@ -151832,14 +151836,14 @@ async function downloadAndExtract(codeqlURL, compressionMethod, dest, authorizat
); );
core11.warning(`Falling back to downloading the bundle before extracting.`); core11.warning(`Falling back to downloading the bundle before extracting.`);
} }
const toolsDownloadStart = import_perf_hooks2.performance.now(); const toolsDownloadStart = import_perf_hooks3.performance.now();
const archivedBundlePath = await toolcache2.downloadTool( const archivedBundlePath = await toolcache2.downloadTool(
codeqlURL, codeqlURL,
void 0, void 0,
authorization, authorization,
headers headers
); );
const downloadDurationMs = Math.round(import_perf_hooks2.performance.now() - toolsDownloadStart); const downloadDurationMs = durationMsSince(toolsDownloadStart);
logger.info( logger.info(
`Finished downloading CodeQL bundle to ${archivedBundlePath} (${formatDuration( `Finished downloading CodeQL bundle to ${archivedBundlePath} (${formatDuration(
downloadDurationMs downloadDurationMs
@@ -151848,7 +151852,7 @@ async function downloadAndExtract(codeqlURL, compressionMethod, dest, authorizat
let extractionDurationMs; let extractionDurationMs;
try { try {
logger.info("Extracting CodeQL bundle."); logger.info("Extracting CodeQL bundle.");
const extractionStart = import_perf_hooks2.performance.now(); const extractionStart = import_perf_hooks3.performance.now();
await extract( await extract(
archivedBundlePath, archivedBundlePath,
dest, dest,
@@ -151856,7 +151860,7 @@ async function downloadAndExtract(codeqlURL, compressionMethod, dest, authorizat
tarVersion, tarVersion,
logger logger
); );
extractionDurationMs = Math.round(import_perf_hooks2.performance.now() - extractionStart); extractionDurationMs = durationMsSince(extractionStart);
logger.info( logger.info(
`Finished extracting CodeQL bundle to ${dest} (${formatDuration( `Finished extracting CodeQL bundle to ${dest} (${formatDuration(
extractionDurationMs extractionDurationMs
@@ -151868,7 +151872,7 @@ async function downloadAndExtract(codeqlURL, compressionMethod, dest, authorizat
return { return {
downloadDurationMs, downloadDurationMs,
extractionDurationMs, extractionDurationMs,
totalDurationMs: Math.round(import_perf_hooks2.performance.now() - startTime) totalDurationMs: durationMsSince(startTime)
}; };
} }
async function downloadAndExtractZstdWithStreaming(codeqlURL, dest, authorization, headers, tarVersion, logger) { async function downloadAndExtractZstdWithStreaming(codeqlURL, dest, authorization, headers, tarVersion, logger) {
@@ -152679,7 +152683,7 @@ async function downloadCodeQLBundle(action, source, apiDetails, tarVersion, temp
const { bundle } = source; const { bundle } = source;
const { logger } = action; const { logger } = action;
await tryDeleteToolcacheBundles(action); await tryDeleteToolcacheBundles(action);
const startTime = import_perf_hooks3.performance.now(); const startTime = import_perf_hooks4.performance.now();
try { try {
return await downloadCodeQL( return await downloadCodeQL(
source, source,
@@ -152709,7 +152713,7 @@ async function downloadCodeQLBundle(action, source, apiDetails, tarVersion, temp
...result, ...result,
statusReport: { statusReport: {
...result.statusReport, ...result.statusReport,
totalDurationMs: Math.round(import_perf_hooks3.performance.now() - startTime), totalDurationMs: durationMsSince(startTime),
perLanguageBundleFallback: true perLanguageBundleFallback: true
} }
}; };
@@ -153873,10 +153877,10 @@ function dbIsFinalized(config, language, logger) {
} }
} }
async function finalizeDatabaseCreation(codeql, features, config, threadsFlag, memoryFlag, logger) { async function finalizeDatabaseCreation(codeql, features, config, threadsFlag, memoryFlag, logger) {
const extractionStart = import_perf_hooks4.performance.now(); const extractionStart = import_perf_hooks5.performance.now();
await runExtraction(codeql, features, config, logger); await runExtraction(codeql, features, config, logger);
const extractionTime = import_perf_hooks4.performance.now() - extractionStart; const extractionTime = import_perf_hooks5.performance.now() - extractionStart;
const trapImportStart = import_perf_hooks4.performance.now(); const trapImportStart = import_perf_hooks5.performance.now();
for (const language of config.languages) { for (const language of config.languages) {
if (dbIsFinalized(config, language, logger)) { if (dbIsFinalized(config, language, logger)) {
logger.info( logger.info(
@@ -153893,7 +153897,7 @@ async function finalizeDatabaseCreation(codeql, features, config, threadsFlag, m
logger.endGroup(); logger.endGroup();
} }
} }
const trapImportTime = import_perf_hooks4.performance.now() - trapImportStart; const trapImportTime = import_perf_hooks5.performance.now() - trapImportStart;
return { return {
scanned_language_extraction_duration_ms: Math.round(extractionTime), scanned_language_extraction_duration_ms: Math.round(extractionTime),
trap_import_duration_ms: Math.round(trapImportTime) trap_import_duration_ms: Math.round(trapImportTime)
@@ -156700,9 +156704,9 @@ async function run({ startedAt, logger }) {
features, features,
logger logger
); );
const trapCacheUploadStartTime = import_perf_hooks5.performance.now(); const trapCacheUploadStartTime = import_perf_hooks6.performance.now();
didUploadTrapCaches = await uploadTrapCaches(codeql, config, logger); didUploadTrapCaches = await uploadTrapCaches(codeql, config, logger);
trapCacheUploadTime = import_perf_hooks5.performance.now() - trapCacheUploadStartTime; trapCacheUploadTime = import_perf_hooks6.performance.now() - trapCacheUploadStartTime;
trapCacheCleanupTelemetry = await cleanupTrapCaches( trapCacheCleanupTelemetry = await cleanupTrapCaches(
config, config,
features, features,

View File

@@ -1170,7 +1170,7 @@ export async function downloadCodeQLBundle(
...result, ...result,
statusReport: { statusReport: {
...result.statusReport, ...result.statusReport,
totalDurationMs: Math.round(performance.now() - startTime), totalDurationMs: util.durationMsSince(startTime),
perLanguageBundleFallback: true, perLanguageBundleFallback: true,
}, },
}; };

View File

@@ -17,6 +17,7 @@ import * as tar from "./tar";
import { import {
asHTTPError, asHTTPError,
cleanUpPath, cleanUpPath,
durationMsSince,
getErrorMessage, getErrorMessage,
getRequiredEnvParam, getRequiredEnvParam,
HTTPError, HTTPError,
@@ -91,7 +92,7 @@ export async function downloadAndExtract(
logger, logger,
); );
const totalDurationMs = Math.round(performance.now() - startTime); const totalDurationMs = durationMsSince(startTime);
logger.info( logger.info(
`Finished downloading and extracting CodeQL bundle to ${dest} (${formatDuration( `Finished downloading and extracting CodeQL bundle to ${dest} (${formatDuration(
totalDurationMs, totalDurationMs,
@@ -124,7 +125,7 @@ export async function downloadAndExtract(
authorization, authorization,
headers, headers,
); );
const downloadDurationMs = Math.round(performance.now() - toolsDownloadStart); const downloadDurationMs = durationMsSince(toolsDownloadStart);
logger.info( logger.info(
`Finished downloading CodeQL bundle to ${archivedBundlePath} (${formatDuration( `Finished downloading CodeQL bundle to ${archivedBundlePath} (${formatDuration(
@@ -144,7 +145,7 @@ export async function downloadAndExtract(
tarVersion, tarVersion,
logger, logger,
); );
extractionDurationMs = Math.round(performance.now() - extractionStart); extractionDurationMs = durationMsSince(extractionStart);
logger.info( logger.info(
`Finished extracting CodeQL bundle to ${dest} (${formatDuration( `Finished extracting CodeQL bundle to ${dest} (${formatDuration(
extractionDurationMs, extractionDurationMs,
@@ -157,7 +158,7 @@ export async function downloadAndExtract(
return { return {
downloadDurationMs, downloadDurationMs,
extractionDurationMs, extractionDurationMs,
totalDurationMs: Math.round(performance.now() - startTime), totalDurationMs: durationMsSince(startTime),
}; };
} }

View File

@@ -1,6 +1,7 @@
import * as fs from "fs"; import * as fs from "fs";
import * as os from "os"; import * as os from "os";
import path from "path"; import path from "path";
import { performance } from "perf_hooks";
import * as core from "@actions/core"; import * as core from "@actions/core";
import test from "ava"; import test from "ava";
@@ -508,6 +509,26 @@ test("joinAtMost - truncates list if array is > than limit", (t) => {
t.false(result.includes("test6")); t.false(result.includes("test6"));
}); });
test.serial(
"durationMsSince rounds elapsed milliseconds rather than the timestamps",
(t) => {
const startTime = 1000.25;
const now = sinon.stub(performance, "now");
for (const [endTime, expected] of [
[1000.25, 0],
[1000.74, 0],
[1000.75, 1],
[1001.74, 1],
[1001.75, 2],
[2000.74, 1000],
[2000.75, 1001],
]) {
now.returns(endTime);
t.is(util.durationMsSince(startTime), expected);
}
},
);
test("Success creates a success result", (t) => { test("Success creates a success result", (t) => {
const result = new util.Success("test value"); const result = new util.Success("test value");
t.true(result.isSuccess()); t.true(result.isSuccess());

View File

@@ -2,6 +2,7 @@ import * as fs from "fs";
import * as fsPromises from "fs/promises"; import * as fsPromises from "fs/promises";
import * as os from "os"; import * as os from "os";
import * as path from "path"; import * as path from "path";
import { performance } from "perf_hooks";
import * as core from "@actions/core"; import * as core from "@actions/core";
import * as io from "@actions/io"; import * as io from "@actions/io";
@@ -681,6 +682,11 @@ export async function bundleDb(
return databaseBundlePath; return databaseBundlePath;
} }
/** Returns the elapsed milliseconds, rounded, since a `performance.now()` timestamp. */
export function durationMsSince(startTime: number): number {
return Math.round(performance.now() - startTime);
}
/** /**
* @param milliseconds time to delay * @param milliseconds time to delay
* @param opts options * @param opts options