chore(core): add location startup diagnostics
This commit is contained in:
parent
fe0c74f4df
commit
8c9b5b7b4e
5 changed files with 191 additions and 62 deletions
27
packages/core/src/observability/event-loop-delay.ts
Normal file
27
packages/core/src/observability/event-loop-delay.ts
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
const ResolutionMs = 20
|
||||
|
||||
export function makeEventLoopDelayMonitor() {
|
||||
const state = {
|
||||
expectedAt: performance.now() + ResolutionMs,
|
||||
maxMs: 0,
|
||||
stoppedAt: undefined as number | undefined,
|
||||
}
|
||||
const timer = setInterval(() => {
|
||||
const now = performance.now()
|
||||
state.maxMs = Math.max(state.maxMs, now - state.expectedAt)
|
||||
state.expectedAt = now + ResolutionMs
|
||||
}, ResolutionMs)
|
||||
timer.unref()
|
||||
|
||||
const maxMs = () => Math.max(0, state.maxMs, (state.stoppedAt ?? performance.now()) - state.expectedAt)
|
||||
return {
|
||||
maxMs,
|
||||
stop: () => {
|
||||
if (state.stoppedAt === undefined) {
|
||||
state.stoppedAt = performance.now()
|
||||
clearInterval(timer)
|
||||
}
|
||||
return maxMs()
|
||||
},
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue