feat: add name to app.getAppMetrics() output (#24359)
This commit is contained in:
parent
25a36a43c1
commit
7fd96cd188
6 changed files with 26 additions and 6 deletions
|
@ -11,6 +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.
|
||||||
|
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.
|
||||||
The time is represented as number of milliseconds since epoch.
|
The time is represented as number of milliseconds since epoch.
|
||||||
|
|
|
@ -790,7 +790,8 @@ 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));
|
||||||
}
|
}
|
||||||
|
|
||||||
void App::BrowserChildProcessHostDisconnected(
|
void App::BrowserChildProcessHostDisconnected(
|
||||||
|
@ -830,7 +831,9 @@ void App::RenderProcessDisconnected(base::ProcessId host_pid) {
|
||||||
ChildProcessDisconnected(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);
|
auto pid = base::GetProcId(handle);
|
||||||
|
|
||||||
#if defined(OS_MACOSX)
|
#if defined(OS_MACOSX)
|
||||||
|
@ -840,7 +843,7 @@ void App::ChildProcessLaunched(int process_type, base::ProcessHandle handle) {
|
||||||
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));
|
process_type, handle, std::move(metrics), name);
|
||||||
}
|
}
|
||||||
|
|
||||||
void App::ChildProcessDisconnected(base::ProcessId pid) {
|
void App::ChildProcessDisconnected(base::ProcessId pid) {
|
||||||
|
@ -1281,6 +1284,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->name.empty()) {
|
||||||
|
pid_dict.Set("name", process_metric.second->name);
|
||||||
|
}
|
||||||
|
|
||||||
#if !defined(OS_LINUX)
|
#if !defined(OS_LINUX)
|
||||||
auto memory_info = process_metric.second->GetMemoryInfo();
|
auto memory_info = process_metric.second->GetMemoryInfo();
|
||||||
|
|
||||||
|
|
|
@ -158,7 +158,9 @@ class App : public ElectronBrowserClient::Delegate,
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void SetAppPath(const base::FilePath& app_path);
|
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 ChildProcessDisconnected(base::ProcessId pid);
|
||||||
|
|
||||||
void SetAppLogsPath(gin_helper::ErrorThrower thrower,
|
void SetAppLogsPath(gin_helper::ErrorThrower thrower,
|
||||||
|
|
|
@ -52,9 +52,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& name) {
|
||||||
this->type = type;
|
this->type = type;
|
||||||
this->metrics = std::move(metrics);
|
this->metrics = std::move(metrics);
|
||||||
|
this->name = name;
|
||||||
|
|
||||||
#if defined(OS_WIN)
|
#if defined(OS_WIN)
|
||||||
HANDLE duplicate_handle = INVALID_HANDLE_VALUE;
|
HANDLE duplicate_handle = INVALID_HANDLE_VALUE;
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#define SHELL_BROWSER_API_PROCESS_METRIC_H_
|
#define SHELL_BROWSER_API_PROCESS_METRIC_H_
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "base/process/process.h"
|
#include "base/process/process.h"
|
||||||
#include "base/process/process_handle.h"
|
#include "base/process/process_handle.h"
|
||||||
|
@ -37,10 +38,12 @@ 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 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& name = std::string());
|
||||||
~ProcessMetric();
|
~ProcessMetric();
|
||||||
|
|
||||||
#if !defined(OS_LINUX)
|
#if !defined(OS_LINUX)
|
||||||
|
|
|
@ -1079,6 +1079,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') {
|
||||||
|
expect(entry).to.have.property('name').that.is.a('string');
|
||||||
|
}
|
||||||
|
|
||||||
if (process.platform === 'win32') {
|
if (process.platform === 'win32') {
|
||||||
expect(entry.memory).to.have.property('privateBytes').that.is.greaterThan(0);
|
expect(entry.memory).to.have.property('privateBytes').that.is.greaterThan(0);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue