This commit is contained in:
2026-03-15 12:22:42 +01:00
parent cd99275933
commit 311ba5e7f3
558 changed files with 55182 additions and 22981 deletions

View File

@@ -131,6 +131,7 @@ function display(data) {
/* c8 ignore next */
module.exports = (function () {
const data = Object.create(null);
let displayEnabled = true;
/**
* Time the run
@@ -158,9 +159,42 @@ module.exports = (function () {
};
}
/**
* Returns a shallow copy of the collected timings data.
* @returns {Record<string, number>} mapping of ruleId to total time in ms
*/
function getData() {
return { ...data };
}
/**
* Merges rule timing totals collected elsewhere into this process' totals.
* @param {Record<string, number>} dataToMerge mapping of ruleId to total time in ms
* @returns {void}
*/
function mergeData(dataToMerge) {
for (const [key, value] of Object.entries(dataToMerge)) {
if (typeof data[key] === "undefined") {
data[key] = 0;
}
data[key] += value;
}
}
/**
* Disables printing of timing data on process exit.
* Intended for worker threads or non-main contexts.
* @returns {void}
*/
function disableDisplay() {
displayEnabled = false;
}
if (enabled) {
process.on("exit", () => {
display(data);
if (displayEnabled && Object.keys(data).length > 0) {
display(data);
}
});
}
@@ -168,5 +202,8 @@ module.exports = (function () {
time,
enabled,
getListSize,
getData,
mergeData,
disableDisplay,
};
})();