diff --git a/atom/browser/api/atom_api_app.cc b/atom/browser/api/atom_api_app.cc index 93cb4fd52a7..ba70191f74c 100644 --- a/atom/browser/api/atom_api_app.cc +++ b/atom/browser/api/atom_api_app.cc @@ -511,7 +511,7 @@ App::App(v8::Isolate* isolate) { base::ProcessId pid = base::GetCurrentProcId(); std::unique_ptr process_metric( new atom::ProcessMetric( - "Browser", + content::PROCESS_TYPE_BROWSER, pid, base::ProcessMetrics::CreateCurrentProcessMetrics())); app_metrics_[pid] = std::move(process_metric); @@ -717,10 +717,7 @@ void App::ChildProcessLaunched(int process_type, base::ProcessHandle handle) { base::ProcessMetrics::CreateProcessMetrics(handle)); #endif std::unique_ptr process_metric( - new atom::ProcessMetric( - content::GetProcessTypeNameInEnglish(process_type), - pid, - std::move(metrics))); + new atom::ProcessMetric(process_type, pid, std::move(metrics))); app_metrics_[pid] = std::move(process_metric); } @@ -1016,7 +1013,8 @@ std::vector App::GetAppMetrics(v8::Isolate* isolate) { process_metric.second->metrics->GetIdleWakeupsPerSecond()); pid_dict.Set("cpu", cpu_dict); pid_dict.Set("pid", process_metric.second->pid); - pid_dict.Set("type", process_metric.second->type); + pid_dict.Set("type", + content::GetProcessTypeNameInEnglish(process_metric.second->type)); result.push_back(pid_dict); } diff --git a/atom/browser/api/atom_api_app.h b/atom/browser/api/atom_api_app.h index 353eba6883c..d68b172a7fa 100644 --- a/atom/browser/api/atom_api_app.h +++ b/atom/browser/api/atom_api_app.h @@ -45,11 +45,11 @@ enum class JumpListResult : int; #endif struct ProcessMetric { - std::string type; + int type; base::ProcessId pid; std::unique_ptr metrics; - ProcessMetric(const std::string& type, + ProcessMetric(int type, base::ProcessId pid, std::unique_ptr metrics) { this->type = type; diff --git a/spec/api-app-spec.js b/spec/api-app-spec.js index 6b0a3ca354b..d2bab22b860 100644 --- a/spec/api-app-spec.js +++ b/spec/api-app-spec.js @@ -538,15 +538,21 @@ describe('app module', function () { it('returns memory and cpu stats of all running electron processes', function () { const appMetrics = app.getAppMetrics() assert.ok(appMetrics.length > 0, 'App memory info object is not > 0') + const types = [] for (const {memory, pid, type, cpu} of appMetrics) { assert.ok(memory.workingSetSize > 0, 'working set size is not > 0') assert.ok(memory.privateBytes > 0, 'private bytes is not > 0') assert.ok(memory.sharedBytes > 0, 'shared bytes is not > 0') assert.ok(pid > 0, 'pid is not > 0') assert.ok(type.length > 0, 'process type is null') + types.push(type) assert.equal(typeof cpu.percentCPUUsage, 'number') assert.equal(typeof cpu.idleWakeupsPerSecond, 'number') } + + assert.ok(types.includes('GPU')) + assert.ok(types.includes('Browser')) + assert.ok(types.includes('Tab')) }) }) })