8000 feat: add serviceName to 'child-process-gone' / app.getAppMetrics() by miniak · Pull Request #25975 · electron/electron · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
10000

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/api/app.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
3 changes: 2 additions & 1 deletion docs/api/structures/process-metric.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 8 additions & 2 deletions shell/browser/api/electron_api_app.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);

Expand All @@ -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) {
Expand Down Expand Up @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions shell/browser/api/electron_api_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 2 additions & 0 deletions shell/browser/api/process_metric.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions shell/browser/api/process_metric.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
4 changes: 4 additions & 0 deletions spec-main/api-app-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down
0