From decb1eb87b394f4fabb8cb16fcd8abc385958bf5 Mon Sep 17 00:00:00 2001 From: Milan Burda Date: Mon, 19 Oct 2020 13:55:47 +0200 Subject: [PATCH] feat: add serviceName to 'child-process-gone' / app.getAppMetrics() (#25975) --- docs/api/app.md | 1 + docs/api/structures/process-metric.md | 3 ++- shell/browser/api/electron_api_app.cc | 10 ++++++++-- shell/browser/api/electron_api_app.h | 1 + shell/browser/api/process_metric.cc | 2 ++ shell/browser/api/process_metric.h | 2 ++ spec-main/api-app-spec.ts | 4 ++++ 7 files changed, 20 insertions(+), 3 deletions(-) diff --git a/docs/api/app.md b/docs/api/app.md index 690af81a142..1e1cf56cd45 100644 --- a/docs/api/app.md +++ b/docs/api/app.md @@ -432,6 +432,7 @@ Returns: * `integrity-failure` - Windows code integrity checks failed * `exitCode` Number - The exit code for the process (e.g. status from waitpid if on posix, from GetExitCodeProcess on Windows). + * `serviceName` String (optional) - The non-localized name of the process. * `name` String (optional) - The name of the process. Examples for utility: `Audio Service`, `Content Decryption Module Service`, `Network Service`, `Video Capture`, etc. diff --git a/docs/api/structures/process-metric.md b/docs/api/structures/process-metric.md index 446051716da..764912bca0f 100644 --- a/docs/api/structures/process-metric.md +++ b/docs/api/structures/process-metric.md @@ -11,7 +11,8 @@ * `Pepper Plugin` * `Pepper Plugin Broker` * `Unknown` -* `name` String (optional) - The name of the process. i.e. for plugins it might be Flash. +* `serviceName` String (optional) - The non-localized name of the process. +* `name` String (optional) - The name of the process. Examples for utility: `Audio Service`, `Content Decryption Module Service`, `Network Service`, `Video Capture`, etc. * `cpu` [CPUUsage](cpu-usage.md) - CPU usage of the process. * `creationTime` Number - Creation time for this process. diff --git a/shell/browser/api/electron_api_app.cc b/shell/browser/api/electron_api_app.cc index e55db8832ad..ea3756dd6d3 100644 --- a/shell/browser/api/electron_api_app.cc +++ b/shell/browser/api/electron_api_app.cc @@ -837,7 +837,7 @@ void App::OnGpuProcessCrashed(base::TerminationStatus status) { void App::BrowserChildProcessLaunchedAndConnected( const content::ChildProcessData& data) { ChildProcessLaunched(data.process_type, data.GetProcess().Handle(), - base::UTF16ToUTF8(data.name)); + data.metrics_name, base::UTF16ToUTF8(data.name)); } void App::BrowserChildProcessHostDisconnected( @@ -868,6 +868,7 @@ void App::BrowserChildProcessCrashedOrKilled( details.Set("type", content::GetProcessTypeNameInEnglish(data.process_type)); details.Set("reason", info.status); details.Set("exitCode", info.exit_code); + details.Set("serviceName", data.metrics_name); if (!data.name.empty()) { details.Set("name", data.name); } @@ -896,6 +897,7 @@ void App::RenderProcessDisconnected(base::ProcessId host_pid) { void App::ChildProcessLaunched(int process_type, base::ProcessHandle handle, + const std::string& service_name, const std::string& name) { auto pid = base::GetProcId(handle); @@ -906,7 +908,7 @@ void App::ChildProcessLaunched(int process_type, auto metrics = base::ProcessMetrics::CreateProcessMetrics(handle); #endif app_metrics_[pid] = std::make_unique( - process_type, handle, std::move(metrics), name); + process_type, handle, std::move(metrics), service_name, name); } void App::ChildProcessDisconnected(base::ProcessId pid) { @@ -1349,6 +1351,10 @@ std::vector App::GetAppMetrics(v8::Isolate* isolate) { pid_dict.Set("creationTime", process_metric.second->process.CreationTime().ToJsTime()); + if (!process_metric.second->service_name.empty()) { + pid_dict.Set("serviceName", process_metric.second->service_name); + } + if (!process_metric.second->name.empty()) { pid_dict.Set("name", process_metric.second->name); } diff --git a/shell/browser/api/electron_api_app.h b/shell/browser/api/electron_api_app.h index ab0ecc66685..10e5961166f 100644 --- a/shell/browser/api/electron_api_app.h +++ b/shell/browser/api/electron_api_app.h @@ -168,6 +168,7 @@ class App : public ElectronBrowserClient::Delegate, void SetAppPath(const base::FilePath& app_path); void ChildProcessLaunched(int process_type, base::ProcessHandle handle, + const std::string& service_name = std::string(), const std::string& name = std::string()); void ChildProcessDisconnected(base::ProcessId pid); diff --git a/shell/browser/api/process_metric.cc b/shell/browser/api/process_metric.cc index c3506e9d605..c327b6cccc8 100644 --- a/shell/browser/api/process_metric.cc +++ b/shell/browser/api/process_metric.cc @@ -53,9 +53,11 @@ namespace electron { ProcessMetric::ProcessMetric(int type, base::ProcessHandle handle, std::unique_ptr metrics, + const std::string& service_name, const std::string& name) { this->type = type; this->metrics = std::move(metrics); + this->service_name = service_name; this->name = name; #if defined(OS_WIN) diff --git a/shell/browser/api/process_metric.h b/shell/browser/api/process_metric.h index 83fd80ded17..e0580c63f32 100644 --- a/shell/browser/api/process_metric.h +++ b/shell/browser/api/process_metric.h @@ -38,11 +38,13 @@ struct ProcessMetric { int type; base::Process process; std::unique_ptr metrics; + std::string service_name; std::string name; ProcessMetric(int type, base::ProcessHandle handle, std::unique_ptr metrics, + const std::string& service_name = std::string(), const std::string& name = std::string()); ~ProcessMetric(); diff --git a/spec-main/api-app-spec.ts b/spec-main/api-app-spec.ts index b2b78d87f2a..4e247c37acf 100644 --- a/spec-main/api-app-spec.ts +++ b/spec-main/api-app-spec.ts @@ -1176,6 +1176,10 @@ describe('app module', () => { expect(entry.memory).to.have.property('workingSetSize').that.is.greaterThan(0); expect(entry.memory).to.have.property('peakWorkingSetSize').that.is.greaterThan(0); + if (entry.type === 'Utility' || entry.type === 'GPU') { + expect(entry.serviceName).to.be.a('string').that.does.not.equal(''); + } + if (entry.type === 'Utility') { expect(entry).to.have.property('name').that.is.a('string'); }