Store process type as int

This commit is contained in:
Kevin Sawicki 2017-05-26 08:53:26 -07:00
parent cabcd0ef8f
commit 1e4dd9b163
3 changed files with 12 additions and 8 deletions

View file

@ -511,7 +511,7 @@ App::App(v8::Isolate* isolate) {
base::ProcessId pid = base::GetCurrentProcId();
std::unique_ptr<atom::ProcessMetric> process_metric(
new atom::ProcessMetric(
"Browser",
content::PROCESS_TYPE_BROWSER,
pid,
base::ProcessMetrics::CreateCurrentProcessMetrics()));
app_metrics_[pid] = std::move(process_metric);
@ -717,10 +717,7 @@ void App::ChildProcessLaunched(int process_type, base::ProcessHandle handle) {
base::ProcessMetrics::CreateProcessMetrics(handle));
#endif
std::unique_ptr<atom::ProcessMetric> process_metric(
new atom::ProcessMetric(
content::GetProcessTypeNameInEnglish(process_type),
pid,
std::move(metrics)));
new atom::ProcessMetric(process_type, pid, std::move(metrics)));
app_metrics_[pid] = std::move(process_metric);
}
@ -1016,7 +1013,8 @@ std::vector<mate::Dictionary> App::GetAppMetrics(v8::Isolate* isolate) {
process_metric.second->metrics->GetIdleWakeupsPerSecond());
pid_dict.Set("cpu", cpu_dict);
pid_dict.Set("pid", process_metric.second->pid);
pid_dict.Set("type", process_metric.second->type);
pid_dict.Set("type",
content::GetProcessTypeNameInEnglish(process_metric.second->type));
result.push_back(pid_dict);
}

View file

@ -45,11 +45,11 @@ enum class JumpListResult : int;
#endif
struct ProcessMetric {
std::string type;
int type;
base::ProcessId pid;
std::unique_ptr<base::ProcessMetrics> metrics;
ProcessMetric(const std::string& type,
ProcessMetric(int type,
base::ProcessId pid,
std::unique_ptr<base::ProcessMetrics> metrics) {
this->type = type;

View file

@ -538,15 +538,21 @@ describe('app module', function () {
it('returns memory and cpu stats of all running electron processes', function () {
const appMetrics = app.getAppMetrics()
assert.ok(appMetrics.length > 0, 'App memory info object is not > 0')
const types = []
for (const {memory, pid, type, cpu} of appMetrics) {
assert.ok(memory.workingSetSize > 0, 'working set size is not > 0')
assert.ok(memory.privateBytes > 0, 'private bytes is not > 0')
assert.ok(memory.sharedBytes > 0, 'shared bytes is not > 0')
assert.ok(pid > 0, 'pid is not > 0')
assert.ok(type.length > 0, 'process type is null')
types.push(type)
assert.equal(typeof cpu.percentCPUUsage, 'number')
assert.equal(typeof cpu.idleWakeupsPerSecond, 'number')
}
assert.ok(types.includes('GPU'))
assert.ok(types.includes('Browser'))
assert.ok(types.includes('Tab'))
})
})
})