@magield/collectors 0.21.0 → 0.23.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/dist/run.js +8 -0
- package/dist/types.d.ts +8 -0
- package/package.json +1 -1
package/dist/run.js
CHANGED
|
@@ -44,6 +44,8 @@ export async function runCollectors(env, options = {}) {
|
|
|
44
44
|
const signals = {};
|
|
45
45
|
const skipped = [];
|
|
46
46
|
const errors = [];
|
|
47
|
+
const timings = {};
|
|
48
|
+
const waveTimings = {};
|
|
47
49
|
const startedAll = now();
|
|
48
50
|
let expected = 0;
|
|
49
51
|
let obtained = 0;
|
|
@@ -80,6 +82,7 @@ export async function runCollectors(env, options = {}) {
|
|
|
80
82
|
skipped.push(collector.id);
|
|
81
83
|
continue;
|
|
82
84
|
}
|
|
85
|
+
const collectorStarted = now();
|
|
83
86
|
try {
|
|
84
87
|
// Bounded by what is left of the wave, not merely checked before it
|
|
85
88
|
// starts. The budget is "a protected action is never delayed by
|
|
@@ -93,6 +96,7 @@ export async function runCollectors(env, options = {}) {
|
|
|
93
96
|
// hostile-runtime event rather than an exotic one.
|
|
94
97
|
const remaining = budget - (now() - waveStarted);
|
|
95
98
|
const result = await withDeadline(collector.collect(env), remaining);
|
|
99
|
+
timings[collector.id] = Math.round(now() - collectorStarted);
|
|
96
100
|
if (result === TIMED_OUT) {
|
|
97
101
|
skipped.push(collector.id);
|
|
98
102
|
errors.push(`${collector.id}: exceeded the ${wave} budget`);
|
|
@@ -113,10 +117,12 @@ export async function runCollectors(env, options = {}) {
|
|
|
113
117
|
// One broken collector must never cost the whole bundle. Browsers are
|
|
114
118
|
// a hostile runtime: extensions remove APIs, hardening throws on
|
|
115
119
|
// property access, and a page can be closed mid-collection.
|
|
120
|
+
timings[collector.id] = Math.round(now() - collectorStarted);
|
|
116
121
|
skipped.push(collector.id);
|
|
117
122
|
errors.push(`${collector.id}: ${err.message}`);
|
|
118
123
|
}
|
|
119
124
|
}
|
|
125
|
+
waveTimings[wave] = Math.round(now() - waveStarted);
|
|
120
126
|
}
|
|
121
127
|
return {
|
|
122
128
|
signals,
|
|
@@ -124,5 +130,7 @@ export async function runCollectors(env, options = {}) {
|
|
|
124
130
|
skipped,
|
|
125
131
|
errors,
|
|
126
132
|
confidence: expected === 0 ? 0 : Number((obtained / expected).toFixed(3)),
|
|
133
|
+
timings,
|
|
134
|
+
waves: waveTimings,
|
|
127
135
|
};
|
|
128
136
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -51,4 +51,12 @@ export interface CollectionResult {
|
|
|
51
51
|
readonly errors: readonly string[];
|
|
52
52
|
/** 0..1 — how much of the expected signal set was actually obtained. */
|
|
53
53
|
readonly confidence: number;
|
|
54
|
+
/**
|
|
55
|
+
* Milliseconds each collector that ran took, by id, including one that was
|
|
56
|
+
* cut off by its wave's budget (then the time it was waited for). Collectors
|
|
57
|
+
* that were never started are absent.
|
|
58
|
+
*/
|
|
59
|
+
readonly timings?: Readonly<Record<string, number>>;
|
|
60
|
+
/** Milliseconds each wave that ran took, by wave. */
|
|
61
|
+
readonly waves?: Readonly<Partial<Record<Wave, number>>>;
|
|
54
62
|
}
|