Skip to content

Commit

Permalink
Update API data
Browse files Browse the repository at this point in the history
  • Loading branch information
nitsakh committed Oct 15, 2018
1 parent f166585 commit fa62ebd
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 21 deletions.
52 changes: 32 additions & 20 deletions atom/common/api/atom_bindings.cc
Expand Up @@ -27,7 +27,8 @@
#include "services/resource_coordinator/public/cpp/memory_instrumentation/global_memory_dump.h"
#include "services/resource_coordinator/public/cpp/memory_instrumentation/memory_instrumentation.h"

// Must be the last in the includes list.
// Must be the last in the includes list, otherwise the definition of chromium
// macros conflicts with node macros.
#include "atom/common/node_includes.h"

namespace atom {
Expand Down Expand Up @@ -68,7 +69,7 @@ void AtomBindings::BindTo(v8::Isolate* isolate, v8::Local<v8::Object> process) {
dict.SetMethod("getHeapStatistics", &GetHeapStatistics);
dict.SetMethod("getCreationTime", &GetCreationTime);
dict.SetMethod("getSystemMemoryInfo", &GetSystemMemoryInfo);
dict.SetMethod("getMemoryFootprint", &GetMemoryFootprint);
dict.SetMethod("getProcessMemoryInfo", &GetProcessMemoryInfo);
dict.SetMethod("getCPUUsage", base::Bind(&AtomBindings::GetCPUUsage,
base::Unretained(metrics_.get())));
dict.SetMethod("getIOCounters", &GetIOCounters);
Expand Down Expand Up @@ -218,14 +219,15 @@ v8::Local<v8::Value> AtomBindings::GetSystemMemoryInfo(v8::Isolate* isolate,
}

// static
v8::Local<v8::Promise> AtomBindings::GetMemoryFootprint(v8::Isolate* isolate) {
v8::Local<v8::Promise> AtomBindings::GetProcessMemoryInfo(
v8::Isolate* isolate) {
scoped_refptr<util::Promise> promise = new util::Promise(isolate);
node::Environment* env = node::Environment::GetCurrent(isolate);
memory_instrumentation::MemoryInstrumentation::GetInstance()
->RequestGlobalDumpForPid(base::GetCurrentProcId(),
base::AdaptCallbackForRepeating(base::BindOnce(
&AtomBindings::DidReceiveMemoryDump,
base::Unretained(env), promise)));
std::vector<std::string>(),
base::Bind(&AtomBindings::DidReceiveMemoryDump,
base::Unretained(env), promise));
return promise->GetHandle();
}

Expand All @@ -242,21 +244,31 @@ void AtomBindings::DidReceiveMemoryDump(
v8::MicrotasksScope::kRunMicrotasks);
v8::Context::Scope context_scope(env->context());

if (success) {
bool resolved = false;
for (const memory_instrumentation::GlobalMemoryDump::ProcessDump& dump :
global_dump->process_dumps()) {
if (base::GetCurrentProcId() == dump.pid()) {
promise->Resolve(dump.os_dump().private_footprint_kb);
resolved = true;
}
}
if (!resolved) {
promise->RejectWithErrorMessage(
R"(Failed to find current process memory details in memory dump)");
}
} else {
if (!success) {
promise->RejectWithErrorMessage("Failed to receive memory dump");
return;
}

bool resolved = false;
for (const memory_instrumentation::GlobalMemoryDump::ProcessDump& dump :
global_dump->process_dumps()) {
if (base::GetCurrentProcId() == dump.pid()) {
mate::Dictionary dict = mate::Dictionary::CreateEmpty(env->isolate());
const auto& osdump = dump.os_dump();
#if defined(OS_LINUX)
dict.Set("residentSetBytes", osdump.resident_set_kb);
#elif defined(OS_WIN)
dict.Set("workingSetSize", osdump.resident_set_kb);
#endif
dict.Set("privateBytes", osdump.private_footprint_kb);
dict.Set("sharedBytes", osdump.shared_footprint_kb);
promise->Resolve(dict.GetHandle());
resolved = true;
}
}
if (!resolved) {
promise->RejectWithErrorMessage(
R"(Failed to find current process memory details in memory dump)");
}
}

Expand Down
2 changes: 1 addition & 1 deletion atom/common/api/atom_bindings.h
Expand Up @@ -49,7 +49,7 @@ class AtomBindings {
static v8::Local<v8::Value> GetCreationTime(v8::Isolate* isolate);
static v8::Local<v8::Value> GetSystemMemoryInfo(v8::Isolate* isolate,
mate::Arguments* args);
static v8::Local<v8::Promise> GetMemoryFootprint(v8::Isolate* isolate);
static v8::Local<v8::Promise> GetProcessMemoryInfo(v8::Isolate* isolate);
static v8::Local<v8::Value> GetCPUUsage(base::ProcessMetrics* metrics,
v8::Isolate* isolate);
static v8::Local<v8::Value> GetIOCounters(v8::Isolate* isolate);
Expand Down
15 changes: 15 additions & 0 deletions docs/api/process.md
Expand Up @@ -14,6 +14,7 @@ In sandboxed renderers the `process` object contains only a subset of the APIs:
- `crash()`
- `hang()`
- `getHeapStatistics()`
- `getProcessMemoryInfo()`
- `getSystemMemoryInfo()`
- `getCPUUsage()`
- `getIOCounters()`
Expand Down Expand Up @@ -157,6 +158,20 @@ Returns `Object`:

Returns an object with V8 heap statistics. Note that all statistics are reported in Kilobytes.

### `process.getProcessMemoryInfo()`

Returns `Object`:

* `residentSetBytes` Integer on _Linux_ or `workingSetSize` Integer on _Windows_ - The
amount of memory currently pinned to actual physical RAM.
* `privateBytes` Integer - The amount of memory not shared by other processes, such as
JS heap or HTML content.
* `sharedBytes` Integer - The amount of memory shared between processes, typically
memory consumed by the Electron code itself.

Returns an object giving memory usage statistics about the current process. Note
that all statistics are reported in Kilobytes.

### `process.getSystemMemoryInfo()`

Returns `Object`:
Expand Down

0 comments on commit fa62ebd

Please sign in to comment.