diff --git a/docs/api/structures/cpu-usage.md b/docs/api/structures/cpu-usage.md index 00c267533a1ee..8fa6cb79efe21 100644 --- a/docs/api/structures/cpu-usage.md +++ b/docs/api/structures/cpu-usage.md @@ -2,6 +2,7 @@ * `percentCPUUsage` number - Percentage of CPU used since the last call to getCPUUsage. First call returns 0. +* `cumulativeCPUUsage` number - Total seconds of CPU time used since process startup. * `idleWakeupsPerSecond` number - The number of average idle CPU wakeups per second since the last call to getCPUUsage. First call returns 0. Will always return 0 on Windows. diff --git a/shell/browser/api/electron_api_app.cc b/shell/browser/api/electron_api_app.cc index cad66ef5e8129..dd8928d8c789d 100644 --- a/shell/browser/api/electron_api_app.cc +++ b/shell/browser/api/electron_api_app.cc @@ -1280,6 +1280,7 @@ std::vector App::GetAppMetrics(v8::Isolate* isolate) { std::optional usage = process_metric.second->metrics->GetPlatformIndependentCPUUsage(); cpu_dict.Set("percentCPUUsage", usage.value_or(0) / processor_count); + cpu_dict.Set("cumulativeCPUUsage", process_metric.second->metrics->GetCumulativeCPUUsage().InSecondsF()); #if !BUILDFLAG(IS_WIN) cpu_dict.Set("idleWakeupsPerSecond", diff --git a/shell/common/api/electron_bindings.cc b/shell/common/api/electron_bindings.cc index d0ae770b73272..2cc125879cdf8 100644 --- a/shell/common/api/electron_bindings.cc +++ b/shell/common/api/electron_bindings.cc @@ -280,6 +280,8 @@ v8::Local ElectronBindings::GetCPUUsage( std::optional usage = metrics->GetPlatformIndependentCPUUsage(); dict.Set("percentCPUUsage", usage.value_or(0) / processor_count); + dict.Set("cumulativeCPUUsage", metrics->GetCumulativeCPUUsage().InSecondsF()); + // NB: This will throw NOTIMPLEMENTED() on Windows // For backwards compatibility, we'll return 0 #if !BUILDFLAG(IS_WIN) diff --git a/spec/api-app-spec.ts b/spec/api-app-spec.ts index 4b3f9d185c130..491f1cc859b1e 100644 --- a/spec/api-app-spec.ts +++ b/spec/api-app-spec.ts @@ -1442,6 +1442,7 @@ describe('app module', () => { types.push(entry.type); expect(entry.cpu).to.have.ownProperty('percentCPUUsage').that.is.a('number'); + expect(entry.cpu).to.have.ownProperty('cumulativeCPUUsage').that.is.a('number'); expect(entry.cpu).to.have.ownProperty('idleWakeupsPerSecond').that.is.a('number'); expect(entry.memory).to.have.property('workingSetSize').that.is.greaterThan(0); diff --git a/spec/api-process-spec.ts b/spec/api-process-spec.ts index 909f6f5244de2..3a9a068cee8c3 100644 --- a/spec/api-process-spec.ts +++ b/spec/api-process-spec.ts @@ -26,6 +26,7 @@ describe('process module', () => { it('returns a cpu usage object', async () => { const cpuUsage = await w.webContents.executeJavaScript('process.getCPUUsage()'); expect(cpuUsage.percentCPUUsage).to.be.a('number'); + expect(cpuUsage.cumulativeCPUUsage).to.be.a('number'); expect(cpuUsage.idleWakeupsPerSecond).to.be.a('number'); }); }); @@ -124,6 +125,7 @@ describe('process module', () => { it('returns a cpu usage object', () => { const cpuUsage = process.getCPUUsage(); expect(cpuUsage.percentCPUUsage).to.be.a('number'); + expect(cpuUsage.cumulativeCPUUsage).to.be.a('number'); expect(cpuUsage.idleWakeupsPerSecond).to.be.a('number'); }); });