VOOZH about

URL: https://www.geeksforgeeks.org/node-js/node-js-process-cpuusage-method/

⇱ Node.js process.cpuUsage() Method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Node.js process.cpuUsage() Method

Last Updated : 28 Apr, 2025

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:  

  • previous_value: It is an optional parameter, an object returned by the calling process.cpuUsage() previously. If it is passed then the difference is returned.

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. 

  • user: It is an integer that represents the time elapsed by user
  • system: It is an integer represents the time elapsed by system

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
 

Comment

Explore