Skip to content

Commit c726123

Browse files
committed
refactor: wip
1 parent 96ccaa9 commit c726123

File tree

4 files changed

+12
-28
lines changed

4 files changed

+12
-28
lines changed

packages/utils/docs/profiler.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ The `Profiler` class provides a clean, type-safe API for performance monitoring
4747
utils: { track: 'Utils', color: 'primary' },
4848
core: { track: 'Core', color: 'primary-light' },
4949
},
50-
enabled: true,
5150
});
5251
```
5352

@@ -207,7 +206,6 @@ const profiler = new Profiler({
207206
utils: { track: 'Utils', color: 'primary' },
208207
core: { track: 'Core', color: 'primary-light' },
209208
},
210-
enabled: true,
211209
});
212210

213211
// Simple measurement

packages/utils/src/lib/profiler/profiler-node.unit.test.ts

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
import { MockTraceEventFileSink } from '../../../mocks/sink.mock';
1010
import { subscribeProcessExit } from '../exit-process.js';
1111
import type { PerformanceEntryEncoder } from '../performance-observer.js';
12+
import { ID_PATTERNS } from '../process-id.js';
1213
import type {
1314
ActionTrackEntryPayload,
1415
UserTimingDetail,
@@ -33,10 +34,6 @@ const simpleEncoder: PerformanceEntryEncoder<{ message: string }> = entry => {
3334
return [];
3435
};
3536

36-
// ─────────────────────────────────────────────────────────────
37-
// Helper functions
38-
// ─────────────────────────────────────────────────────────────
39-
4037
const resetEnv = () => {
4138
// eslint-disable-next-line functional/immutable-data
4239
delete process.env.DEBUG;
@@ -192,7 +189,6 @@ describe('NodejsProfiler', () => {
192189
it('should initialize with sink opened when enabled is true', () => {
193190
const profiler = createProfiler({
194191
measureName: 'init-enabled',
195-
enabled: true,
196192
});
197193
expect(profiler.state).toBe('running');
198194
expect(profiler.stats.shardOpen).toBe(true);
@@ -322,7 +318,6 @@ describe('NodejsProfiler', () => {
322318
it('is idempotent for repeated operations', () => {
323319
const profiler = createProfiler({
324320
measureName: 'idempotent-operations',
325-
enabled: true,
326321
});
327322

328323
profiler.setEnabled(true);
@@ -359,7 +354,6 @@ describe('NodejsProfiler', () => {
359354
it('should expose shardPath in stats', () => {
360355
const profiler = createProfiler({
361356
measureName: 'filepath-getter',
362-
enabled: true,
363357
});
364358
// When measureName is provided, it's used as the groupId directory
365359
expect(profiler.stats.shardPath).toContain(
@@ -395,7 +389,6 @@ describe('NodejsProfiler', () => {
395389
it('should perform measurements when enabled', () => {
396390
const profiler = createProfiler({
397391
measureName: 'measurements-enabled',
398-
enabled: true,
399392
});
400393

401394
const result = profiler.measure('test-op', () => 'success');
@@ -424,7 +417,9 @@ describe('NodejsProfiler', () => {
424417
const stats = profiler.stats;
425418
// shardPath uses dynamic shard ID format, so we check it matches the pattern
426419
expect(stats.shardPath).toMatch(
427-
/^tmp\/profiles\/stats-getter\/trace\.\d{8}-\d{6}-\d{3}\.\d+\.\d+\.\d+\.jsonl$/,
420+
new RegExp(
421+
`^tmp/profiles/stats-getter/trace\\.${ID_PATTERNS.INSTANCE_ID.source}\\.jsonl$`,
422+
),
428423
);
429424
expect(stats).toStrictEqual({
430425
profilerState: 'idle',
@@ -454,15 +449,13 @@ describe('NodejsProfiler', () => {
454449
it('flush() should flush when profiler is running', () => {
455450
const profiler = createProfiler({
456451
measureName: 'flush-running',
457-
enabled: true,
458452
});
459453
expect(() => profiler.flush()).not.toThrow();
460454
});
461455

462456
it('should propagate errors from measure work function', () => {
463457
const profiler = createProfiler({
464458
measureName: 'measure-error',
465-
enabled: true,
466459
});
467460

468461
const error = new Error('Test error');
@@ -476,7 +469,6 @@ describe('NodejsProfiler', () => {
476469
it('should propagate errors from measureAsync work function', async () => {
477470
const profiler = createProfiler({
478471
measureName: 'measure-async-error',
479-
enabled: true,
480472
});
481473

482474
const error = new Error('Async test error');
@@ -605,7 +597,6 @@ describe('NodejsProfiler', () => {
605597
process.env.DEBUG = 'true';
606598
const profiler = createProfiler({
607599
measureName: 'debug-no-transition-marker',
608-
enabled: true,
609600
});
610601

611602
performance.clearMarks();
@@ -683,7 +674,6 @@ describe('NodejsProfiler', () => {
683674
it('setEnabled toggles profiler state', () => {
684675
const profiler = createSimpleProfiler({
685676
measureName: 'exit-set-enabled',
686-
enabled: true,
687677
});
688678
expect(profiler.isEnabled()).toBe(true);
689679

@@ -699,7 +689,6 @@ describe('NodejsProfiler', () => {
699689
expect(() =>
700690
createSimpleProfiler({
701691
measureName: 'exit-uncaught-exception',
702-
enabled: true,
703692
}),
704693
).not.toThrow();
705694

@@ -731,7 +720,6 @@ describe('NodejsProfiler', () => {
731720
const handlers = captureExitHandlers();
732721
const profiler = createSimpleProfiler({
733722
measureName: 'exit-unhandled-rejection',
734-
enabled: true,
735723
});
736724
expect(profiler.isEnabled()).toBe(true);
737725

@@ -762,7 +750,6 @@ describe('NodejsProfiler', () => {
762750
const handlers = captureExitHandlers();
763751
const profiler = createSimpleProfiler({
764752
measureName: 'exit-handler-shutdown',
765-
enabled: true,
766753
});
767754
const closeSpy = vi.spyOn(profiler, 'close');
768755
expect(profiler.isEnabled()).toBe(true);

packages/utils/src/lib/profiler/profiler.int.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ describe('Profiler Integration', () => {
1111
tracks: {
1212
utils: { track: 'Utils', color: 'primary' },
1313
},
14-
enabled: true,
1514
});
1615
}
1716

packages/utils/src/lib/profiler/profiler.unit.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ describe('Profiler', () => {
4848
});
4949

5050
it('constructor should use defaults for measure', () => {
51-
const customProfiler = getProfiler({ color: 'secondary', enabled: true });
51+
const customProfiler = getProfiler({ color: 'secondary' });
5252

5353
const result = customProfiler.measure('test-operation', () => 'success');
5454

@@ -147,7 +147,7 @@ describe('Profiler', () => {
147147
});
148148

149149
it('marker should execute without error when enabled', () => {
150-
const enabledProfiler = getProfiler({ enabled: true });
150+
const enabledProfiler = getProfiler();
151151
expect(() => {
152152
enabledProfiler.marker('test-marker', {
153153
color: 'primary',
@@ -175,7 +175,7 @@ describe('Profiler', () => {
175175
it('marker should execute without error when enabled with default color', () => {
176176
performance.clearMarks();
177177

178-
const profilerWithColor = getProfiler({ color: 'primary', enabled: true });
178+
const profilerWithColor = getProfiler({ color: 'primary' });
179179

180180
expect(() => {
181181
profilerWithColor.marker('test-marker-default-color', {
@@ -199,7 +199,7 @@ describe('Profiler', () => {
199199
});
200200

201201
it('marker should execute without error when enabled with no default color', () => {
202-
const profilerNoColor = getProfiler({ enabled: true });
202+
const profilerNoColor = getProfiler();
203203

204204
expect(() => {
205205
profilerNoColor.marker('test-marker-no-color', {
@@ -243,7 +243,7 @@ describe('Profiler', () => {
243243
performance.clearMarks();
244244
performance.clearMeasures();
245245

246-
const enabledProfiler = getProfiler({ enabled: true });
246+
const enabledProfiler = getProfiler();
247247
const workFn = vi.fn(() => 'result');
248248
const result = enabledProfiler.measure('test-event', workFn, {
249249
color: 'primary',
@@ -319,7 +319,7 @@ describe('Profiler', () => {
319319
});
320320

321321
it('measure should propagate errors when enabled and call error callback', () => {
322-
const enabledProfiler = getProfiler({ enabled: true });
322+
const enabledProfiler = getProfiler();
323323
const error = new Error('Enabled test error');
324324
const workFn = vi.fn(() => {
325325
throw error;
@@ -357,7 +357,7 @@ describe('Profiler', () => {
357357
});
358358

359359
it('measureAsync should handle async operations correctly when enabled', async () => {
360-
const enabledProfiler = getProfiler({ enabled: true });
360+
const enabledProfiler = getProfiler();
361361
const workFn = vi.fn(async () => {
362362
await Promise.resolve();
363363
return 'async-result';
@@ -429,7 +429,7 @@ describe('Profiler', () => {
429429
});
430430

431431
it('measureAsync should propagate async errors when enabled and call error callback', async () => {
432-
const enabledProfiler = getProfiler({ enabled: true });
432+
const enabledProfiler = getProfiler();
433433
const error = new Error('Enabled async test error');
434434
const workFn = vi.fn(async () => {
435435
await Promise.resolve();

0 commit comments

Comments
 (0)