MCPcopy Index your code
hub / github.com/nodejs/node / cpuUsage

Method cpuUsage

lib/internal/worker.js:567–596  ·  view source on GitHub ↗
(prev)

Source from the content-addressed store, hash-verified

565 }
566
567 cpuUsage(prev) {
568 if (prev) {
569 validateObject(prev, 'prev');
570 validateNumber(prev.user, 'prev.user', 0, NumberMAX_SAFE_INTEGER);
571 validateNumber(prev.system, 'prev.system', 0, NumberMAX_SAFE_INTEGER);
572 }
573 if (process.platform === 'sunos') {
574 throw new ERR_OPERATION_FAILED('worker.cpuUsage() is not available on SunOS');
575 }
576 const taker = this[kHandle]?.cpuUsage();
577 return new Promise((resolve, reject) => {
578 if (!taker) return reject(new ERR_WORKER_NOT_RUNNING());
579 taker.ondone = (err, current) => {
580 if (err !== null) {
581 return reject(err);
582 }
583 if (prev) {
584 resolve({
585 user: current.user - prev.user,
586 system: current.system - prev.system,
587 });
588 } else {
589 resolve({
590 user: current.user,
591 system: current.system,
592 });
593 }
594 };
595 });
596 }
597
598 startCpuProfile(options) {
599 normalizeCpuProfileOptions ??=

Callers

nothing calls this directly

Calls 3

cpuUsageMethod · 0.65
rejectFunction · 0.50
resolveFunction · 0.50

Tested by

no test coverage detected