Move everything into atom_bindings
This commit is contained in:
parent
dc86ec8ddd
commit
e995befcd0
5 changed files with 44 additions and 72 deletions
|
@ -1,67 +0,0 @@
|
||||||
// Copyright (c) 2015 GitHub, Inc.
|
|
||||||
// Use of this source code is governed by the MIT license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
#include "atom/common/api/atom_api_native_image.h"
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include "atom/common/node_includes.h"
|
|
||||||
#include "base/process/process_metrics.h"
|
|
||||||
#include "native_mate/dictionary.h"
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
v8::Local<v8::Value> GetProcessMemoryInfo(v8::Isolate* isolate) {
|
|
||||||
mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate);
|
|
||||||
std::unique_ptr<base::ProcessMetrics> metrics(
|
|
||||||
base::ProcessMetrics::CreateCurrentProcessMetrics());
|
|
||||||
|
|
||||||
dict.Set("workingSetSize",
|
|
||||||
static_cast<double>(metrics->GetWorkingSetSize() >> 10));
|
|
||||||
dict.Set("peakWorkingSetSize",
|
|
||||||
static_cast<double>(metrics->GetPeakWorkingSetSize() >> 10));
|
|
||||||
|
|
||||||
size_t private_bytes, shared_bytes;
|
|
||||||
if (metrics->GetMemoryBytes(&private_bytes, &shared_bytes)) {
|
|
||||||
dict.Set("privateBytes", static_cast<double>(private_bytes >> 10));
|
|
||||||
dict.Set("sharedBytes", static_cast<double>(shared_bytes >> 10));
|
|
||||||
}
|
|
||||||
|
|
||||||
return dict.GetHandle();
|
|
||||||
}
|
|
||||||
|
|
||||||
v8::Local<v8::Value> GetSystemMemoryInfo(
|
|
||||||
v8::Isolate* isolate,
|
|
||||||
mate::Arguments* args) {
|
|
||||||
mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate);
|
|
||||||
base::SystemMemoryInfoKB memInfo;
|
|
||||||
|
|
||||||
if (!base::GetSystemMemoryInfo(&memInfo)) {
|
|
||||||
args->ThrowError("Unable to retrieve system memory information");
|
|
||||||
return v8::Undefined(isolate);
|
|
||||||
}
|
|
||||||
|
|
||||||
dict.Set("total", memInfo.total);
|
|
||||||
dict.Set("free", memInfo.free);
|
|
||||||
|
|
||||||
// NB: These return bogus values on OS X
|
|
||||||
#if !defined(OS_MACOSX)
|
|
||||||
dict.Set("swapTotal", memInfo.swap_total);
|
|
||||||
dict.Set("swapFree", memInfo.swap_free);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return dict.GetHandle();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
|
|
||||||
v8::Local<v8::Context> context, void* priv) {
|
|
||||||
mate::Dictionary dict(context->GetIsolate(), exports);
|
|
||||||
dict.SetMethod("getProcessMemoryInfo", &GetProcessMemoryInfo);
|
|
||||||
dict.SetMethod("getSystemMemoryInfo", &GetSystemMemoryInfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
NODE_MODULE_CONTEXT_AWARE_BUILTIN(atom_common_process_stats, Initialize)
|
|
|
@ -33,6 +33,48 @@ void Hang() {
|
||||||
base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(1));
|
base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
v8::Local<v8::Value> GetProcessMemoryInfo(v8::Isolate* isolate) {
|
||||||
|
mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate);
|
||||||
|
std::unique_ptr<base::ProcessMetrics> metrics(
|
||||||
|
base::ProcessMetrics::CreateCurrentProcessMetrics());
|
||||||
|
|
||||||
|
dict.Set("workingSetSize",
|
||||||
|
static_cast<double>(metrics->GetWorkingSetSize() >> 10));
|
||||||
|
dict.Set("peakWorkingSetSize",
|
||||||
|
static_cast<double>(metrics->GetPeakWorkingSetSize() >> 10));
|
||||||
|
|
||||||
|
size_t private_bytes, shared_bytes;
|
||||||
|
if (metrics->GetMemoryBytes(&private_bytes, &shared_bytes)) {
|
||||||
|
dict.Set("privateBytes", static_cast<double>(private_bytes >> 10));
|
||||||
|
dict.Set("sharedBytes", static_cast<double>(shared_bytes >> 10));
|
||||||
|
}
|
||||||
|
|
||||||
|
return dict.GetHandle();
|
||||||
|
}
|
||||||
|
|
||||||
|
v8::Local<v8::Value> GetSystemMemoryInfo(
|
||||||
|
v8::Isolate* isolate,
|
||||||
|
mate::Arguments* args) {
|
||||||
|
mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate);
|
||||||
|
base::SystemMemoryInfoKB memInfo;
|
||||||
|
|
||||||
|
if (!base::GetSystemMemoryInfo(&memInfo)) {
|
||||||
|
args->ThrowError("Unable to retrieve system memory information");
|
||||||
|
return v8::Undefined(isolate);
|
||||||
|
}
|
||||||
|
|
||||||
|
dict.Set("total", memInfo.total);
|
||||||
|
dict.Set("free", memInfo.free);
|
||||||
|
|
||||||
|
// NB: These return bogus values on OS X
|
||||||
|
#if !defined(OS_MACOSX)
|
||||||
|
dict.Set("swapTotal", memInfo.swap_total);
|
||||||
|
dict.Set("swapFree", memInfo.swap_free);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return dict.GetHandle();
|
||||||
|
}
|
||||||
|
|
||||||
// Called when there is a fatal error in V8, we just crash the process here so
|
// Called when there is a fatal error in V8, we just crash the process here so
|
||||||
// we can get the stack trace.
|
// we can get the stack trace.
|
||||||
void FatalErrorCallback(const char* location, const char* message) {
|
void FatalErrorCallback(const char* location, const char* message) {
|
||||||
|
@ -63,6 +105,8 @@ void AtomBindings::BindTo(v8::Isolate* isolate,
|
||||||
dict.SetMethod("crash", &Crash);
|
dict.SetMethod("crash", &Crash);
|
||||||
dict.SetMethod("hang", &Hang);
|
dict.SetMethod("hang", &Hang);
|
||||||
dict.SetMethod("log", &Log);
|
dict.SetMethod("log", &Log);
|
||||||
|
dict.SetMethod("getProcessMemoryInfo", &GetProcessMemoryInfo);
|
||||||
|
dict.SetMethod("getSystemMemoryInfo", &GetSystemMemoryInfo);
|
||||||
#if defined(OS_POSIX)
|
#if defined(OS_POSIX)
|
||||||
dict.SetMethod("setFdLimit", &base::SetFdLimit);
|
dict.SetMethod("setFdLimit", &base::SetFdLimit);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -54,7 +54,6 @@ REFERENCE_MODULE(atom_common_clipboard);
|
||||||
REFERENCE_MODULE(atom_common_crash_reporter);
|
REFERENCE_MODULE(atom_common_crash_reporter);
|
||||||
REFERENCE_MODULE(atom_common_native_image);
|
REFERENCE_MODULE(atom_common_native_image);
|
||||||
REFERENCE_MODULE(atom_common_screen);
|
REFERENCE_MODULE(atom_common_screen);
|
||||||
REFERENCE_MODULE(atom_common_process_stats);
|
|
||||||
REFERENCE_MODULE(atom_common_shell);
|
REFERENCE_MODULE(atom_common_shell);
|
||||||
REFERENCE_MODULE(atom_common_v8_util);
|
REFERENCE_MODULE(atom_common_v8_util);
|
||||||
REFERENCE_MODULE(atom_renderer_ipc);
|
REFERENCE_MODULE(atom_renderer_ipc);
|
||||||
|
|
|
@ -44,7 +44,6 @@
|
||||||
'lib/common/api/deprecations.js',
|
'lib/common/api/deprecations.js',
|
||||||
'lib/common/api/exports/electron.js',
|
'lib/common/api/exports/electron.js',
|
||||||
'lib/common/api/native-image.js',
|
'lib/common/api/native-image.js',
|
||||||
'lib/common/api/process-stats.js',
|
|
||||||
'lib/common/api/shell.js',
|
'lib/common/api/shell.js',
|
||||||
'lib/common/init.js',
|
'lib/common/init.js',
|
||||||
'lib/common/reset-search-paths.js',
|
'lib/common/reset-search-paths.js',
|
||||||
|
@ -293,7 +292,6 @@
|
||||||
'atom/common/api/atom_api_native_image.cc',
|
'atom/common/api/atom_api_native_image.cc',
|
||||||
'atom/common/api/atom_api_native_image.h',
|
'atom/common/api/atom_api_native_image.h',
|
||||||
'atom/common/api/atom_api_native_image_mac.mm',
|
'atom/common/api/atom_api_native_image_mac.mm',
|
||||||
'atom/common/api/atom_api_process_stats.cc',
|
|
||||||
'atom/common/api/atom_api_shell.cc',
|
'atom/common/api/atom_api_shell.cc',
|
||||||
'atom/common/api/atom_api_v8_util.cc',
|
'atom/common/api/atom_api_v8_util.cc',
|
||||||
'atom/common/api/atom_bindings.cc',
|
'atom/common/api/atom_bindings.cc',
|
||||||
|
|
|
@ -46,5 +46,3 @@ if (process.type === 'browser') {
|
||||||
if (process.platform === 'win32' && __dirname.indexOf('\\Program Files\\WindowsApps\\') === 2) {
|
if (process.platform === 'win32' && __dirname.indexOf('\\Program Files\\WindowsApps\\') === 2) {
|
||||||
process.windowsStore = true
|
process.windowsStore = true
|
||||||
}
|
}
|
||||||
|
|
||||||
Object.assign(Object.getPrototypeOf(process), process.atomBinding('process_stats'))
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue