From 5791d36d88473ca55b32f93c78bde40d8c874de8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gon=C3=A7alo=20Rica=20Pais=20da=20Silva?= Date: Fri, 13 Dec 2024 17:58:49 +0100 Subject: [PATCH] [ObsUX][Synthtrace] Remove `pidusage` for logging cpu usage (#204043) ## Summary Removes `pidusage` in favour of just getting cpu usage stats from `node:process` for logging purposes. Other than that, not sure the point of logging this, but keeping it in case it serves some purpose. Closes #203983 ## How to test Not sure, make sure CI doesn't break or something from its removal, given it is only used for logging. --- package.json | 2 -- .../src/cli/utils/synthtrace_worker.ts | 11 ++++++++--- yarn.lock | 12 ------------ 3 files changed, 8 insertions(+), 17 deletions(-) diff --git a/package.json b/package.json index 57beea6859b5a..b00039fbf3c04 100644 --- a/package.json +++ b/package.json @@ -1635,7 +1635,6 @@ "@types/pbf": "3.0.2", "@types/pdfmake": "^0.2.2", "@types/picomatch": "^2.3.0", - "@types/pidusage": "^2.0.2", "@types/pixelmatch": "^5.2.4", "@types/pngjs": "^6.0.5", "@types/prop-types": "^15.7.5", @@ -1807,7 +1806,6 @@ "p-reflect": "2.1.0", "peggy": "^1.2.0", "picomatch": "^2.3.1", - "pidusage": "^3.0.2", "pirates": "^4.0.1", "piscina": "^3.2.0", "pixelmatch": "^5.3.0", diff --git a/packages/kbn-apm-synthtrace/src/cli/utils/synthtrace_worker.ts b/packages/kbn-apm-synthtrace/src/cli/utils/synthtrace_worker.ts index 72644bd8f1103..0d5398f473cb2 100644 --- a/packages/kbn-apm-synthtrace/src/cli/utils/synthtrace_worker.ts +++ b/packages/kbn-apm-synthtrace/src/cli/utils/synthtrace_worker.ts @@ -9,7 +9,6 @@ import { timerange } from '@kbn/apm-synthtrace-client'; import { castArray } from 'lodash'; -import pidusage from 'pidusage'; import { memoryUsage } from 'process'; import { parentPort, workerData } from 'worker_threads'; import { getApmEsClient } from './get_apm_es_client'; @@ -123,10 +122,16 @@ async function start() { return Math.round(value / 1024 ** 2).toString() + 'mb'; } + let cpuUsage = process.cpuUsage(); + setInterval(async () => { - const stats = await pidusage(process.pid); + cpuUsage = process.cpuUsage(cpuUsage); const mem = memoryUsage(); - logger.info(`cpu: ${stats.cpu}, memory: ${mb(mem.heapUsed)}/${mb(mem.heapTotal)}`); + logger.info( + `cpu time: (user: ${cpuUsage.user}µs, sys: ${cpuUsage.system}µs), memory: ${mb( + mem.heapUsed + )}/${mb(mem.heapTotal)}` + ); }, 5000); await logger.perf('index_scenario', async () => { diff --git a/yarn.lock b/yarn.lock index 7af5656ccfe69..c2ba4f87ce1f8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -12097,11 +12097,6 @@ resolved "https://registry.yarnpkg.com/@types/picomatch/-/picomatch-2.3.0.tgz#75db5e75a713c5a83d5b76780c3da84a82806003" integrity sha512-O397rnSS9iQI4OirieAtsDqvCj4+3eY1J+EPdNTKuHuRWIfUoGyzX294o8C4KJYaLqgSrd2o60c5EqCU8Zv02g== -"@types/pidusage@^2.0.2": - version "2.0.2" - resolved "https://registry.yarnpkg.com/@types/pidusage/-/pidusage-2.0.2.tgz#3f8c4b19ba7ea438a733d093661e92b60e5f88ee" - integrity sha512-lHgpGZjXDfjggZDLkgp4zQTYkvXq4S7RxjBjrDcPe1MBU72hESWxubutx8+AM4QkJdRxAhrQyxSA6pzHKJKlsQ== - "@types/pixelmatch@^5.2.4": version "5.2.4" resolved "https://registry.yarnpkg.com/@types/pixelmatch/-/pixelmatch-5.2.4.tgz#ca145cc5ede1388c71c68edf2d1f5190e5ddd0f6" @@ -26284,13 +26279,6 @@ picomatch@^4.0.2: resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-4.0.2.tgz#77c742931e8f3b8820946c76cd0c1f13730d1dab" integrity sha512-M7BAV6Rlcy5u+m6oPhAPFgJTzAioX/6B0DxyvDlo9l8+T3nLKbrczg2WLUyzd45L8RqfUMyGPzekbMvX2Ldkwg== -pidusage@^3.0.2: - version "3.0.2" - resolved "https://registry.yarnpkg.com/pidusage/-/pidusage-3.0.2.tgz#6faa5402b2530b3af2cf93d13bcf202889724a53" - integrity sha512-g0VU+y08pKw5M8EZ2rIGiEBaB8wrQMjYGFfW2QVIfyT8V+fq8YFLkvlz4bz5ljvFDJYNFCWT3PWqcRr2FKO81w== - dependencies: - safe-buffer "^5.2.1" - pify@^2.0.0, pify@^2.2.0: version "2.3.0" resolved "https://registry.yarnpkg.com/pify/-/pify-2.3.0.tgz#ed141a6ac043a849ea588498e7dca8b15330e90c"