From 5b09f78bf6a78c45c1c4aad71f61e66f416f6592 Mon Sep 17 00:00:00 2001 From: Paolo Insogna Date: Sat, 18 Jan 2025 08:48:35 +0100 Subject: [PATCH] process: add threadCpuUsage --- doc/api/process.md | 19 ++++ lib/internal/bootstrap/node.js | 1 + lib/internal/process/per_thread.js | 42 +++++++++ src/node_process_methods.cc | 25 ++++++ ...test-process-threadCpuUsage-main-thread.js | 76 ++++++++++++++++ ...t-process-threadCpuUsage-worker-threads.js | 89 +++++++++++++++++++ typings/globals.d.ts | 2 + typings/internalBinding/process.d.ts | 15 ++++ 8 files changed, 269 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 95b35897f9d568..89914610994c63 100644 --- a/doc/api/process.md +++ b/doc/api/process.md @@ -4211,6 +4211,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`