diff --git a/src/profiler/runtime/clock.ts b/src/profiler/runtime/clock.ts index 97a6f833c..282a95bf1 100644 --- a/src/profiler/runtime/clock.ts +++ b/src/profiler/runtime/clock.ts @@ -1,24 +1,29 @@ import { performance } from "node:perf_hooks"; +interface CpuUsage { + user: number; + system: number; +} + export interface ProfilerClock { /** High-resolution monotonic time in milliseconds. It is suitable for measuring elapsed time. */ now(): number; /** Unix wall-clock timestamp in milliseconds. It is suitable for timestamps shared between processes. */ epochNow(): number; /** Process CPU usage since startup, or since `previousValue` when it is supplied. */ - cpuUsage(previousValue?: NodeJS.CpuUsage): NodeJS.CpuUsage; + cpuUsage(previousValue?: CpuUsage): CpuUsage; /** Current-thread CPU usage since startup, or since `previousValue` when it is supplied. */ - threadCpuUsage?(previousValue?: NodeJS.CpuUsage): NodeJS.CpuUsage; + threadCpuUsage?(previousValue?: CpuUsage): CpuUsage; } export const systemClock: ProfilerClock = { now: () => performance.now(), epochNow: () => Date.now(), - cpuUsage: (previousValue): NodeJS.CpuUsage => process.cpuUsage(previousValue), + cpuUsage: (previousValue): CpuUsage => process.cpuUsage(previousValue), threadCpuUsage: typeof process.threadCpuUsage === "function" - ? (previousValue): NodeJS.CpuUsage => process.threadCpuUsage(previousValue) + ? (previousValue): CpuUsage => process.threadCpuUsage(previousValue) : undefined, }; -export const cpuUsageToMs = (usage: NodeJS.CpuUsage): number => (usage.user + usage.system) / 1000; +export const cpuUsageToMs = (usage: CpuUsage): number => (usage.user + usage.system) / 1000;