![]() |
VOOZH | about |
The process.cpuUsage() method is an inbuilt application programming interface of the Process module which is used to get the user, system CPU time usage of the current process. It is returned as an object with property user and system, values are in microseconds. Return values may differ from the actual time elapsed especially for multi-core CPUs.
Syntax:
process.cpuUsage( previous_value )
Parameters: This method accepts a single parameter as mentioned above and described below:
Return: This method returns an object on success, which contains properties like user and system, with some integer value that signifies time elapsed by the process, measured in microseconds.
Below examples illustrate the use of process.cpuUsage() method in Node.js:
Example 1:
Output:
{ user: 78000, system: 15000 }
Example 2:
Output:
cpu usage before: { user: 62000, system: 15000 }
Cpu usage by this process: { user: 109000, system: 0 }
Reference: https://nodejs.org/api/process.html#process_process_cpuusage_previousvalue