From 0236fbf75a54eeb03ac7c2fc15130a04164eed92 Mon Sep 17 00:00:00 2001 From: Paolo Insogna Date: Fri, 21 Feb 2025 15:14:02 +0100 Subject: [PATCH] process: add threadCpuUsage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/56467 Reviewed-By: Matteo Collina Reviewed-By: Juan José Arboleda Reviewed-By: James M Snell --- doc/api/process.md | 19 ++++ lib/internal/bootstrap/node.js | 1 + lib/internal/process/per_thread.js | 47 ++++++++++ src/node_process_methods.cc | 25 +++++ ...test-process-threadCpuUsage-main-thread.js | 87 ++++++++++++++++++ ...t-process-threadCpuUsage-worker-threads.js | 91 +++++++++++++++++++ typings/globals.d.ts | 2 + typings/internalBinding/process.d.ts | 15 +++ 8 files changed, 287 insertions(+) create mode 100644 test/parallel/test-process-threadCpuUsage-main-thread.js create mode 100644 test/parallel/test-process-threadCpuUsage-worker-threads.js create mode 100644 typings/internalBinding/process.d.ts diff --git a/doc/api/process.md b/doc/api/process.md index 5d3a1f2d214c83..a58d7cc03cfff0 100644 --- a/doc/api/process.md +++ b/doc/api/process.md @@ -4204,6 +4204,25 @@ Thrown: [DeprecationWarning: test] { name: 'DeprecationWarning' } ``` +## `process.threadCpuUsage([previousValue])` + + + +* `previousValue` {Object} A previous return value from calling + `process.cpuUsage()` +* Returns: {Object} + * `user` {integer} + * `system` {integer} + +The `process.threadCpuUsage()` method returns the user and system CPU time usage of +the current worker thread, in an object with properties `user` and `system`, whose +values are microsecond values (millionth of a second). + +The result of a previous call to `process.threadCpuUsage()` can be passed as the +argument to the function, to get a diff reading. + ## `process.title`