export interface Snapshot { usage : NodeJS . CpuUsage ; time : number ; } interface CpuUsage { user : number ; system : number ; } export function cpuSnapshot ( ) { return { time : microtime ( ) , usage : process . cpuUsage ( ) , } ; } export function snapshotDiff ( curr , last ) { const timeDiff = curr . time - last . time ; return { system : ( curr . usage . system - last . usage . system ) / timeDiff , user : ( curr . usage . user - last . usage . user ) / timeDiff , } ; } function microtime ( ) { const hrTime = process . hrtime ( ) ; return hrTime [ 0 ] * 1000000 + hrTime [ 1 ] / 1000 ; }