in AutoCollection/Performance.ts [50:88]
public enable(isEnabled: boolean, collectionInterval?: number) {
this._isEnabled = isEnabled;
if (this._isEnabled && !this._isInitialized) {
this._isInitialized = true;
}
if (isEnabled) {
if (!this._handle) {
this._lastCpus = os.cpus();
this._lastRequests = {
totalRequestCount: AutoCollectPerformance._totalRequestCount,
totalFailedRequestCount: AutoCollectPerformance._totalFailedRequestCount,
time: +new Date
};
this._lastDependencies = {
totalDependencyCount: AutoCollectPerformance._totalDependencyCount,
totalFailedDependencyCount: AutoCollectPerformance._totalFailedDependencyCount,
time: +new Date
};
this._lastExceptions = {
totalExceptionCount: AutoCollectPerformance._totalExceptionCount,
time: +new Date
};
if (typeof (process as any).cpuUsage === 'function') {
this._lastAppCpuUsage = (process as any).cpuUsage();
}
this._lastHrtime = process.hrtime();
this._collectionInterval = collectionInterval || this._collectionInterval;
this._handle = setInterval(() => this.trackPerformance(), this._collectionInterval);
this._handle.unref(); // Allow the app to terminate even while this loop is going on
}
} else {
if (this._handle) {
clearInterval(this._handle);
this._handle = undefined;
}
}
}