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

This commit is contained in:
Milan Burda 2020-10-19 13:55:47 +02:00 committed by GitHub
parent c27e5fdbb6
commit decb1eb87b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 20 additions and 3 deletions

View file

@ -432,6 +432,7 @@ Returns:
* `integrity-failure` - Windows code integrity checks failed * `integrity-failure` - Windows code integrity checks failed
* `exitCode` Number - The exit code for the process * `exitCode` Number - The exit code for the process
(e.g. status from waitpid if on posix, from GetExitCodeProcess on Windows). (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. * `name` String (optional) - The name of the process.
Examples for utility: `Audio Service`, `Content Decryption Module Service`, `Network Service`, `Video Capture`, etc. Examples for utility: `Audio Service`, `Content Decryption Module Service`, `Network Service`, `Video Capture`, etc.

View file

@ -11,7 +11,8 @@
* `Pepper Plugin` * `Pepper Plugin`
* `Pepper Plugin Broker` * `Pepper Plugin Broker`
* `Unknown` * `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. Examples for utility: `Audio Service`, `Content Decryption Module Service`, `Network Service`, `Video Capture`, etc.
* `cpu` [CPUUsage](cpu-usage.md) - CPU usage of the process. * `cpu` [CPUUsage](cpu-usage.md) - CPU usage of the process.
* `creationTime` Number - Creation time for this process. * `creationTime` Number - Creation time for this process.

View file

@ -837,7 +837,7 @@ void App::OnGpuProcessCrashed(base::TerminationStatus status) {
void App::BrowserChildProcessLaunchedAndConnected( void App::BrowserChildProcessLaunchedAndConnected(
const content::ChildProcessData& data) { const content::ChildProcessData& data) {
ChildProcessLaunched(data.process_type, data.GetProcess().Handle(), ChildProcessLaunched(data.process_type, data.GetProcess().Handle(),
base::UTF16ToUTF8(data.name)); data.metrics_name, base::UTF16ToUTF8(data.name));
} }
void App::BrowserChildProcessHostDisconnected( void App::BrowserChildProcessHostDisconnected(
@ -868,6 +868,7 @@ void App::BrowserChildProcessCrashedOrKilled(
details.Set("type", content::GetProcessTypeNameInEnglish(data.process_type)); details.Set("type", content::GetProcessTypeNameInEnglish(data.process_type));
details.Set("reason", info.status); details.Set("reason", info.status);
details.Set("exitCode", info.exit_code); details.Set("exitCode", info.exit_code);
details.Set("serviceName", data.metrics_name);
if (!data.name.empty()) { if (!data.name.empty()) {
details.Set("name", data.name); details.Set("name", data.name);
} }
@ -896,6 +897,7 @@ void App::RenderProcessDisconnected(base::ProcessId host_pid) {
void App::ChildProcessLaunched(int process_type, void App::ChildProcessLaunched(int process_type,
base::ProcessHandle handle, base::ProcessHandle handle,
const std::string& service_name,
const std::string& name) { const std::string& name) {
auto pid = base::GetProcId(handle); auto pid = base::GetProcId(handle);
@ -906,7 +908,7 @@ void App::ChildProcessLaunched(int process_type,
auto metrics = base::ProcessMetrics::CreateProcessMetrics(handle); auto metrics = base::ProcessMetrics::CreateProcessMetrics(handle);
#endif #endif
app_metrics_[pid] = std::make_unique<electron::ProcessMetric>( 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) { void App::ChildProcessDisconnected(base::ProcessId pid) {
@ -1349,6 +1351,10 @@ std::vector<gin_helper::Dictionary> App::GetAppMetrics(v8::Isolate* isolate) {
pid_dict.Set("creationTime", pid_dict.Set("creationTime",
process_metric.second->process.CreationTime().ToJsTime()); 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()) { if (!process_metric.second->name.empty()) {
pid_dict.Set("name", process_metric.second->name); pid_dict.Set("name", process_metric.second->name);
} }

View file

@ -168,6 +168,7 @@ class App : public ElectronBrowserClient::Delegate,
void SetAppPath(const base::FilePath& app_path); void SetAppPath(const base::FilePath& app_path);
void ChildProcessLaunched(int process_type, void ChildProcessLaunched(int process_type,
base::ProcessHandle handle, base::ProcessHandle handle,
const std::string& service_name = std::string(),
const std::string& name = std::string()); const std::string& name = std::string());
void ChildProcessDisconnected(base::ProcessId pid); void ChildProcessDisconnected(base::ProcessId pid);

View file

@ -53,9 +53,11 @@ namespace electron {
ProcessMetric::ProcessMetric(int type, ProcessMetric::ProcessMetric(int type,
base::ProcessHandle handle, base::ProcessHandle handle,
std::unique_ptr<base::ProcessMetrics> metrics, std::unique_ptr<base::ProcessMetrics> metrics,
const std::string& service_name,
const std::string& name) { const std::string& name) {
this->type = type; this->type = type;
this->metrics = std::move(metrics); this->metrics = std::move(metrics);
this->service_name = service_name;
this->name = name; this->name = name;
#if defined(OS_WIN) #if defined(OS_WIN)

View file

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

View file

@ -1176,6 +1176,10 @@ describe('app module', () => {
expect(entry.memory).to.have.property('workingSetSize').that.is.greaterThan(0); expect(entry.memory).to.have.property('workingSetSize').that.is.greaterThan(0);
expect(entry.memory).to.have.property('peakWorkingSetSize').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') { if (entry.type === 'Utility') {
expect(entry).to.have.property('name').that.is.a('string'); expect(entry).to.have.property('name').that.is.a('string');
} }