Repository URL to install this package:
|
Version:
0.8.2 ▾
|
// (c) Copyright 2023 Supertenant Ltd. - all rights reserved.
// See LICENSE file in project root for license terms.
"use strict";const DataSource=require("../DataSource");class ProcessDataSource extends DataSource{constructor(refreshDelay){super(refreshDelay),this.previousTimestamp=Date.now(),this.previousCpuUsage=process.cpuUsage()}doRefresh(callback){const currentTimestamp=Date.now();let cpuUsageDiff;cpuUsageDiff=currentTimestamp<=this.previousTimestamp+50?{}:process.cpuUsage(this.previousCpuUsage);const previousTimestamp=this.previousTimestamp;this.previousTimestamp=currentTimestamp,this.previousCpuUsage=process.cpuUsage(),process.nextTick(()=>{callback(null,{cpuUsageDiff:cpuUsageDiff,timeDelta:currentTimestamp-previousTimestamp})})}}module.exports=exports=ProcessDataSource;