@kiwa-test/perf-harness 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/index.cjs +422 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +169 -1
- package/dist/index.d.ts +169 -1
- package/dist/index.js +407 -5
- package/dist/index.js.map +1 -1
- package/package.json +15 -16
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 cardene777
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
|
|
20
30
|
// src/index.ts
|
|
@@ -27,6 +37,11 @@ __export(index_exports, {
|
|
|
27
37
|
evaluatePerfGate: () => evaluatePerfGate,
|
|
28
38
|
loadBaseline: () => loadBaseline,
|
|
29
39
|
measure: () => measure,
|
|
40
|
+
measureConcurrent: () => measureConcurrent,
|
|
41
|
+
measureMemory: () => measureMemory,
|
|
42
|
+
resolveKiwaRepoRoot: () => resolveKiwaRepoRoot,
|
|
43
|
+
runPerf3Layer: () => runPerf3Layer,
|
|
44
|
+
runPerf3LayerLive: () => runPerf3LayerLive,
|
|
30
45
|
saveBaseline: () => saveBaseline
|
|
31
46
|
});
|
|
32
47
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -81,6 +96,66 @@ function percentile(sorted, ratio) {
|
|
|
81
96
|
return sorted[rank] ?? sorted[sorted.length - 1] ?? 0;
|
|
82
97
|
}
|
|
83
98
|
|
|
99
|
+
// src/concurrent.ts
|
|
100
|
+
async function measureConcurrent(input) {
|
|
101
|
+
if (input.concurrency < 1) {
|
|
102
|
+
throw new Error(`measureConcurrent: concurrency must be >= 1, got ${input.concurrency}`);
|
|
103
|
+
}
|
|
104
|
+
if (input.iterationsPerWorker < 1) {
|
|
105
|
+
throw new Error(
|
|
106
|
+
`measureConcurrent: iterationsPerWorker must be >= 1, got ${input.iterationsPerWorker}`
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
const warmup = input.warmup ?? 0;
|
|
110
|
+
if (warmup < 0) {
|
|
111
|
+
throw new Error(`measureConcurrent: warmup must be >= 0, got ${warmup}`);
|
|
112
|
+
}
|
|
113
|
+
const worker = async () => {
|
|
114
|
+
for (let index = 0; index < warmup; index += 1) {
|
|
115
|
+
await input.fn();
|
|
116
|
+
}
|
|
117
|
+
const local = [];
|
|
118
|
+
for (let index = 0; index < input.iterationsPerWorker; index += 1) {
|
|
119
|
+
const start = process.hrtime.bigint();
|
|
120
|
+
await input.fn();
|
|
121
|
+
const end = process.hrtime.bigint();
|
|
122
|
+
local.push(Number(end - start) / 1e6);
|
|
123
|
+
}
|
|
124
|
+
return local;
|
|
125
|
+
};
|
|
126
|
+
const workers = Array.from({ length: input.concurrency }, () => worker());
|
|
127
|
+
const perWorkerSamples = await Promise.all(workers);
|
|
128
|
+
const samples = perWorkerSamples.flat();
|
|
129
|
+
const totalIterations = input.concurrency * input.iterationsPerWorker;
|
|
130
|
+
return buildMeasureResult(input.name, totalIterations, warmup * input.concurrency, samples);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// src/memory.ts
|
|
134
|
+
async function measureMemory(input) {
|
|
135
|
+
if (input.iterations < 1) {
|
|
136
|
+
throw new Error(`measureMemory: iterations must be >= 1, got ${input.iterations}`);
|
|
137
|
+
}
|
|
138
|
+
const gcRef = globalThis.gc;
|
|
139
|
+
const gcExposed = typeof gcRef === "function";
|
|
140
|
+
if (gcExposed) gcRef();
|
|
141
|
+
const before = process.memoryUsage();
|
|
142
|
+
for (let index = 0; index < input.iterations; index += 1) {
|
|
143
|
+
await input.fn();
|
|
144
|
+
}
|
|
145
|
+
if (gcExposed) gcRef();
|
|
146
|
+
const after = process.memoryUsage();
|
|
147
|
+
const heapUsedDelta = after.heapUsed - before.heapUsed;
|
|
148
|
+
return {
|
|
149
|
+
iterationCount: input.iterations,
|
|
150
|
+
heapUsedDeltaBytes: heapUsedDelta,
|
|
151
|
+
heapUsedDeltaPerIterationBytes: heapUsedDelta / input.iterations,
|
|
152
|
+
rssDeltaBytes: after.rss - before.rss,
|
|
153
|
+
externalDeltaBytes: after.external - before.external,
|
|
154
|
+
arrayBuffersDeltaBytes: after.arrayBuffers - before.arrayBuffers,
|
|
155
|
+
gcExposed
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
|
|
84
159
|
// src/regression.ts
|
|
85
160
|
function detectRegression(input) {
|
|
86
161
|
const threshold = input.threshold ?? 0.2;
|
|
@@ -136,9 +211,9 @@ function sampleStats(samples) {
|
|
|
136
211
|
// src/baseline.ts
|
|
137
212
|
var import_promises = require("fs/promises");
|
|
138
213
|
var import_node_path = require("path");
|
|
139
|
-
async function loadBaseline(
|
|
214
|
+
async function loadBaseline(path3) {
|
|
140
215
|
try {
|
|
141
|
-
const body = await (0, import_promises.readFile)(
|
|
216
|
+
const body = await (0, import_promises.readFile)(path3, "utf8");
|
|
142
217
|
return JSON.parse(body);
|
|
143
218
|
} catch (error) {
|
|
144
219
|
if (isMissingFile(error)) {
|
|
@@ -147,9 +222,9 @@ async function loadBaseline(path) {
|
|
|
147
222
|
throw error;
|
|
148
223
|
}
|
|
149
224
|
}
|
|
150
|
-
async function saveBaseline(
|
|
151
|
-
await (0, import_promises.mkdir)((0, import_node_path.dirname)(
|
|
152
|
-
await (0, import_promises.writeFile)(
|
|
225
|
+
async function saveBaseline(path3, result) {
|
|
226
|
+
await (0, import_promises.mkdir)((0, import_node_path.dirname)(path3), { recursive: true });
|
|
227
|
+
await (0, import_promises.writeFile)(path3, `${JSON.stringify(result, null, 2)}
|
|
153
228
|
`, "utf8");
|
|
154
229
|
}
|
|
155
230
|
function defaultBaselinePath(moduleName) {
|
|
@@ -373,6 +448,343 @@ function formatSignedPct(value) {
|
|
|
373
448
|
const sign = value > 0 ? "+" : "";
|
|
374
449
|
return `${sign}${value.toFixed(2)}%`;
|
|
375
450
|
}
|
|
451
|
+
|
|
452
|
+
// src/three-layer.ts
|
|
453
|
+
var import_node_fs = require("fs");
|
|
454
|
+
var import_node_path2 = __toESM(require("path"), 1);
|
|
455
|
+
async function runPerf3Layer(input) {
|
|
456
|
+
const serialIterations = input.serialIterations ?? 200;
|
|
457
|
+
const serialWarmup = input.serialWarmup ?? 5;
|
|
458
|
+
const concurrency = input.concurrency ?? 10;
|
|
459
|
+
const iterationsPerWorker = input.iterationsPerWorker ?? 50;
|
|
460
|
+
const memoryIterations = input.memoryIterations ?? 200;
|
|
461
|
+
const memoryCapDefault = 100 * 1024;
|
|
462
|
+
const baselinePath = input.baselinePath ?? defaultBaselinePath(input.moduleName);
|
|
463
|
+
const thresholdDocLink = input.thresholdDocLink ?? "../../quality/perf-thresholds";
|
|
464
|
+
const priorBaseline = await loadBaseline(baselinePath);
|
|
465
|
+
const combinedForBaseline = {};
|
|
466
|
+
const outcomes = [];
|
|
467
|
+
for (const op of input.ops) {
|
|
468
|
+
const serial = await measure({
|
|
469
|
+
name: `${op.name}.serial`,
|
|
470
|
+
iterations: serialIterations,
|
|
471
|
+
warmup: serialWarmup,
|
|
472
|
+
fn: async () => {
|
|
473
|
+
await op.fn();
|
|
474
|
+
}
|
|
475
|
+
});
|
|
476
|
+
const concurrent = await measureConcurrent({
|
|
477
|
+
name: `${op.name}.concurrent`,
|
|
478
|
+
concurrency,
|
|
479
|
+
iterationsPerWorker,
|
|
480
|
+
warmup: 2,
|
|
481
|
+
fn: async () => {
|
|
482
|
+
await op.fn();
|
|
483
|
+
}
|
|
484
|
+
});
|
|
485
|
+
const memory = await measureMemory({
|
|
486
|
+
fn: async () => {
|
|
487
|
+
await op.fn();
|
|
488
|
+
},
|
|
489
|
+
iterations: memoryIterations
|
|
490
|
+
});
|
|
491
|
+
const concurrentCap = op.concurrentP95CapMs ?? op.serialP95CapMs * 2;
|
|
492
|
+
const memoryCap = op.memoryArrayBuffersCapBytes ?? memoryCapDefault;
|
|
493
|
+
const serialGate = evaluatePerfGate({
|
|
494
|
+
result: serial,
|
|
495
|
+
thresholds: { p95Ms: op.serialP95CapMs }
|
|
496
|
+
});
|
|
497
|
+
const concurrentGate = evaluatePerfGate({
|
|
498
|
+
result: concurrent,
|
|
499
|
+
thresholds: { p95Ms: concurrentCap }
|
|
500
|
+
});
|
|
501
|
+
const memoryGatePassed = memory.arrayBuffersDeltaBytes < memoryCap;
|
|
502
|
+
const priorSerial = priorBaseline?.[`${op.name}.serial`];
|
|
503
|
+
const regression = priorSerial ? detectRegression({ current: serial, baseline: priorSerial, threshold: 0.2 }) : null;
|
|
504
|
+
combinedForBaseline[`${op.name}.serial`] = serial;
|
|
505
|
+
combinedForBaseline[`${op.name}.concurrent`] = concurrent;
|
|
506
|
+
outcomes.push({
|
|
507
|
+
name: op.name,
|
|
508
|
+
serial,
|
|
509
|
+
concurrent,
|
|
510
|
+
memory,
|
|
511
|
+
serialGatePassed: serialGate.verdict.passed,
|
|
512
|
+
concurrentGatePassed: concurrentGate.verdict.passed,
|
|
513
|
+
memoryGatePassed,
|
|
514
|
+
regressionVerdict: regression ? regression.verdict : "n/a (baseline seeded)"
|
|
515
|
+
});
|
|
516
|
+
}
|
|
517
|
+
const baselineSeeded = priorBaseline === null;
|
|
518
|
+
if (baselineSeeded) {
|
|
519
|
+
await saveBaseline(
|
|
520
|
+
baselinePath,
|
|
521
|
+
combinedForBaseline
|
|
522
|
+
);
|
|
523
|
+
}
|
|
524
|
+
const allPassed = outcomes.every(
|
|
525
|
+
(o) => o.serialGatePassed && o.concurrentGatePassed && o.memoryGatePassed
|
|
526
|
+
);
|
|
527
|
+
writeReport({
|
|
528
|
+
reportPath: input.reportPath,
|
|
529
|
+
moduleName: input.moduleName,
|
|
530
|
+
outcomes,
|
|
531
|
+
ops: input.ops,
|
|
532
|
+
thresholdDocLink,
|
|
533
|
+
priorBaseline,
|
|
534
|
+
concurrency,
|
|
535
|
+
iterationsPerWorker,
|
|
536
|
+
memoryIterations,
|
|
537
|
+
memoryCapDefault
|
|
538
|
+
});
|
|
539
|
+
return { outcomes, allPassed, baselineSeeded };
|
|
540
|
+
}
|
|
541
|
+
function writeReport(input) {
|
|
542
|
+
const lines = [
|
|
543
|
+
`# Perf Suite \u2014 ${input.moduleName}`,
|
|
544
|
+
"",
|
|
545
|
+
`Threshold source: [docs/quality/perf-thresholds.md](${input.thresholdDocLink})`,
|
|
546
|
+
"",
|
|
547
|
+
"## Serial p95 (concurrency = 1)",
|
|
548
|
+
"",
|
|
549
|
+
"| op | p95 | cap | gate | regression |",
|
|
550
|
+
"|---|---|---|---|---|"
|
|
551
|
+
];
|
|
552
|
+
input.ops.forEach((op, idx) => {
|
|
553
|
+
const out = input.outcomes[idx];
|
|
554
|
+
lines.push(
|
|
555
|
+
`| ${op.name} | ${out.serial.p95.toFixed(2)}ms | ${op.serialP95CapMs}ms | ${out.serialGatePassed ? "PASS" : "FAIL"} | ${out.regressionVerdict} |`
|
|
556
|
+
);
|
|
557
|
+
});
|
|
558
|
+
lines.push(
|
|
559
|
+
"",
|
|
560
|
+
`## Concurrent p95 (concurrency = ${input.concurrency}, ${input.iterationsPerWorker} iter each)`,
|
|
561
|
+
"",
|
|
562
|
+
"| op | p95 | cap | gate |",
|
|
563
|
+
"|---|---|---|---|"
|
|
564
|
+
);
|
|
565
|
+
input.ops.forEach((op, idx) => {
|
|
566
|
+
const out = input.outcomes[idx];
|
|
567
|
+
const cap = op.concurrentP95CapMs ?? op.serialP95CapMs * 2;
|
|
568
|
+
lines.push(
|
|
569
|
+
`| ${op.name} | ${out.concurrent.p95.toFixed(2)}ms | ${cap}ms | ${out.concurrentGatePassed ? "PASS" : "FAIL"} |`
|
|
570
|
+
);
|
|
571
|
+
});
|
|
572
|
+
lines.push(
|
|
573
|
+
"",
|
|
574
|
+
`## Memory retention (${input.memoryIterations} iter, arrayBuffers axis is the gate; heap is informational)`,
|
|
575
|
+
"",
|
|
576
|
+
"| op | heapUsed \u0394 | arrayBuffers \u0394 | cap | verdict |",
|
|
577
|
+
"|---|---|---|---|---|"
|
|
578
|
+
);
|
|
579
|
+
input.ops.forEach((op, idx) => {
|
|
580
|
+
const out = input.outcomes[idx];
|
|
581
|
+
const cap = op.memoryArrayBuffersCapBytes ?? input.memoryCapDefault;
|
|
582
|
+
lines.push(
|
|
583
|
+
`| ${op.name} | ${out.memory.heapUsedDeltaBytes} B | ${out.memory.arrayBuffersDeltaBytes} B | ${cap} B | ${out.memoryGatePassed ? "PASS" : "FAIL"} |`
|
|
584
|
+
);
|
|
585
|
+
});
|
|
586
|
+
lines.push("", "## Detailed serial reports", "");
|
|
587
|
+
input.ops.forEach((op, idx) => {
|
|
588
|
+
const out = input.outcomes[idx];
|
|
589
|
+
lines.push(`### ${op.name}`);
|
|
590
|
+
lines.push("");
|
|
591
|
+
const priorSerial = input.priorBaseline?.[`${op.name}.serial`];
|
|
592
|
+
lines.push(
|
|
593
|
+
emitPerfReport(out.serial, {
|
|
594
|
+
includeSamples: false,
|
|
595
|
+
...priorSerial !== void 0 ? { baseline: priorSerial } : {}
|
|
596
|
+
})
|
|
597
|
+
);
|
|
598
|
+
});
|
|
599
|
+
(0, import_node_fs.mkdirSync)(import_node_path2.default.dirname(input.reportPath), { recursive: true });
|
|
600
|
+
(0, import_node_fs.writeFileSync)(input.reportPath, `${lines.join("\n")}
|
|
601
|
+
`, "utf8");
|
|
602
|
+
}
|
|
603
|
+
function resolveKiwaRepoRoot(start) {
|
|
604
|
+
let current = start;
|
|
605
|
+
while (true) {
|
|
606
|
+
const pkgPath = import_node_path2.default.join(current, "package.json");
|
|
607
|
+
if ((0, import_node_fs.existsSync)(pkgPath)) {
|
|
608
|
+
const m = JSON.parse((0, import_node_fs.readFileSync)(pkgPath, "utf8"));
|
|
609
|
+
if (m.name === "kiwa-monorepo") return current;
|
|
610
|
+
}
|
|
611
|
+
const parent = import_node_path2.default.dirname(current);
|
|
612
|
+
if (parent === current) throw new Error(`Could not resolve repo root from ${start}`);
|
|
613
|
+
current = parent;
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
// src/live.ts
|
|
618
|
+
var import_node_fs2 = require("fs");
|
|
619
|
+
var import_node_path3 = __toESM(require("path"), 1);
|
|
620
|
+
async function runPerf3LayerLive(input) {
|
|
621
|
+
const serialIterations = input.serialIterations ?? 10;
|
|
622
|
+
const serialWarmup = input.serialWarmup ?? 1;
|
|
623
|
+
const concurrency = input.concurrency ?? 3;
|
|
624
|
+
const iterationsPerWorker = input.iterationsPerWorker ?? 3;
|
|
625
|
+
const memoryIterations = input.memoryIterations ?? 20;
|
|
626
|
+
const memoryCapDefault = 100 * 1024;
|
|
627
|
+
const baselinePath = input.baselinePath ?? defaultBaselinePath(`${input.moduleName}.live`);
|
|
628
|
+
const thresholdDocLink = input.thresholdDocLink ?? "../../quality/perf-thresholds";
|
|
629
|
+
const priorBaseline = await loadBaseline(baselinePath);
|
|
630
|
+
const combinedForBaseline = {};
|
|
631
|
+
const outcomes = [];
|
|
632
|
+
let baselineSeeded = false;
|
|
633
|
+
let anySkipped = false;
|
|
634
|
+
for (const op of input.ops) {
|
|
635
|
+
const missing = op.requiredEnv.filter((key) => !process.env[key]);
|
|
636
|
+
if (missing.length > 0) {
|
|
637
|
+
anySkipped = true;
|
|
638
|
+
outcomes.push({
|
|
639
|
+
name: op.name,
|
|
640
|
+
skipped: true,
|
|
641
|
+
skipReason: `LIVE_ENV_MISSING: ${missing.join(", ")}`
|
|
642
|
+
});
|
|
643
|
+
continue;
|
|
644
|
+
}
|
|
645
|
+
const serial = await measure({
|
|
646
|
+
name: `${op.name}.live.serial`,
|
|
647
|
+
iterations: serialIterations,
|
|
648
|
+
warmup: serialWarmup,
|
|
649
|
+
fn: async () => {
|
|
650
|
+
await op.fn();
|
|
651
|
+
}
|
|
652
|
+
});
|
|
653
|
+
const concurrent = await measureConcurrent({
|
|
654
|
+
name: `${op.name}.live.concurrent`,
|
|
655
|
+
concurrency,
|
|
656
|
+
iterationsPerWorker,
|
|
657
|
+
warmup: 1,
|
|
658
|
+
fn: async () => {
|
|
659
|
+
await op.fn();
|
|
660
|
+
}
|
|
661
|
+
});
|
|
662
|
+
const memory = await measureMemory({
|
|
663
|
+
fn: async () => {
|
|
664
|
+
await op.fn();
|
|
665
|
+
},
|
|
666
|
+
iterations: memoryIterations
|
|
667
|
+
});
|
|
668
|
+
const concurrentCap = op.concurrentP95CapMs ?? op.serialP95CapMs * 2;
|
|
669
|
+
const memoryCap = op.memoryArrayBuffersCapBytes ?? memoryCapDefault;
|
|
670
|
+
const serialGate = evaluatePerfGate({
|
|
671
|
+
result: serial,
|
|
672
|
+
thresholds: { p95Ms: op.serialP95CapMs }
|
|
673
|
+
});
|
|
674
|
+
const concurrentGate = evaluatePerfGate({
|
|
675
|
+
result: concurrent,
|
|
676
|
+
thresholds: { p95Ms: concurrentCap }
|
|
677
|
+
});
|
|
678
|
+
const memoryGatePassed = memory.arrayBuffersDeltaBytes < memoryCap;
|
|
679
|
+
const priorSerial = priorBaseline?.[`${op.name}.live.serial`];
|
|
680
|
+
const regression = priorSerial ? detectRegression({ current: serial, baseline: priorSerial, threshold: 0.2 }) : null;
|
|
681
|
+
combinedForBaseline[`${op.name}.live.serial`] = serial;
|
|
682
|
+
combinedForBaseline[`${op.name}.live.concurrent`] = concurrent;
|
|
683
|
+
outcomes.push({
|
|
684
|
+
name: op.name,
|
|
685
|
+
skipped: false,
|
|
686
|
+
skipReason: null,
|
|
687
|
+
serial,
|
|
688
|
+
concurrent,
|
|
689
|
+
memory,
|
|
690
|
+
serialGatePassed: serialGate.verdict.passed,
|
|
691
|
+
concurrentGatePassed: concurrentGate.verdict.passed,
|
|
692
|
+
memoryGatePassed,
|
|
693
|
+
regressionVerdict: regression ? regression.verdict : "n/a (baseline seeded)"
|
|
694
|
+
});
|
|
695
|
+
}
|
|
696
|
+
const anyMeasured = outcomes.some((o) => !o.skipped);
|
|
697
|
+
if (anyMeasured && priorBaseline === null) {
|
|
698
|
+
await saveBaseline(baselinePath, combinedForBaseline);
|
|
699
|
+
baselineSeeded = true;
|
|
700
|
+
}
|
|
701
|
+
const allPassed = outcomes.filter((o) => !o.skipped).every((o) => o.serialGatePassed && o.concurrentGatePassed && o.memoryGatePassed);
|
|
702
|
+
writeLiveReport({
|
|
703
|
+
reportPath: input.reportPath,
|
|
704
|
+
moduleName: input.moduleName,
|
|
705
|
+
outcomes,
|
|
706
|
+
ops: input.ops,
|
|
707
|
+
thresholdDocLink,
|
|
708
|
+
priorBaseline,
|
|
709
|
+
concurrency,
|
|
710
|
+
iterationsPerWorker,
|
|
711
|
+
memoryIterations,
|
|
712
|
+
memoryCapDefault
|
|
713
|
+
});
|
|
714
|
+
return { outcomes, allPassed, anySkipped, baselineSeeded };
|
|
715
|
+
}
|
|
716
|
+
function writeLiveReport(input) {
|
|
717
|
+
const lines = [
|
|
718
|
+
`# Perf Suite \u2014 ${input.moduleName} (LIVE)`,
|
|
719
|
+
"",
|
|
720
|
+
`Threshold source: [docs/quality/perf-thresholds.md \xA7 Real-API measurement mode](${input.thresholdDocLink})`,
|
|
721
|
+
""
|
|
722
|
+
];
|
|
723
|
+
const skippedOps = input.outcomes.filter((o) => o.skipped);
|
|
724
|
+
const measuredOps = input.outcomes.filter((o) => !o.skipped);
|
|
725
|
+
if (skippedOps.length > 0) {
|
|
726
|
+
lines.push("## Skipped ops (missing env)", "", "| op | reason |", "|---|---|");
|
|
727
|
+
for (const o of skippedOps) lines.push(`| ${o.name} | ${o.skipReason} |`);
|
|
728
|
+
lines.push("");
|
|
729
|
+
}
|
|
730
|
+
if (measuredOps.length === 0) {
|
|
731
|
+
lines.push("_No live ops ran this pass. Set the required env vars to enable._");
|
|
732
|
+
} else {
|
|
733
|
+
lines.push("## Serial p95 (LIVE)", "");
|
|
734
|
+
lines.push("| op | p95 | cap | gate | regression |");
|
|
735
|
+
lines.push("|---|---|---|---|---|");
|
|
736
|
+
input.ops.forEach((op) => {
|
|
737
|
+
const out = input.outcomes.find((o) => o.name === op.name);
|
|
738
|
+
if (!out || out.skipped || !out.serial) return;
|
|
739
|
+
lines.push(
|
|
740
|
+
`| ${op.name} | ${out.serial.p95.toFixed(2)}ms | ${op.serialP95CapMs}ms | ${out.serialGatePassed ? "PASS" : "FAIL"} | ${out.regressionVerdict} |`
|
|
741
|
+
);
|
|
742
|
+
});
|
|
743
|
+
lines.push(
|
|
744
|
+
"",
|
|
745
|
+
`## Concurrent p95 (LIVE, concurrency = ${input.concurrency})`,
|
|
746
|
+
"",
|
|
747
|
+
"| op | p95 | cap | gate |",
|
|
748
|
+
"|---|---|---|---|"
|
|
749
|
+
);
|
|
750
|
+
input.ops.forEach((op) => {
|
|
751
|
+
const out = input.outcomes.find((o) => o.name === op.name);
|
|
752
|
+
if (!out || out.skipped || !out.concurrent) return;
|
|
753
|
+
const cap = op.concurrentP95CapMs ?? op.serialP95CapMs * 2;
|
|
754
|
+
lines.push(
|
|
755
|
+
`| ${op.name} | ${out.concurrent.p95.toFixed(2)}ms | ${cap}ms | ${out.concurrentGatePassed ? "PASS" : "FAIL"} |`
|
|
756
|
+
);
|
|
757
|
+
});
|
|
758
|
+
lines.push("", "## Memory retention (LIVE)", "");
|
|
759
|
+
lines.push("| op | heapUsed \u0394 | arrayBuffers \u0394 | cap | verdict |");
|
|
760
|
+
lines.push("|---|---|---|---|---|");
|
|
761
|
+
input.ops.forEach((op) => {
|
|
762
|
+
const out = input.outcomes.find((o) => o.name === op.name);
|
|
763
|
+
if (!out || out.skipped || !out.memory) return;
|
|
764
|
+
const cap = op.memoryArrayBuffersCapBytes ?? input.memoryCapDefault;
|
|
765
|
+
lines.push(
|
|
766
|
+
`| ${op.name} | ${out.memory.heapUsedDeltaBytes} B | ${out.memory.arrayBuffersDeltaBytes} B | ${cap} B | ${out.memoryGatePassed ? "PASS" : "FAIL"} |`
|
|
767
|
+
);
|
|
768
|
+
});
|
|
769
|
+
lines.push("", "## Detailed serial reports", "");
|
|
770
|
+
input.ops.forEach((op) => {
|
|
771
|
+
const out = input.outcomes.find((o) => o.name === op.name);
|
|
772
|
+
if (!out || out.skipped || !out.serial) return;
|
|
773
|
+
lines.push(`### ${op.name}`);
|
|
774
|
+
lines.push("");
|
|
775
|
+
const priorSerial = input.priorBaseline?.[`${op.name}.live.serial`];
|
|
776
|
+
lines.push(
|
|
777
|
+
emitPerfReport(out.serial, {
|
|
778
|
+
includeSamples: false,
|
|
779
|
+
...priorSerial !== void 0 ? { baseline: priorSerial } : {}
|
|
780
|
+
})
|
|
781
|
+
);
|
|
782
|
+
});
|
|
783
|
+
}
|
|
784
|
+
(0, import_node_fs2.mkdirSync)(import_node_path3.default.dirname(input.reportPath), { recursive: true });
|
|
785
|
+
(0, import_node_fs2.writeFileSync)(input.reportPath, `${lines.join("\n")}
|
|
786
|
+
`, "utf8");
|
|
787
|
+
}
|
|
376
788
|
// Annotate the CommonJS export names for ESM import in node:
|
|
377
789
|
0 && (module.exports = {
|
|
378
790
|
buildMeasureResult,
|
|
@@ -382,6 +794,11 @@ function formatSignedPct(value) {
|
|
|
382
794
|
evaluatePerfGate,
|
|
383
795
|
loadBaseline,
|
|
384
796
|
measure,
|
|
797
|
+
measureConcurrent,
|
|
798
|
+
measureMemory,
|
|
799
|
+
resolveKiwaRepoRoot,
|
|
800
|
+
runPerf3Layer,
|
|
801
|
+
runPerf3LayerLive,
|
|
385
802
|
saveBaseline
|
|
386
803
|
});
|
|
387
804
|
//# sourceMappingURL=index.cjs.map
|