feat: add process.getBlinkMemoryInfo() (#17762)

This commit is contained in:
Milan Burda 2019-05-30 11:50:35 +02:00 committed by Alexey Kuzmin
parent 2dbd2c07e4
commit a1226d75ff
6 changed files with 42 additions and 0 deletions

View file

@ -29,6 +29,7 @@
#include "native_mate/dictionary.h"
#include "services/resource_coordinator/public/cpp/memory_instrumentation/global_memory_dump.h"
#include "services/resource_coordinator/public/cpp/memory_instrumentation/memory_instrumentation.h"
#include "third_party/blink/renderer/platform/heap/process_heap.h" // nogncheck
namespace atom {
@ -68,6 +69,7 @@ void ElectronBindings::BindProcess(v8::Isolate* isolate,
process->SetMethod("log", &Log);
process->SetMethod("getCreationTime", &GetCreationTime);
process->SetMethod("getHeapStatistics", &GetHeapStatistics);
process->SetMethod("getBlinkMemoryInfo", &GetBlinkMemoryInfo);
process->SetMethod("getProcessMemoryInfo", &GetProcessMemoryInfo);
process->SetMethod("getSystemMemoryInfo", &GetSystemMemoryInfo);
process->SetMethod("getSystemVersion",
@ -252,6 +254,21 @@ v8::Local<v8::Promise> ElectronBindings::GetProcessMemoryInfo(
return handle;
}
// static
v8::Local<v8::Value> ElectronBindings::GetBlinkMemoryInfo(
v8::Isolate* isolate) {
auto allocated = blink::ProcessHeap::TotalAllocatedObjectSize();
auto marked = blink::ProcessHeap::TotalMarkedObjectSize();
auto total = blink::ProcessHeap::TotalAllocatedSpace();
mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate);
dict.SetHidden("simple", true);
dict.Set("allocated", static_cast<double>(allocated >> 10));
dict.Set("marked", static_cast<double>(marked >> 10));
dict.Set("total", static_cast<double>(total >> 10));
return dict.GetHandle();
}
// static
void ElectronBindings::DidReceiveMemoryDump(
v8::Global<v8::Context> context,

View file

@ -58,6 +58,7 @@ class ElectronBindings {
static v8::Local<v8::Value> GetSystemMemoryInfo(v8::Isolate* isolate,
mate::Arguments* args);
static v8::Local<v8::Promise> GetProcessMemoryInfo(v8::Isolate* isolate);
static v8::Local<v8::Value> GetBlinkMemoryInfo(v8::Isolate* isolate);
static v8::Local<v8::Value> GetCPUUsage(base::ProcessMetrics* metrics,
v8::Isolate* isolate);
static v8::Local<v8::Value> GetIOCounters(v8::Isolate* isolate);