feat: add name to app.getAppMetrics() output (#24359)

This commit is contained in:
Milan Burda 2020-07-07 20:00:45 +02:00 committed by GitHub
parent 25a36a43c1
commit 7fd96cd188
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 26 additions and 6 deletions

View file

@ -11,6 +11,8 @@
* `Pepper Plugin`
* `Pepper Plugin Broker`
* `Unknown`
* `name` String (optional) - The name of the process. i.e. for plugins it might be Flash.
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.
The time is represented as number of milliseconds since epoch.

View file

@ -790,7 +790,8 @@ void App::OnGpuProcessCrashed(base::TerminationStatus status) {
void App::BrowserChildProcessLaunchedAndConnected(
const content::ChildProcessData& data) {
ChildProcessLaunched(data.process_type, data.GetProcess().Handle());
ChildProcessLaunched(data.process_type, data.GetProcess().Handle(),
base::UTF16ToUTF8(data.name));
}
void App::BrowserChildProcessHostDisconnected(
@ -830,7 +831,9 @@ void App::RenderProcessDisconnected(base::ProcessId host_pid) {
ChildProcessDisconnected(host_pid);
}
void App::ChildProcessLaunched(int process_type, base::ProcessHandle handle) {
void App::ChildProcessLaunched(int process_type,
base::ProcessHandle handle,
const std::string& name) {
auto pid = base::GetProcId(handle);
#if defined(OS_MACOSX)
@ -840,7 +843,7 @@ void App::ChildProcessLaunched(int process_type, base::ProcessHandle handle) {
auto metrics = base::ProcessMetrics::CreateProcessMetrics(handle);
#endif
app_metrics_[pid] = std::make_unique<electron::ProcessMetric>(
process_type, handle, std::move(metrics));
process_type, handle, std::move(metrics), name);
}
void App::ChildProcessDisconnected(base::ProcessId pid) {
@ -1281,6 +1284,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->name.empty()) {
pid_dict.Set("name", process_metric.second->name);
}
#if !defined(OS_LINUX)
auto memory_info = process_metric.second->GetMemoryInfo();

View file

@ -158,7 +158,9 @@ class App : public ElectronBrowserClient::Delegate,
private:
void SetAppPath(const base::FilePath& app_path);
void ChildProcessLaunched(int process_type, base::ProcessHandle handle);
void ChildProcessLaunched(int process_type,
base::ProcessHandle handle,
const std::string& name = std::string());
void ChildProcessDisconnected(base::ProcessId pid);
void SetAppLogsPath(gin_helper::ErrorThrower thrower,

View file

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

View file

@ -6,6 +6,7 @@
#define SHELL_BROWSER_API_PROCESS_METRIC_H_
#include <memory>
#include <string>
#include "base/process/process.h"
#include "base/process/process_handle.h"
@ -37,10 +38,12 @@ struct ProcessMetric {
int type;
base::Process process;
std::unique_ptr<base::ProcessMetrics> metrics;
std::string name;
ProcessMetric(int type,
base::ProcessHandle handle,
std::unique_ptr<base::ProcessMetrics> metrics);
std::unique_ptr<base::ProcessMetrics> metrics,
const std::string& name = std::string());
~ProcessMetric();
#if !defined(OS_LINUX)

View file

@ -1079,6 +1079,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') {
expect(entry).to.have.property('name').that.is.a('string');
}
if (process.platform === 'win32') {
expect(entry.memory).to.have.property('privateBytes').that.is.greaterThan(0);
}