|
@@ -14,6 +14,7 @@
|
|
|
#include "atom/common/node_includes.h"
|
|
|
#include "base/logging.h"
|
|
|
#include "base/process/process_metrics.h"
|
|
|
+#include "base/sys_info.h"
|
|
|
#include "native_mate/dictionary.h"
|
|
|
|
|
|
namespace atom {
|
|
@@ -23,6 +24,38 @@ 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;
|
|
|
+ const bool got_counters = metrics->GetIOCounters(&io_counters);
|
|
|
+ mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate);
|
|
|
+
|
|
|
+ if (got_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) {
|
|
@@ -52,6 +85,8 @@ void AtomBindings::BindTo(v8::Isolate* isolate,
|
|
|
dict.SetMethod("log", &Log);
|
|
|
dict.SetMethod("getProcessMemoryInfo", &GetProcessMemoryInfo);
|
|
|
dict.SetMethod("getSystemMemoryInfo", &GetSystemMemoryInfo);
|
|
|
+ dict.SetMethod("getCPUUsage", &GetCPUUsage);
|
|
|
+ dict.SetMethod("getIOCounters", &GetIOCounters);
|
|
|
#if defined(OS_POSIX)
|
|
|
dict.SetMethod("setFdLimit", &base::SetFdLimit);
|
|
|
#endif
|