|
@@ -23,51 +23,6 @@ namespace {
|
|
|
// Dummy class type that used for crashing the program.
|
|
|
struct DummyClass { bool crash; };
|
|
|
|
|
|
-void Hang() {
|
|
|
- for (;;)
|
|
|
- base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(1));
|
|
|
-}
|
|
|
-
|
|
|
-v8::Local<v8::Value> GetProcessMemoryInfo(v8::Isolate* isolate) {
|
|
|
- std::unique_ptr<base::ProcessMetrics> metrics(
|
|
|
- base::ProcessMetrics::CreateCurrentProcessMetrics());
|
|
|
-
|
|
|
- mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate);
|
|
|
- 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) {
|
|
|
- base::SystemMemoryInfoKB mem_info;
|
|
|
- if (!base::GetSystemMemoryInfo(&mem_info)) {
|
|
|
- args->ThrowError("Unable to retrieve system memory information");
|
|
|
- return v8::Undefined(isolate);
|
|
|
- }
|
|
|
-
|
|
|
- mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate);
|
|
|
- dict.Set("total", mem_info.total);
|
|
|
- dict.Set("free", mem_info.free);
|
|
|
-
|
|
|
- // NB: These return bogus values on macOS
|
|
|
-#if !defined(OS_MACOSX)
|
|
|
- dict.Set("swapTotal", mem_info.swap_total);
|
|
|
- dict.Set("swapFree", mem_info.swap_free);
|
|
|
-#endif
|
|
|
-
|
|
|
- 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) {
|
|
@@ -168,4 +123,52 @@ void AtomBindings::Crash() {
|
|
|
static_cast<DummyClass*>(nullptr)->crash = true;
|
|
|
}
|
|
|
|
|
|
+// static
|
|
|
+void AtomBindings::Hang() {
|
|
|
+ for (;;)
|
|
|
+ base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(1));
|
|
|
+}
|
|
|
+
|
|
|
+// static
|
|
|
+v8::Local<v8::Value> AtomBindings::GetProcessMemoryInfo(v8::Isolate* isolate) {
|
|
|
+ std::unique_ptr<base::ProcessMetrics> metrics(
|
|
|
+ base::ProcessMetrics::CreateCurrentProcessMetrics());
|
|
|
+
|
|
|
+ mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate);
|
|
|
+ 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();
|
|
|
+}
|
|
|
+
|
|
|
+// static
|
|
|
+v8::Local<v8::Value> AtomBindings::GetSystemMemoryInfo(v8::Isolate* isolate,
|
|
|
+ mate::Arguments* args) {
|
|
|
+ base::SystemMemoryInfoKB mem_info;
|
|
|
+ if (!base::GetSystemMemoryInfo(&mem_info)) {
|
|
|
+ args->ThrowError("Unable to retrieve system memory information");
|
|
|
+ return v8::Undefined(isolate);
|
|
|
+ }
|
|
|
+
|
|
|
+ mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate);
|
|
|
+ dict.Set("total", mem_info.total);
|
|
|
+ dict.Set("free", mem_info.free);
|
|
|
+
|
|
|
+ // NB: These return bogus values on macOS
|
|
|
+#if !defined(OS_MACOSX)
|
|
|
+ dict.Set("swapTotal", mem_info.swap_total);
|
|
|
+ dict.Set("swapFree", mem_info.swap_free);
|
|
|
+#endif
|
|
|
+
|
|
|
+ return dict.GetHandle();
|
|
|
+}
|
|
|
+
|
|
|
} // namespace atom
|