fix(core): fix startup stats to use int values for timestamps and durations (#22201)

Co-authored-by: Yuna Seol <yunaseol@google.com>
This commit is contained in:
Yuna Seol
2026-03-12 15:06:12 -04:00
committed by GitHub
parent 8a537d85e9
commit 391715c33c
2 changed files with 34 additions and 4 deletions

View File

@@ -388,5 +388,32 @@ describe('StartupProfiler', () => {
}),
);
});
it('should log startup stats timestamps as rounded integers', () => {
const handle = profiler.start('test_phase');
handle?.end();
profiler.flush(mockConfig);
const statsEvent = logStartupStats.mock.calls[0][1];
const phase = statsEvent.phases[0];
// Verify they are integers
expect(Number.isInteger(phase.start_time_usec)).toBe(true);
expect(Number.isInteger(phase.end_time_usec)).toBe(true);
});
it('should log startup stats duration as rounded integers', () => {
const handle = profiler.start('test_phase');
handle?.end();
profiler.flush(mockConfig);
const statsEvent = logStartupStats.mock.calls[0][1];
const phase = statsEvent.phases[0];
// Verify they are integers
expect(Number.isInteger(phase.duration_ms)).toBe(true);
});
});
});

View File

@@ -207,13 +207,16 @@ export class StartupProfiler {
if (measure && phase.cpuUsage) {
startupPhases.push({
name: phase.name,
duration_ms: measure.duration,
duration_ms: Math.round(measure.duration),
cpu_usage_user_usec: phase.cpuUsage.user,
cpu_usage_system_usec: phase.cpuUsage.system,
start_time_usec: (performance.timeOrigin + measure.startTime) * 1000,
end_time_usec:
start_time_usec: Math.round(
(performance.timeOrigin + measure.startTime) * 1000,
),
end_time_usec: Math.round(
(performance.timeOrigin + measure.startTime + measure.duration) *
1000,
1000,
),
});
}
}