X Tutup
Skip to content

Commit decb1eb

Browse files
authored
feat: add serviceName to 'child-process-gone' / app.getAppMetrics() (electron#25975)
1 parent c27e5fd commit decb1eb

File tree

7 files changed

+20
-3
lines changed

7 files changed

+20
-3
lines changed

docs/api/app.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ Returns:
432432
* `integrity-failure` - Windows code integrity checks failed
433433
* `exitCode` Number - The exit code for the process
434434
(e.g. status from waitpid if on posix, from GetExitCodeProcess on Windows).
435+
* `serviceName` String (optional) - The non-localized name of the process.
435436
* `name` String (optional) - The name of the process.
436437
Examples for utility: `Audio Service`, `Content Decryption Module Service`, `Network Service`, `Video Capture`, etc.
437438

docs/api/structures/process-metric.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
* `Pepper Plugin`
1212
* `Pepper Plugin Broker`
1313
* `Unknown`
14-
* `name` String (optional) - The name of the process. i.e. for plugins it might be Flash.
14+
* `serviceName` String (optional) - The non-localized name of the process.
15+
* `name` String (optional) - The name of the process.
1516
Examples for utility: `Audio Service`, `Content Decryption Module Service`, `Network Service`, `Video Capture`, etc.
1617
* `cpu` [CPUUsage](cpu-usage.md) - CPU usage of the process.
1718
* `creationTime` Number - Creation time for this process.

shell/browser/api/electron_api_app.cc

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,7 @@ void App::OnGpuProcessCrashed(base::TerminationStatus status) {
837837
void App::BrowserChildProcessLaunchedAndConnected(
838838
const content::ChildProcessData& data) {
839839
ChildProcessLaunched(data.process_type, data.GetProcess().Handle(),
840-
base::UTF16ToUTF8(data.name));
840+
data.metrics_name, base::UTF16ToUTF8(data.name));
841841
}
842842

843843
void App::BrowserChildProcessHostDisconnected(
@@ -868,6 +868,7 @@ void App::BrowserChildProcessCrashedOrKilled(
868868
details.Set("type", content::GetProcessTypeNameInEnglish(data.process_type));
869869
details.Set("reason", info.status);
870870
details.Set("exitCode", info.exit_code);
871+
details.Set("serviceName", data.metrics_name);
871872
if (!data.name.empty()) {
872873
details.Set("name", data.name);
873874
}
@@ -896,6 +897,7 @@ void App::RenderProcessDisconnected(base::ProcessId host_pid) {
896897

897898
void App::ChildProcessLaunched(int process_type,
898899
base::ProcessHandle handle,
900+
const std::string& service_name,
899901
const std::string& name) {
900902
auto pid = base::GetProcId(handle);
901903

@@ -906,7 +908,7 @@ void App::ChildProcessLaunched(int process_type,
906908
auto metrics = base::ProcessMetrics::CreateProcessMetrics(handle);
907909
#endif
908910
app_metrics_[pid] = std::make_unique<electron::ProcessMetric>(
909-
process_type, handle, std::move(metrics), name);
911+
process_type, handle, std::move(metrics), service_name, name);
910912
}
911913

912914
void App::ChildProcessDisconnected(base::ProcessId pid) {
@@ -1349,6 +1351,10 @@ std::vector<gin_helper::Dictionary> App::GetAppMetrics(v8::Isolate* isolate) {
13491351
pid_dict.Set("creationTime",
13501352
process_metric.second->process.CreationTime().ToJsTime());
13511353

1354+
if (!process_metric.second->service_name.empty()) {
1355+
pid_dict.Set("serviceName", process_metric.second->service_name);
1356+
}
1357+
13521358
if (!process_metric.second->name.empty()) {
13531359
pid_dict.Set("name", process_metric.second->name);
13541360
}

shell/browser/api/electron_api_app.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ class App : public ElectronBrowserClient::Delegate,
168168
void SetAppPath(const base::FilePath& app_path);
169169
void ChildProcessLaunched(int process_type,
170170
base::ProcessHandle handle,
171+
const std::string& service_name = std::string(),
171172
const std::string& name = std::string());
172173
void ChildProcessDisconnected(base::ProcessId pid);
173174

shell/browser/api/process_metric.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,11 @@ namespace electron {
5353
ProcessMetric::ProcessMetric(int type,
5454
base::ProcessHandle handle,
5555
std::unique_ptr<base::ProcessMetrics> metrics,
56+
const std::string& service_name,
5657
const std::string& name) {
5758
this->type = type;
5859
this->metrics = std::move(metrics);
60+
this->service_name = service_name;
5961
this->name = name;
6062

6163
#if defined(OS_WIN)

shell/browser/api/process_metric.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,13 @@ struct ProcessMetric {
3838
int type;
3939
base::Process process;
4040
std::unique_ptr<base::ProcessMetrics> metrics;
41+
std::string service_name;
4142
std::string name;
4243

4344
ProcessMetric(int type,
4445
base::ProcessHandle handle,
4546
std::unique_ptr<base::ProcessMetrics> metrics,
47+
const std::string& service_name = std::string(),
4648
const std::string& name = std::string());
4749
~ProcessMetric();
4850

spec-main/api-app-spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,6 +1176,10 @@ describe('app module', () => {
11761176
expect(entry.memory).to.have.property('workingSetSize').that.is.greaterThan(0);
11771177
expect(entry.memory).to.have.property('peakWorkingSetSize').that.is.greaterThan(0);
11781178

1179+
if (entry.type === 'Utility' || entry.type === 'GPU') {
1180+
expect(entry.serviceName).to.be.a('string').that.does.not.equal('');
1181+
}
1182+
11791183
if (entry.type === 'Utility') {
11801184
expect(entry).to.have.property('name').that.is.a('string');
11811185
}

0 commit comments

Comments
 (0)
X Tutup