Add process.getHeapStatistics() (#13183)
This commit is contained in:
parent
1b8790aeb2
commit
6ad0a22602
6 changed files with 64 additions and 0 deletions
|
@ -52,6 +52,7 @@ void AtomBindings::BindTo(v8::Isolate* isolate, v8::Local<v8::Object> process) {
|
|||
dict.SetMethod("crash", &AtomBindings::Crash);
|
||||
dict.SetMethod("hang", &Hang);
|
||||
dict.SetMethod("log", &Log);
|
||||
dict.SetMethod("getHeapStatistics", &GetHeapStatistics);
|
||||
dict.SetMethod("getProcessMemoryInfo", &GetProcessMemoryInfo);
|
||||
dict.SetMethod("getSystemMemoryInfo", &GetSystemMemoryInfo);
|
||||
dict.SetMethod("getCPUUsage", base::Bind(&AtomBindings::GetCPUUsage,
|
||||
|
@ -125,6 +126,35 @@ void AtomBindings::Hang() {
|
|||
base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(1));
|
||||
}
|
||||
|
||||
// static
|
||||
v8::Local<v8::Value> AtomBindings::GetHeapStatistics(v8::Isolate* isolate) {
|
||||
v8::HeapStatistics v8_heap_stats;
|
||||
isolate->GetHeapStatistics(&v8_heap_stats);
|
||||
|
||||
mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate);
|
||||
dict.Set("totalHeapSize",
|
||||
static_cast<double>(v8_heap_stats.total_heap_size() >> 10));
|
||||
dict.Set(
|
||||
"totalHeapSizeExecutable",
|
||||
static_cast<double>(v8_heap_stats.total_heap_size_executable() >> 10));
|
||||
dict.Set("totalPhysicalSize",
|
||||
static_cast<double>(v8_heap_stats.total_physical_size() >> 10));
|
||||
dict.Set("totalAvailableSize",
|
||||
static_cast<double>(v8_heap_stats.total_available_size() >> 10));
|
||||
dict.Set("usedHeapSize",
|
||||
static_cast<double>(v8_heap_stats.used_heap_size() >> 10));
|
||||
dict.Set("heapSizeLimit",
|
||||
static_cast<double>(v8_heap_stats.heap_size_limit() >> 10));
|
||||
dict.Set("mallocedMemory",
|
||||
static_cast<double>(v8_heap_stats.malloced_memory() >> 10));
|
||||
dict.Set("peakMallocedMemory",
|
||||
static_cast<double>(v8_heap_stats.peak_malloced_memory() >> 10));
|
||||
dict.Set("doesZapGarbage",
|
||||
static_cast<bool>(v8_heap_stats.does_zap_garbage()));
|
||||
|
||||
return dict.GetHandle();
|
||||
}
|
||||
|
||||
// static
|
||||
v8::Local<v8::Value> AtomBindings::GetProcessMemoryInfo(v8::Isolate* isolate) {
|
||||
std::unique_ptr<base::ProcessMetrics> metrics(
|
||||
|
|
|
@ -35,6 +35,7 @@ class AtomBindings {
|
|||
static void Log(const base::string16& message);
|
||||
static void Crash();
|
||||
static void Hang();
|
||||
static v8::Local<v8::Value> GetHeapStatistics(v8::Isolate* isolate);
|
||||
static v8::Local<v8::Value> GetProcessMemoryInfo(v8::Isolate* isolate);
|
||||
static v8::Local<v8::Value> GetSystemMemoryInfo(v8::Isolate* isolate,
|
||||
mate::Arguments* args);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue