Exposing cpu & io counters function similar to mem methods
This commit is contained in:
parent
472dad1ffc
commit
6b51c25820
2 changed files with 35 additions and 31 deletions
|
@ -24,37 +24,6 @@ namespace {
|
|||
// Dummy class type that used for crashing the program.
|
||||
struct DummyClass { bool crash; };
|
||||
|
||||
v8::Local<v8::Value> GetCPUUsage(v8::Isolate* isolate) {
|
||||
std::unique_ptr<base::ProcessMetrics> metrics(
|
||||
base::ProcessMetrics::CreateCurrentProcessMetrics());
|
||||
|
||||
mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate);
|
||||
int processor_count = base::SysInfo::NumberOfProcessors();
|
||||
dict.Set("percentCPUUsage",
|
||||
metrics->GetPlatformIndependentCPUUsage() / processor_count);
|
||||
dict.Set("idleWakeupsPerSecond", metrics->GetIdleWakeupsPerSecond());
|
||||
|
||||
return dict.GetHandle();
|
||||
}
|
||||
|
||||
v8::Local<v8::Value> GetIOCounters(v8::Isolate* isolate) {
|
||||
std::unique_ptr<base::ProcessMetrics> metrics(
|
||||
base::ProcessMetrics::CreateCurrentProcessMetrics());
|
||||
base::IoCounters io_counters;
|
||||
mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate);
|
||||
|
||||
if (metrics->GetIOCounters(&io_counters)) {
|
||||
dict.Set("readOperationCount", io_counters.ReadOperationCount);
|
||||
dict.Set("writeOperationCount", io_counters.WriteOperationCount);
|
||||
dict.Set("otherOperationCount", io_counters.OtherOperationCount);
|
||||
dict.Set("readTransferCount", io_counters.ReadTransferCount);
|
||||
dict.Set("writeTransferCount", io_counters.WriteTransferCount);
|
||||
dict.Set("otherTransferCount", io_counters.OtherTransferCount);
|
||||
}
|
||||
|
||||
return dict.GetHandle();
|
||||
}
|
||||
|
||||
// Called when there is a fatal error in V8, we just crash the process here so
|
||||
// we can get the stack trace.
|
||||
void FatalErrorCallback(const char* location, const char* message) {
|
||||
|
@ -205,4 +174,37 @@ v8::Local<v8::Value> AtomBindings::GetSystemMemoryInfo(v8::Isolate* isolate,
|
|||
return dict.GetHandle();
|
||||
}
|
||||
|
||||
// static
|
||||
v8::Local<v8::Value> AtomBindings::GetCPUUsage(v8::Isolate* isolate) {
|
||||
std::unique_ptr<base::ProcessMetrics> metrics(
|
||||
base::ProcessMetrics::CreateCurrentProcessMetrics());
|
||||
|
||||
mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate);
|
||||
int processor_count = base::SysInfo::NumberOfProcessors();
|
||||
dict.Set("percentCPUUsage",
|
||||
metrics->GetPlatformIndependentCPUUsage() / processor_count);
|
||||
dict.Set("idleWakeupsPerSecond", metrics->GetIdleWakeupsPerSecond());
|
||||
|
||||
return dict.GetHandle();
|
||||
}
|
||||
|
||||
// static
|
||||
v8::Local<v8::Value> AtomBindings::GetIOCounters(v8::Isolate* isolate) {
|
||||
std::unique_ptr<base::ProcessMetrics> metrics(
|
||||
base::ProcessMetrics::CreateCurrentProcessMetrics());
|
||||
base::IoCounters io_counters;
|
||||
mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate);
|
||||
|
||||
if (metrics->GetIOCounters(&io_counters)) {
|
||||
dict.Set("readOperationCount", io_counters.ReadOperationCount);
|
||||
dict.Set("writeOperationCount", io_counters.WriteOperationCount);
|
||||
dict.Set("otherOperationCount", io_counters.OtherOperationCount);
|
||||
dict.Set("readTransferCount", io_counters.ReadTransferCount);
|
||||
dict.Set("writeTransferCount", io_counters.WriteTransferCount);
|
||||
dict.Set("otherTransferCount", io_counters.OtherTransferCount);
|
||||
}
|
||||
|
||||
return dict.GetHandle();
|
||||
}
|
||||
|
||||
} // namespace atom
|
||||
|
|
|
@ -37,6 +37,8 @@ class AtomBindings {
|
|||
static v8::Local<v8::Value> GetProcessMemoryInfo(v8::Isolate* isolate);
|
||||
static v8::Local<v8::Value> GetSystemMemoryInfo(v8::Isolate* isolate,
|
||||
mate::Arguments* args);
|
||||
static v8::Local<v8::Value> GetCPUUsage(v8::Isolate* isolate);
|
||||
static v8::Local<v8::Value> GetIOCounters(v8::Isolate* isolate);
|
||||
|
||||
private:
|
||||
void ActivateUVLoop(v8::Isolate* isolate);
|
||||
|
|
Loading…
Reference in a new issue