@ac-bench/measure-resource 0.1.11 → 0.2.1
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/CHANGELOG.md +148 -0
- package/README.md +17 -0
- package/dist/_counters.d.ts +62 -9
- package/dist/_counters.d.ts.map +1 -1
- package/dist/_counters.js +191 -15
- package/dist/_counters.js.map +1 -1
- package/dist/_gate-metrics.d.ts +10 -0
- package/dist/_gate-metrics.d.ts.map +1 -0
- package/dist/_gate-metrics.js +59 -0
- package/dist/_gate-metrics.js.map +1 -0
- package/dist/_run-case.d.ts +5 -0
- package/dist/_run-case.d.ts.map +1 -1
- package/dist/_run-case.js +65 -38
- package/dist/_run-case.js.map +1 -1
- package/dist/_statistics.d.ts.map +1 -1
- package/dist/_statistics.js +18 -3
- package/dist/_statistics.js.map +1 -1
- package/dist/_types.d.ts +66 -0
- package/dist/_types.d.ts.map +1 -1
- package/dist/_types.js +44 -0
- package/dist/_types.js.map +1 -1
- package/dist/_warnings.d.ts +4 -0
- package/dist/_warnings.d.ts.map +1 -1
- package/dist/_warnings.js +14 -0
- package/dist/_warnings.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/plugin.js +2 -0
- package/dist/plugin.js.map +1 -1
- package/package.json +11 -11
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,153 @@
|
|
|
1
1
|
# @ac-bench/measure-resource
|
|
2
2
|
|
|
3
|
+
## 0.2.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [0b4fe43]
|
|
8
|
+
- Updated dependencies [0b4fe43]
|
|
9
|
+
- Updated dependencies [0b4fe43]
|
|
10
|
+
- Updated dependencies [0b4fe43]
|
|
11
|
+
- Updated dependencies [0b4fe43]
|
|
12
|
+
- Updated dependencies [0b4fe43]
|
|
13
|
+
- Updated dependencies [0b4fe43]
|
|
14
|
+
- Updated dependencies [0b4fe43]
|
|
15
|
+
- Updated dependencies [0b4fe43]
|
|
16
|
+
- Updated dependencies [0b4fe43]
|
|
17
|
+
- Updated dependencies [0b4fe43]
|
|
18
|
+
- Updated dependencies [0b4fe43]
|
|
19
|
+
- Updated dependencies [0b4fe43]
|
|
20
|
+
- Updated dependencies [0b4fe43]
|
|
21
|
+
- Updated dependencies [0b4fe43]
|
|
22
|
+
- Updated dependencies [0b4fe43]
|
|
23
|
+
- Updated dependencies [0b4fe43]
|
|
24
|
+
- Updated dependencies [0b4fe43]
|
|
25
|
+
- Updated dependencies [0b4fe43]
|
|
26
|
+
- Updated dependencies [0b4fe43]
|
|
27
|
+
- Updated dependencies [0b4fe43]
|
|
28
|
+
- Updated dependencies [0b4fe43]
|
|
29
|
+
- Updated dependencies [0b4fe43]
|
|
30
|
+
- Updated dependencies [0b4fe43]
|
|
31
|
+
- Updated dependencies [0b4fe43]
|
|
32
|
+
- @ac-kit/algo@0.6.0
|
|
33
|
+
- @ac-bench/core@0.4.0
|
|
34
|
+
- @ac-kit/core@0.13.0
|
|
35
|
+
- @ac-kit/math-stats@0.6.0
|
|
36
|
+
- @ac-kit/model-dataset@0.3.0
|
|
37
|
+
- @ac-kit/app-report@0.3.1
|
|
38
|
+
|
|
39
|
+
## 0.2.0
|
|
40
|
+
|
|
41
|
+
### Minor Changes
|
|
42
|
+
|
|
43
|
+
- 34e8cfa: Reports tell conditions apart. **`@ac-bench/reporter-json`** writes the archive
|
|
44
|
+
(`format: "ac-bench-archive"`, version 1) instead of one section per measure:
|
|
45
|
+
every condition keyed and titled, so two suites that each declare a case `new`
|
|
46
|
+
are two conditions, with the run, machine and runtime descriptions, and what a
|
|
47
|
+
gate reads: each execution's `processKey` and `observations` per gate metric,
|
|
48
|
+
each condition's `metrics`, the run's `gates` and `verdicts`, so
|
|
49
|
+
`@ac-bench/gate` evaluates it offline. It folds
|
|
50
|
+
events as they arrive and keeps no raw result, and writes nothing for a run that
|
|
51
|
+
described nothing (a listing). **Migration:** read `conditions[].cases[].result`
|
|
52
|
+
where you read `<measure>.conditions[]`. **`@ac-bench/reporter-markdown`** opens
|
|
53
|
+
with an environment section and renders one titled table per condition, its
|
|
54
|
+
heading on one line whatever the titles or file name hold.
|
|
55
|
+
**`@ac-bench/reporter-csv`** writes one table per condition, each row ending with
|
|
56
|
+
`runtime` and `condition` columns; a condition with no result is one row with
|
|
57
|
+
only those two filled. Neither asks a measure to conclude on a condition with
|
|
58
|
+
no result. **`@ac-bench/measure-duration`** leaves the
|
|
59
|
+
raw `timings` out of its JSON form unless the run was started with
|
|
60
|
+
`--emit-samples`; a six-case archive no longer weighs tens of megabytes.
|
|
61
|
+
**Duration, jitter, resource and constant-time** close a case that threw as
|
|
62
|
+
`failed` — its failure result is still reported — so the archive, the report
|
|
63
|
+
and the run's outcome count it as failed rather than measured.
|
|
64
|
+
- 34e8cfa: Gates. Every measure package re-exports `ratioGate`, `differenceGate`,
|
|
65
|
+
`boundGate` and `registerGate` beside `beforeAll` and `afterAll`, so a suite
|
|
66
|
+
declares a gate next to the cases it reads. `@ac-bench/measure-duration` declares
|
|
67
|
+
the gate metrics `median` (the default) and `mean`, per operation on the log
|
|
68
|
+
scale: the variance of the median comes from its distribution-free interval,
|
|
69
|
+
never below what the clock's quantum forces over the timed span. A gate reads
|
|
70
|
+
`statistics`, not the overhead-adjusted ones. `@ac-bench/measure-resource`
|
|
71
|
+
declares `allocatedBytes` (linear, in bytes per operation, never more precise
|
|
72
|
+
than one byte over a batch) and `cpuTime` (log); its statistics gain
|
|
73
|
+
`allocatedBytesMad` and `cpuTimeMsMad`, the median absolute deviation of the
|
|
74
|
+
per-batch costs the medians summarise, and `allocatedBytesMedianVariance` and
|
|
75
|
+
`cpuTimeMsMedianVariance`, each median's exact bootstrap variance, which the
|
|
76
|
+
gate metrics read as the median's uncertainty. Measures without gate metrics
|
|
77
|
+
cannot be gated.
|
|
78
|
+
- 34e8cfa: `allocatedBytes` is correct for a batch whose garbage outgrows the young
|
|
79
|
+
generation. The measure now counts allocation with the best counter the process
|
|
80
|
+
offers — `v8.GCProfiler` (heap growth plus the bytes each collection freed in the
|
|
81
|
+
window, exact to the byte), then `v8.getHeapStatistics().total_allocated_bytes`
|
|
82
|
+
(Node 26, exact to about a megabyte), then plain heap growth — and removes the
|
|
83
|
+
counter's own measured cost, so an empty case reports 0 B/op instead of a 14 B/op
|
|
84
|
+
floor. One million operations that each allocate a three-element array report
|
|
85
|
+
about 72 B/op on Node 24 and 26, where they reported 0.
|
|
86
|
+
|
|
87
|
+
Each result records `allocationSource`. With plain heap growth as the only
|
|
88
|
+
counter, a batch in which a collection ran carries the `allocation-undercounted`
|
|
89
|
+
warning (and the statistics count `undercountedBatches`) instead of a silently
|
|
90
|
+
low number, and the next batch is halved to make a collection less likely.
|
|
91
|
+
|
|
92
|
+
Off-heap memory (typed array backing stores) is not counted by any heap
|
|
93
|
+
counter: the figure adds only the net growth of the process's external memory
|
|
94
|
+
and what collections reported freeing, and V8 can release one backing store
|
|
95
|
+
while another is allocated, or after a collection reports. The off-heap share
|
|
96
|
+
is therefore never exact: a batch that moved off-heap memory is a lower bound
|
|
97
|
+
(`offHeap: "lower-bound"` on the sample and the statistics, `offHeapBatches`, the
|
|
98
|
+
`off-heap-lower-bound` warning), and one that moved none is `"unknown"` — no
|
|
99
|
+
movement seen does not mean nothing was allocated off the heap. With
|
|
100
|
+
plain heap growth, a batch is also flagged when collections cannot be observed
|
|
101
|
+
at all, and an interrupted window is discarded instead of leaking into the next
|
|
102
|
+
case.
|
|
103
|
+
|
|
104
|
+
**Migration.** `allocatedBytes` figures from earlier versions are not comparable
|
|
105
|
+
for cases that allocate more than the young generation per batch, or that
|
|
106
|
+
allocate almost nothing. `ResourceBenchStatistics` gains `undercountedBatches`,
|
|
107
|
+
`offHeapBatches` and `offHeap`, and the case result `allocationSource` (all
|
|
108
|
+
required when parsing results from an earlier version).
|
|
109
|
+
|
|
110
|
+
### Patch Changes
|
|
111
|
+
|
|
112
|
+
- Updated dependencies [34e8cfa]
|
|
113
|
+
- Updated dependencies [34e8cfa]
|
|
114
|
+
- Updated dependencies [34e8cfa]
|
|
115
|
+
- Updated dependencies [34e8cfa]
|
|
116
|
+
- Updated dependencies [34e8cfa]
|
|
117
|
+
- Updated dependencies [34e8cfa]
|
|
118
|
+
- Updated dependencies [34e8cfa]
|
|
119
|
+
- Updated dependencies [34e8cfa]
|
|
120
|
+
- Updated dependencies [34e8cfa]
|
|
121
|
+
- Updated dependencies [34e8cfa]
|
|
122
|
+
- Updated dependencies [34e8cfa]
|
|
123
|
+
- Updated dependencies [34e8cfa]
|
|
124
|
+
- Updated dependencies [34e8cfa]
|
|
125
|
+
- Updated dependencies [34e8cfa]
|
|
126
|
+
- Updated dependencies [34e8cfa]
|
|
127
|
+
- Updated dependencies [34e8cfa]
|
|
128
|
+
- Updated dependencies [34e8cfa]
|
|
129
|
+
- Updated dependencies [34e8cfa]
|
|
130
|
+
- Updated dependencies [34e8cfa]
|
|
131
|
+
- Updated dependencies [34e8cfa]
|
|
132
|
+
- Updated dependencies [34e8cfa]
|
|
133
|
+
- Updated dependencies [34e8cfa]
|
|
134
|
+
- Updated dependencies [34e8cfa]
|
|
135
|
+
- Updated dependencies [34e8cfa]
|
|
136
|
+
- Updated dependencies [34e8cfa]
|
|
137
|
+
- Updated dependencies [34e8cfa]
|
|
138
|
+
- Updated dependencies [34e8cfa]
|
|
139
|
+
- Updated dependencies [34e8cfa]
|
|
140
|
+
- Updated dependencies [34e8cfa]
|
|
141
|
+
- Updated dependencies [34e8cfa]
|
|
142
|
+
- Updated dependencies [34e8cfa]
|
|
143
|
+
- Updated dependencies [34e8cfa]
|
|
144
|
+
- @ac-kit/algo@0.5.0
|
|
145
|
+
- @ac-kit/math-stats@0.5.0
|
|
146
|
+
- @ac-bench/core@0.3.0
|
|
147
|
+
- @ac-kit/core@0.12.0
|
|
148
|
+
- @ac-kit/model-dataset@0.2.0
|
|
149
|
+
- @ac-kit/app-report@0.3.0
|
|
150
|
+
|
|
3
151
|
## 0.1.11
|
|
4
152
|
|
|
5
153
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -20,6 +20,23 @@ resourceCondition("parse 10k records", () => {
|
|
|
20
20
|
Results are reported in their own units alongside a duration measure, never
|
|
21
21
|
converted into one.
|
|
22
22
|
|
|
23
|
+
Allocation is counted with the best counter the process offers, and each result
|
|
24
|
+
names it (`allocationSource`): `v8.GCProfiler` (heap growth plus what every
|
|
25
|
+
collection inside the window freed, exact to the byte), then
|
|
26
|
+
`v8.getHeapStatistics().total_allocated_bytes` (Node 26, exact to about a
|
|
27
|
+
megabyte), then plain heap growth. The counter's own cost is measured once and
|
|
28
|
+
removed, so an empty case reads 0 B/op, and a batch that threw discards its
|
|
29
|
+
window instead of leaking it into the next case. With plain heap growth only, a
|
|
30
|
+
batch is reported as `allocation-undercounted` whenever a collection ran or none
|
|
31
|
+
could be observed. Off-heap memory (typed array backing stores) is not seen by
|
|
32
|
+
the heap counters: only the net growth of external memory plus what collections
|
|
33
|
+
report freeing is added, and V8 can release one backing store while another is
|
|
34
|
+
allocated, or after the collection reports. So the off-heap share is never
|
|
35
|
+
exact: each result says `offHeap: "lower-bound"` (and warns
|
|
36
|
+
`off-heap-lower-bound`) when a batch moved off-heap memory, and
|
|
37
|
+
`offHeap: "unknown"` otherwise — no movement seen does not mean none was
|
|
38
|
+
allocated.
|
|
39
|
+
|
|
23
40
|
Host-bound: it reads Node's resource-usage and GC instrumentation.
|
|
24
41
|
|
|
25
42
|
Run suites with the `measure` CLI from `@ac-bench/cli`.
|
package/dist/_counters.d.ts
CHANGED
|
@@ -3,8 +3,6 @@ export type ResourceCounters = {
|
|
|
3
3
|
cpuUserUs: number;
|
|
4
4
|
cpuSystemUs: number;
|
|
5
5
|
heapUsedBytes: number;
|
|
6
|
-
externalBytes: number;
|
|
7
|
-
arrayBuffersBytes: number;
|
|
8
6
|
rssBytes: number;
|
|
9
7
|
};
|
|
10
8
|
/**
|
|
@@ -16,16 +14,71 @@ export type ResourceCounters = {
|
|
|
16
14
|
export declare function readResourceCounters(): ResourceCounters;
|
|
17
15
|
/** The heap ceiling this process was given, fixed for its lifetime. */
|
|
18
16
|
export declare function readHeapLimitBytes(): number;
|
|
17
|
+
export type AllocationCounterSource =
|
|
19
18
|
/**
|
|
20
|
-
*
|
|
21
|
-
*
|
|
19
|
+
* `v8.getHeapStatistics().total_allocated_bytes` (Node ≥ 26). Counts what the
|
|
20
|
+
* mutator allocated, collections included, but V8 advances it by whole
|
|
21
|
+
* allocation buffers, so a window is only exact to about a megabyte.
|
|
22
|
+
*/
|
|
23
|
+
"v8-total-allocated"
|
|
24
|
+
/**
|
|
25
|
+
* Heap growth plus what each collection inside the window freed, from
|
|
26
|
+
* `v8.GCProfiler` (Node ≥ 18.15). Exact to the byte whatever the garbage.
|
|
27
|
+
*/
|
|
28
|
+
| "gc-profiler"
|
|
29
|
+
/**
|
|
30
|
+
* Heap growth alone. Correct only while no collection runs in the window; a
|
|
31
|
+
* fallback, and one that says so through
|
|
32
|
+
* {@link AllocationCounter.undercounted}.
|
|
33
|
+
*/
|
|
34
|
+
| "heap-growth"
|
|
35
|
+
/**
|
|
36
|
+
* `performance.memory.usedJSHeapSize` in Chromium; provided by the browser
|
|
37
|
+
* entry.
|
|
38
|
+
*/
|
|
39
|
+
| "browser-heap-growth";
|
|
40
|
+
/**
|
|
41
|
+
* What a window's figure says about off-heap memory (typed array backing
|
|
42
|
+
* stores, buffers). No counter here sees a backing store allocated: they see
|
|
43
|
+
* the net movement of the process's external memory and what collections report
|
|
44
|
+
* freeing, and V8 can release one backing store while another is allocated, or
|
|
45
|
+
* after the collection reports. So no window's off-heap share is ever exact,
|
|
46
|
+
* and none is ever known to be zero:
|
|
47
|
+
*
|
|
48
|
+
* - `"lower-bound"`: external memory moved in the window; the figure includes
|
|
49
|
+
* that movement, and the bytes actually allocated off the heap may be more.
|
|
50
|
+
* - `"unknown"`: no movement was seen, which does not show that nothing was
|
|
51
|
+
* allocated off the heap — only that the net change stayed under 4 KiB.
|
|
52
|
+
*/
|
|
53
|
+
export type OffHeapAccounting = "lower-bound" | "unknown";
|
|
54
|
+
export type AllocationCounter = {
|
|
55
|
+
readonly source: AllocationCounterSource;
|
|
56
|
+
/** Whether the last window may have lost bytes to a collection. */
|
|
57
|
+
readonly undercounted: boolean;
|
|
58
|
+
/**
|
|
59
|
+
* What the last window's figure says about off-heap memory; never that none
|
|
60
|
+
* was allocated. See {@link OffHeapAccounting}.
|
|
61
|
+
*/
|
|
62
|
+
readonly offHeap: OffHeapAccounting;
|
|
63
|
+
/** Starts a window; one still open is discarded. */
|
|
64
|
+
begin(): void;
|
|
65
|
+
/**
|
|
66
|
+
* Bytes allocated since {@link AllocationCounter.begin}, minus the counter's
|
|
67
|
+
* own cost.
|
|
68
|
+
*/
|
|
69
|
+
end(): number;
|
|
70
|
+
/** Discards an open window, for a batch that threw before `end`. */
|
|
71
|
+
abort(): void;
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* The first of `sources` that works in this process, calibrated, or `null`.
|
|
22
75
|
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* reporting one would make a mean meaningless.
|
|
76
|
+
* A source that throws on construction or on an empty window is skipped rather
|
|
77
|
+
* than reported: this measure must keep working on a runtime that lacks the
|
|
78
|
+
* better counters.
|
|
27
79
|
*/
|
|
28
|
-
export declare function
|
|
80
|
+
export declare function selectAllocationCounter(): AllocationCounter;
|
|
81
|
+
export declare function selectAllocationCounter(sources: readonly AllocationCounterSource[]): AllocationCounter | null;
|
|
29
82
|
export declare function cpuTimeMs(before: ResourceCounters, after: ResourceCounters): number;
|
|
30
83
|
/** Whether the run was started with `--expose-gc`. */
|
|
31
84
|
export declare function hasExposedCollector(): boolean;
|
package/dist/_counters.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_counters.d.ts","sourceRoot":"","sources":["../src/_counters.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"_counters.d.ts","sourceRoot":"","sources":["../src/_counters.ts"],"names":[],"mappings":"AAKA,yEAAyE;AACzE,MAAM,MAAM,gBAAgB,GAAG;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,oBAAoB,IAAI,gBAAgB,CAUvD;AAED,uEAAuE;AACvE,wBAAgB,kBAAkB,IAAI,MAAM,CAE3C;AAED,MAAM,MAAM,uBAAuB;AAClC;;;;GAIG;AACD,oBAAoB;AACtB;;;GAGG;GACD,aAAa;AACf;;;;GAIG;GACD,aAAa;AACf;;;GAGG;GACD,qBAAqB,CAAC;AAEzB;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,iBAAiB,GAAG,aAAa,GAAG,SAAS,CAAC;AAE1D,MAAM,MAAM,iBAAiB,GAAG;IAC/B,QAAQ,CAAC,MAAM,EAAE,uBAAuB,CAAC;IAEzC,mEAAmE;IACnE,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC;IAE/B;;;OAGG;IACH,QAAQ,CAAC,OAAO,EAAE,iBAAiB,CAAC;IAEpC,oDAAoD;IACpD,KAAK,IAAI,IAAI,CAAC;IAEd;;;OAGG;IACH,GAAG,IAAI,MAAM,CAAC;IAEd,oEAAoE;IACpE,KAAK,IAAI,IAAI,CAAC;CACd,CAAC;AAkOF;;;;;;GAMG;AACH,wBAAgB,uBAAuB,IAAI,iBAAiB,CAAC;AAC7D,wBAAgB,uBAAuB,CACtC,OAAO,EAAE,SAAS,uBAAuB,EAAE,GACzC,iBAAiB,GAAG,IAAI,CAAC;AAoB5B,wBAAgB,SAAS,CACxB,MAAM,EAAE,gBAAgB,EACxB,KAAK,EAAE,gBAAgB,GACrB,MAAM,CAOR;AAED,sDAAsD;AACtD,wBAAgB,mBAAmB,IAAI,OAAO,CAE7C;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,IAAI,IAAI,CAEtC;AAED,MAAM,MAAM,QAAQ,GAAG;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,YAAY,IAAI,OAAO,CActC;AAED;;;;;;;GAOG;AACH,qBAAa,UAAU;IACtB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA6B;IACtD,OAAO,CAAC,MAAM,CAAK;IACnB,OAAO,CAAC,QAAQ,CAAK;IAErB,YAAY,UAAU,EAAE,OAAO,EAU9B;IAED,IAAI,IAAI,QAAQ,GAAG,IAAI,CAWtB;IAED,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,IAAI,CAEvB;IAED,OAAO,CAAC,OAAO;CAMf;AAED,wBAAgB,OAAO,CACtB,MAAM,EAAE,QAAQ,GAAG,IAAI,EACvB,KAAK,EAAE,QAAQ,GAAG,IAAI,GACpB,QAAQ,GAAG,IAAI,CASjB"}
|
package/dist/_counters.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { PerformanceObserver } from "node:perf_hooks";
|
|
2
2
|
import v8 from "node:v8";
|
|
3
|
+
import { median } from "@ac-kit/math-stats";
|
|
3
4
|
/**
|
|
4
5
|
* Read twice per batch, so it allocates as little as the platform allows:
|
|
5
6
|
* `v8.getHeapStatistics()` is deliberately not called here — it builds the
|
|
@@ -13,8 +14,6 @@ export function readResourceCounters() {
|
|
|
13
14
|
cpuUserUs: cpu.user,
|
|
14
15
|
cpuSystemUs: cpu.system,
|
|
15
16
|
heapUsedBytes: memory.heapUsed,
|
|
16
|
-
externalBytes: memory.external,
|
|
17
|
-
arrayBuffersBytes: memory.arrayBuffers,
|
|
18
17
|
rssBytes: memory.rss,
|
|
19
18
|
};
|
|
20
19
|
}
|
|
@@ -22,21 +21,198 @@ export function readResourceCounters() {
|
|
|
22
21
|
export function readHeapLimitBytes() {
|
|
23
22
|
return v8.getHeapStatistics().heap_size_limit;
|
|
24
23
|
}
|
|
24
|
+
/** External-memory movement within a window below which it is noise. */
|
|
25
|
+
const OFF_HEAP_NOISE_BYTES_ = 4096;
|
|
26
|
+
function offHeapAccounting_(movedBytes) {
|
|
27
|
+
return movedBytes > OFF_HEAP_NOISE_BYTES_ ? "lower-bound" : "unknown";
|
|
28
|
+
}
|
|
29
|
+
const ALLOCATION_SOURCE_ORDER_ = [
|
|
30
|
+
"gc-profiler",
|
|
31
|
+
"v8-total-allocated",
|
|
32
|
+
"heap-growth",
|
|
33
|
+
];
|
|
34
|
+
/** Empty windows run before the calibration is read, so the JIT has settled. */
|
|
35
|
+
const CALIBRATION_WARMUP_WINDOWS_ = 30;
|
|
36
|
+
/** Empty windows whose median is the counter's own cost. */
|
|
37
|
+
const CALIBRATION_WINDOWS_ = 31;
|
|
38
|
+
function createGcProfilerCounter_() {
|
|
39
|
+
if (typeof v8.GCProfiler !== "function") {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
const profiler = new v8.GCProfiler();
|
|
43
|
+
let heapStart = 0;
|
|
44
|
+
let externalStart = 0;
|
|
45
|
+
let offHeap = "unknown";
|
|
46
|
+
const discard = () => {
|
|
47
|
+
try {
|
|
48
|
+
profiler.stop();
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
// Not running.
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
return {
|
|
55
|
+
source: "gc-profiler",
|
|
56
|
+
undercounted: false,
|
|
57
|
+
get offHeap() {
|
|
58
|
+
return offHeap;
|
|
59
|
+
},
|
|
60
|
+
abort: discard,
|
|
61
|
+
begin() {
|
|
62
|
+
// A window that never ended would otherwise carry its collections, and
|
|
63
|
+
// the bytes they freed, into this one.
|
|
64
|
+
discard();
|
|
65
|
+
profiler.start();
|
|
66
|
+
const memory = process.memoryUsage();
|
|
67
|
+
heapStart = memory.heapUsed;
|
|
68
|
+
externalStart = memory.external;
|
|
69
|
+
},
|
|
70
|
+
end() {
|
|
71
|
+
// Read before `stop`, which builds the report: its allocations belong to
|
|
72
|
+
// no window.
|
|
73
|
+
const memory = process.memoryUsage();
|
|
74
|
+
const profile = profiler.stop();
|
|
75
|
+
// Whatever a collection freed was allocated before it ran or was
|
|
76
|
+
// already garbage at `begin`; either way `used` at `begin` counted it,
|
|
77
|
+
// so growth plus the freed bytes is the allocation, to the byte.
|
|
78
|
+
let heapFreed = 0;
|
|
79
|
+
let externalFreed = 0;
|
|
80
|
+
for (const collection of profile.statistics) {
|
|
81
|
+
const before = collection.beforeGC.heapStatistics;
|
|
82
|
+
const after = collection.afterGC.heapStatistics;
|
|
83
|
+
heapFreed += before.usedHeapSize - after.usedHeapSize;
|
|
84
|
+
externalFreed += before.externalMemory - after.externalMemory;
|
|
85
|
+
}
|
|
86
|
+
const externalGrowth = memory.external - externalStart;
|
|
87
|
+
offHeap = offHeapAccounting_(Math.abs(externalGrowth) + Math.abs(externalFreed));
|
|
88
|
+
return (memory.heapUsed -
|
|
89
|
+
heapStart +
|
|
90
|
+
heapFreed +
|
|
91
|
+
Math.max(0, externalGrowth + externalFreed));
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
function createTotalAllocatedCounter_() {
|
|
96
|
+
const first = v8.getHeapStatistics().total_allocated_bytes;
|
|
97
|
+
if (typeof first !== "number") {
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
let totalStart = 0;
|
|
101
|
+
let externalStart = 0;
|
|
102
|
+
let offHeap = "unknown";
|
|
103
|
+
return {
|
|
104
|
+
source: "v8-total-allocated",
|
|
105
|
+
undercounted: false,
|
|
106
|
+
get offHeap() {
|
|
107
|
+
return offHeap;
|
|
108
|
+
},
|
|
109
|
+
abort() { },
|
|
110
|
+
begin() {
|
|
111
|
+
externalStart = process.memoryUsage().external;
|
|
112
|
+
totalStart = v8.getHeapStatistics().total_allocated_bytes;
|
|
113
|
+
},
|
|
114
|
+
end() {
|
|
115
|
+
const total = v8.getHeapStatistics().total_allocated_bytes;
|
|
116
|
+
const external = process.memoryUsage().external - externalStart;
|
|
117
|
+
offHeap = offHeapAccounting_(Math.abs(external));
|
|
118
|
+
return total - totalStart + Math.max(0, external);
|
|
119
|
+
},
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
function createHeapGrowthCounter_() {
|
|
123
|
+
let heapStart = 0;
|
|
124
|
+
let externalStart = 0;
|
|
125
|
+
let undercounted = false;
|
|
126
|
+
let offHeap = "unknown";
|
|
127
|
+
return {
|
|
128
|
+
source: "heap-growth",
|
|
129
|
+
get undercounted() {
|
|
130
|
+
return undercounted;
|
|
131
|
+
},
|
|
132
|
+
get offHeap() {
|
|
133
|
+
return offHeap;
|
|
134
|
+
},
|
|
135
|
+
abort() { },
|
|
136
|
+
begin() {
|
|
137
|
+
undercounted = false;
|
|
138
|
+
const memory = process.memoryUsage();
|
|
139
|
+
heapStart = memory.heapUsed;
|
|
140
|
+
externalStart = memory.external;
|
|
141
|
+
},
|
|
142
|
+
end() {
|
|
143
|
+
const memory = process.memoryUsage();
|
|
144
|
+
const external = memory.external - externalStart;
|
|
145
|
+
const growth = memory.heapUsed - heapStart + external;
|
|
146
|
+
offHeap = offHeapAccounting_(Math.abs(external));
|
|
147
|
+
// A collection mid-window frees more than the window may have allocated.
|
|
148
|
+
undercounted = growth < 0;
|
|
149
|
+
return Math.max(0, growth);
|
|
150
|
+
},
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
function createRawAllocationCounter_(source) {
|
|
154
|
+
try {
|
|
155
|
+
switch (source) {
|
|
156
|
+
case "gc-profiler":
|
|
157
|
+
return createGcProfilerCounter_();
|
|
158
|
+
case "v8-total-allocated":
|
|
159
|
+
return createTotalAllocatedCounter_();
|
|
160
|
+
case "heap-growth":
|
|
161
|
+
return createHeapGrowthCounter_();
|
|
162
|
+
case "browser-heap-growth":
|
|
163
|
+
return null;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
catch {
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
25
170
|
/**
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* Negative when a collection ran mid-batch and freed more than was allocated,
|
|
30
|
-
* which is why {@link forceCollection} is called before a batch rather than
|
|
31
|
-
* during it. Clamped at zero: a batch cannot allocate a negative amount, and
|
|
32
|
-
* reporting one would make a mean meaningless.
|
|
171
|
+
* Wraps a raw counter so a window reports what the case allocated: the bytes
|
|
172
|
+
* the counter allocates itself are measured on empty windows and removed.
|
|
33
173
|
*/
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
(
|
|
38
|
-
|
|
39
|
-
|
|
174
|
+
function calibrate_(raw) {
|
|
175
|
+
for (let window = 0; window < CALIBRATION_WARMUP_WINDOWS_; window++) {
|
|
176
|
+
raw.begin();
|
|
177
|
+
raw.end();
|
|
178
|
+
}
|
|
179
|
+
const costs = [];
|
|
180
|
+
for (let window = 0; window < CALIBRATION_WINDOWS_; window++) {
|
|
181
|
+
raw.begin();
|
|
182
|
+
costs.push(raw.end());
|
|
183
|
+
}
|
|
184
|
+
// The median, because a collection that lands in a calibration window adds
|
|
185
|
+
// megabytes to that one reading.
|
|
186
|
+
const costBytes = median(costs);
|
|
187
|
+
return {
|
|
188
|
+
source: raw.source,
|
|
189
|
+
get undercounted() {
|
|
190
|
+
return raw.undercounted;
|
|
191
|
+
},
|
|
192
|
+
get offHeap() {
|
|
193
|
+
return raw.offHeap;
|
|
194
|
+
},
|
|
195
|
+
begin: () => raw.begin(),
|
|
196
|
+
abort: () => raw.abort(),
|
|
197
|
+
// Clamped: a window cannot allocate a negative amount, and a mean over
|
|
198
|
+
// batches would be meaningless with one.
|
|
199
|
+
end: () => Math.max(0, raw.end() - costBytes),
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
export function selectAllocationCounter(sources = ALLOCATION_SOURCE_ORDER_) {
|
|
203
|
+
for (const source of sources) {
|
|
204
|
+
const raw = createRawAllocationCounter_(source);
|
|
205
|
+
if (raw === null) {
|
|
206
|
+
continue;
|
|
207
|
+
}
|
|
208
|
+
try {
|
|
209
|
+
return calibrate_(raw);
|
|
210
|
+
}
|
|
211
|
+
catch {
|
|
212
|
+
continue;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
return null;
|
|
40
216
|
}
|
|
41
217
|
export function cpuTimeMs(before, after) {
|
|
42
218
|
return ((after.cpuUserUs -
|
package/dist/_counters.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_counters.js","sourceRoot":"","sources":["../src/_counters.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"_counters.js","sourceRoot":"","sources":["../src/_counters.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,MAAM,SAAS,CAAC;AAEzB,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAU5C;;;;;GAKG;AACH,MAAM,UAAU,oBAAoB;IACnC,MAAM,GAAG,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;IAC/B,MAAM,MAAM,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IAErC,OAAO;QACN,SAAS,EAAE,GAAG,CAAC,IAAI;QACnB,WAAW,EAAE,GAAG,CAAC,MAAM;QACvB,aAAa,EAAE,MAAM,CAAC,QAAQ;QAC9B,QAAQ,EAAE,MAAM,CAAC,GAAG;KACpB,CAAC;AACH,CAAC;AAED,uEAAuE;AACvE,MAAM,UAAU,kBAAkB;IACjC,OAAO,EAAE,CAAC,iBAAiB,EAAE,CAAC,eAAe,CAAC;AAC/C,CAAC;AA+ED,wEAAwE;AACxE,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mE;QACnE,2DAA2D;QAC3D,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC,CAAC;QAE1C,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC;IACvD,CAAC;IAED,CAAC,MAAM,CAAC,OAAO,CAAC;QACf,IAAI,CAAC,QAAQ,EAAE,UAAU,EAAE,CAAC;IAC7B,CAAC;IAEO,OAAO,CAAC,OAAoC;QACnD,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,OAAO,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC;YACrD,IAAI,CAAC,MAAM,EAAE,CAAC;YACd,IAAI,CAAC,QAAQ,IAAI,OAAO,CAAC,KAAK,CAAE,CAAC,QAAQ,CAAC;QAC3C,CAAC;IACF,CAAC;CACD;AAED,MAAM,UAAU,OAAO,CACtB,MAAuB,EACvB,KAAsB;IAEtB,IAAI,MAAM,KAAK,IAAI,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QACvC,OAAO,IAAI,CAAC;IACb,CAAC;IAED,OAAO;QACN,KAAK,EAAE,KAAK,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK;QACjC,OAAO,EAAE,KAAK,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO;KACvC,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { GateMetricSpec } from "@ac-bench/core/plugin";
|
|
2
|
+
import type { ResourceBenchRunCaseResult } from "./_types.js";
|
|
3
|
+
/**
|
|
4
|
+
* The gate metrics of resource.
|
|
5
|
+
*
|
|
6
|
+
* `retainedBytes` is not here: no result carries heap growth after a forced
|
|
7
|
+
* collection yet.
|
|
8
|
+
*/
|
|
9
|
+
export declare const resourceGateMetrics: readonly GateMetricSpec<ResourceBenchRunCaseResult>[];
|
|
10
|
+
//# sourceMappingURL=_gate-metrics.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_gate-metrics.d.ts","sourceRoot":"","sources":["../src/_gate-metrics.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAG5D,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAC;AAK9D;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,EAAE,SAAS,cAAc,CAAC,0BAA0B,CAAC,EAoEnF,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { BYTE, MILLISECOND } from "@ac-kit/model-dataset";
|
|
2
|
+
/** Smallest CPU time step the process reports: one microsecond. */
|
|
3
|
+
const CPU_QUANTUM_MS_ = 0.001;
|
|
4
|
+
/**
|
|
5
|
+
* The gate metrics of resource.
|
|
6
|
+
*
|
|
7
|
+
* `retainedBytes` is not here: no result carries heap growth after a forced
|
|
8
|
+
* collection yet.
|
|
9
|
+
*/
|
|
10
|
+
export const resourceGateMetrics = [
|
|
11
|
+
{
|
|
12
|
+
name: "allocatedBytes",
|
|
13
|
+
title: "allocated bytes per operation",
|
|
14
|
+
unit: BYTE,
|
|
15
|
+
direction: "lower-is-better",
|
|
16
|
+
scale: "linear",
|
|
17
|
+
observe: (result) => {
|
|
18
|
+
const statistics = result.statistics;
|
|
19
|
+
if (statistics === null) {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
// A batch counts whole bytes, so the median per operation cannot be
|
|
23
|
+
// resolved below one byte over the batch's operations.
|
|
24
|
+
const operationsPerBatch = Math.max(1, statistics.operations / Math.max(1, statistics.samples));
|
|
25
|
+
const variance = Math.max(statistics.allocatedBytesMedianVariance, 1 / operationsPerBatch ** 2 / 12);
|
|
26
|
+
return {
|
|
27
|
+
value: statistics.allocatedBytes,
|
|
28
|
+
variance,
|
|
29
|
+
dispersion: null,
|
|
30
|
+
samples: statistics.samples,
|
|
31
|
+
};
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
name: "cpuTime",
|
|
36
|
+
title: "CPU time per operation",
|
|
37
|
+
unit: MILLISECOND,
|
|
38
|
+
direction: "lower-is-better",
|
|
39
|
+
scale: "log",
|
|
40
|
+
observe: (result) => {
|
|
41
|
+
const statistics = result.statistics;
|
|
42
|
+
if (statistics === null || !(statistics.cpuTimeMs > 0)) {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
const { cpuTimeMs, samples } = statistics;
|
|
46
|
+
const operationsPerBatch = Math.max(1, statistics.operations / Math.max(1, samples));
|
|
47
|
+
const relativeMad = statistics.cpuTimeMsMad / cpuTimeMs;
|
|
48
|
+
const quantisation = (CPU_QUANTUM_MS_ /
|
|
49
|
+
(Math.sqrt(12) * cpuTimeMs * operationsPerBatch)) **
|
|
50
|
+
2 /
|
|
51
|
+
Math.max(1, samples);
|
|
52
|
+
// The median's variance on the log scale the metric is tested on:
|
|
53
|
+
// `Var(ln m) ≈ Var(m) / m²` (the delta method).
|
|
54
|
+
const variance = Math.max(statistics.cpuTimeMsMedianVariance / cpuTimeMs ** 2, quantisation);
|
|
55
|
+
return { value: cpuTimeMs, variance, dispersion: relativeMad, samples };
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
];
|
|
59
|
+
//# sourceMappingURL=_gate-metrics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_gate-metrics.js","sourceRoot":"","sources":["../src/_gate-metrics.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAI1D,mEAAmE;AACnE,MAAM,eAAe,GAAG,KAAK,CAAC;AAE9B;;;;;GAKG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAC/B;IACC;QACC,IAAI,EAAE,gBAAgB;QACtB,KAAK,EAAE,+BAA+B;QACtC,IAAI,EAAE,IAAI;QACV,SAAS,EAAE,iBAAiB;QAC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AW,GAAG,UAAU,CAAC,YAAY,GAAG,SAAS,CAAC;YACxD,MAAM,YAAY,GACjB,CAAC,eAAe;gBACf,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,SAAS,GAAG,kBAAkB,CAAC,CAAC;gBACjD,CAAC;gBACF,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;YACtB,kEAAkE;YAClE,gDAAgD;YAChD,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CACxB,UAAU,CAAC,uBAAuB,GAAG,SAAS,IAAI,CAAC,EACnD,YAAY,CACZ,CAAC;YAEF,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,UAAU,EAAE,WAAW,EAAE,OAAO,EAAE,CAAC;QACzE,CAAC;KACD;CACD,CAAC"}
|
package/dist/_run-case.d.ts
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import { BenchCaseRunContext } from "@ac-bench/core/runner";
|
|
2
2
|
import { MaybeAsyncCallable } from "@ac-kit/core";
|
|
3
|
+
import { AllocationCounter } from "./_counters.js";
|
|
3
4
|
import { ResourceCaseOptions, ResourceConditionOptions } from "./options.js";
|
|
4
5
|
export type ResourceCaseFn = MaybeAsyncCallable<[signal: AbortSignal]>;
|
|
5
6
|
export type RunResourceCaseOptions = ResourceCaseOptions & {
|
|
6
7
|
conditionOptions?: ResourceConditionOptions;
|
|
8
|
+
/** Replaces the process's counter; for tests that force one source. */
|
|
9
|
+
allocationCounter?: AllocationCounter;
|
|
10
|
+
/** Overrides whether collections can be observed; for tests. */
|
|
11
|
+
observeCollections?: boolean;
|
|
7
12
|
};
|
|
8
13
|
export declare function runResourceCase(title: string, fn: ResourceCaseFn, context: BenchCaseRunContext, options?: RunResourceCaseOptions): Promise<void>;
|
|
9
14
|
//# sourceMappingURL=_run-case.d.ts.map
|
package/dist/_run-case.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_run-case.d.ts","sourceRoot":"","sources":["../src/_run-case.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,mBAAmB,
|
|
1
|
+
{"version":3,"file":"_run-case.d.ts","sourceRoot":"","sources":["../src/_run-case.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,mBAAmB,EAMnB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAwB,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAExE,OAAO,EACN,iBAAiB,EAUjB,MAAM,gBAAgB,CAAC;AAIxB,OAAO,EAEN,mBAAmB,EACnB,wBAAwB,EAExB,MAAM,cAAc,CAAC;AAEtB,MAAM,MAAM,cAAc,GAAG,kBAAkB,CAAC,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC;AAEvE,MAAM,MAAM,sBAAsB,GAAG,mBAAmB,GAAG;IAC1D,gBAAgB,CAAC,EAAE,wBAAwB,CAAC;IAE5C,uEAAuE;IACvE,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;IAEtC,gEAAgE;IAChE,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC7B,CAAC;AAsFF,wBAAsB,eAAe,CACpC,KAAK,EAAE,MAAM,EACb,EAAE,EAAE,cAAc,EAClB,OAAO,EAAE,mBAAmB,EAC5B,OAAO,CAAC,EAAE,sBAAsB,GAC9B,OAAO,CAAC,IAAI,CAAC,CAqHf"}
|