Browse Source

feat: add serviceName to 'child-process-gone' / app.getAppMetrics() (#25975)

Milan Burda 4 years ago
parent
commit
decb1eb87b

+ 1 - 0
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.
 

+ 2 - 1
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.

+ 8 - 2
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<electron::ProcessMetric>(
-      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<gin_helper::Dictionary> 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);
     }

+ 1 - 0
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);
 

+ 2 - 0
shell/browser/api/process_metric.cc

@@ -53,9 +53,11 @@ namespace electron {
 ProcessMetric::ProcessMetric(int type,
                              base::ProcessHandle handle,
                              std::unique_ptr<base::ProcessMetrics> 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)

+ 2 - 0
shell/browser/api/process_metric.h

@@ -38,11 +38,13 @@ struct ProcessMetric {
   int type;
   base::Process process;
   std::unique_ptr<base::ProcessMetrics> metrics;
+  std::string service_name;
   std::string name;
 
   ProcessMetric(int type,
                 base::ProcessHandle handle,
                 std::unique_ptr<base::ProcessMetrics> metrics,
+                const std::string& service_name = std::string(),
                 const std::string& name = std::string());
   ~ProcessMetric();
 

+ 4 - 0
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');
         }