3.2 KiB
3.2 KiB
Proposal — Migrate @suaveplan/profiler to genesis
Why
@suaveplan/profiler is the universal-tier runtime performance profiling primitive consumed by downstream observability tooling. The upstream package at /mnt/s/web/suaveplan/packages/universal/profiler/ reached 93.95% test coverage and lacks the genesis enterprise gates (Clock/TimersLike/LoggerLike injection, defineCodes error registry, OTel meter wiring, Zod-validated boundaries, 100/100/100/100 coverage). This change re-lands the package at packages/devtools/tooling/profiler/ with the full feature surface and the genesis enterprise contract.
What
Land @suaveplan/profiler@0.1.0 with the following modules (one per feature folder, 5-files-per-feature):
profiler/—Profilerclass:start/stop/mark/measure/measureAsyncsampler/— periodic metric sampler with injectableClock+TimersLikememory/— heap snapshot capture with injectable capture-fn; leak detectionbottleneck/— hot-path detector + budget-violation findercomparison/— diff two profiles; regression/improvement classifierflamegraph/— flamegraph JSON tree builder + recursive-call collapsereporter/— text formatter + percentile statisticsotel/— OTLP-compatible span exporter (HTTPfetch)error-codes/—PROFILER_CODESviadefineCodes+ProfilerErrortelemetry/— OTel meter for the profiler itself (counter + histogram)types/— sharedProfileEntry/ProfileMark/SamplePoint/etc
Source mapping
| Upstream file | Genesis file | Notes |
|---|---|---|
src/profiler/profiler.ts |
src/profiler/profiler.ts |
Clock+TimersLike injected; Zod options |
src/sampler/sampler.ts |
src/sampler/sampler.ts |
TimersLike.setTimer replaces setInterval |
src/memory/memory-profiler.ts |
src/memory/memory.ts |
Injectable HeapCapture fn replaces global probe |
src/bottleneck/bottleneck-detector.ts |
src/bottleneck/bottleneck.ts |
Same algorithm, renamed file |
src/comparison/profile-comparator.ts |
src/comparison/comparison.ts |
Same algorithm |
src/flamegraph/flamegraph-generator.ts |
src/flamegraph/flamegraph.ts |
Same algorithm |
src/reporter/reporter.ts |
src/reporter/reporter.ts |
Same algorithm |
src/otel/otel-exporter.ts |
src/otel/otel.ts |
fetch is injectable for tests |
src/index.ts |
src/index.ts |
Explicit named re-exports only |
| (none) | src/error-codes/error-codes.ts |
New — required by genesis rule |
| (none) | src/telemetry/telemetry.ts |
New — required by genesis rule |
Deviations from upstream
- Upstream uses
@suaveplan/eventsEventEmitterwith variadic tuple payloads. Genesis@suaveplan/eventsexposesEventBuswith single-payload (emit(type, payload)) — event maps reshaped to single-object payloads. - Upstream calls
Date.now()andsetIntervaldirectly. Genesis injectsClock+TimersLikeper the universal-tier contract. - Upstream has no error-code registry. Genesis adds
PROFILER_CODES/ProfilerError. - Upstream emits no profiler-self-telemetry. Genesis adds a
telemetry/module emitting per-public-call counters + duration histograms. - Boundary validation: every public constructor option object is now Zod-validated.