(
protected config: Config,
statsSource?: MachineStatsSource,
logFn?: (msg: string) => void,
)
| 371 | protected firstSamplePromise: Promise<void>; |
| 372 | |
| 373 | constructor( |
| 374 | protected config: Config, |
| 375 | statsSource?: MachineStatsSource, |
| 376 | logFn?: (msg: string) => void, |
| 377 | ) { |
| 378 | super(); |
| 379 | this.statsSource = |
| 380 | statsSource ?? detectMachineStatsSource(config.getMachineStatsSource()); |
| 381 | const log = logFn ?? ((msg: string) => this.log.info(msg)); |
| 382 | log(`Machine stats source: ${this.statsSource.name}`); |
| 383 | |
| 384 | this.firstSamplePromise = this.sample(); |
| 385 | this.samplerHandle = setInterval(() => { |
| 386 | this.sample(); |
| 387 | }, this.config.getCpuSampleIntervalMs()); |
| 388 | // Don't keep the event loop alive solely for this timer (test runners hang otherwise). |
| 389 | this.samplerHandle.unref(); |
| 390 | } |
| 391 | |
| 392 | protected async sample(): Promise<void> { |
| 393 | const { cpu, memory } = await this.statsSource.read(); |
nothing calls this directly
no test coverage detected