From bef7d5a520c5eedfae38bd1237e0d3526f2db56e Mon Sep 17 00:00:00 2001 From: Hari Krishna Reddy Juturu Date: Mon, 17 Apr 2017 04:59:16 -0700 Subject: [PATCH 01/11] API to get memory of all processes of the app --- atom/browser/api/atom_api_app.cc | 35 +++++++++++++++++++++++++++++++- atom/browser/api/atom_api_app.h | 14 +++++++++++++ docs/api/app.md | 17 ++++++++++++++++ 3 files changed, 65 insertions(+), 1 deletion(-) diff --git a/atom/browser/api/atom_api_app.cc b/atom/browser/api/atom_api_app.cc index 115041d008..a990b5c1bd 100644 --- a/atom/browser/api/atom_api_app.cc +++ b/atom/browser/api/atom_api_app.cc @@ -912,6 +912,38 @@ void App::GetFileIcon(const base::FilePath& path, } } +v8::Local App::GetAppMemoryInfo(v8::Isolate* isolate) { + AppIdProcessIterator processIterator; + auto processEntry = processIterator.NextProcessEntry(); + mate::Dictionary result = mate::Dictionary::CreateEmpty(isolate); + + while(processEntry != nullptr) { + int64_t pid = processEntry->pid(); + auto process = base::Process::OpenWithExtraPrivileges(pid); + + std::unique_ptr metrics( + base::ProcessMetrics::CreateProcessMetrics(process.Handle())); + + mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate); + + dict.Set("workingSetSize", + static_cast(metrics->GetWorkingSetSize() >> 10)); + dict.Set("peakWorkingSetSize", + static_cast(metrics->GetPeakWorkingSetSize() >> 10)); + + size_t private_bytes, shared_bytes; + if (metrics->GetMemoryBytes(&private_bytes, &shared_bytes)) { + dict.Set("privateBytes", static_cast(private_bytes >> 10)); + dict.Set("sharedBytes", static_cast(shared_bytes >> 10)); + } + + result.Set(std::to_string(pid).c_str(), dict); + processEntry = processIterator.NextProcessEntry(); + } + + return result.GetHandle(); +} + // static mate::Handle App::Create(v8::Isolate* isolate) { return mate::CreateHandle(isolate, new App(isolate)); @@ -983,7 +1015,8 @@ void App::BuildPrototype( &App::IsAccessibilitySupportEnabled) .SetMethod("disableHardwareAcceleration", &App::DisableHardwareAcceleration) - .SetMethod("getFileIcon", &App::GetFileIcon); + .SetMethod("getFileIcon", &App::GetFileIcon) + .SetMethod("getAppMemoryInfo", &App::GetAppMemoryInfo); } } // namespace api diff --git a/atom/browser/api/atom_api_app.h b/atom/browser/api/atom_api_app.h index a87b88bc46..9c35d91af7 100644 --- a/atom/browser/api/atom_api_app.h +++ b/atom/browser/api/atom_api_app.h @@ -13,6 +13,7 @@ #include "atom/browser/browser.h" #include "atom/browser/browser_observer.h" #include "atom/common/native_mate_converters/callback.h" +#include "base/process/process_iterator.h" #include "base/task/cancelable_task_tracker.h" #include "chrome/browser/icon_manager.h" #include "chrome/browser/process_singleton.h" @@ -141,6 +142,8 @@ class App : public AtomBrowserClient::Delegate, void GetFileIcon(const base::FilePath& path, mate::Arguments* args); + v8::Local GetAppMemoryInfo(v8::Isolate* isolate); + #if defined(OS_WIN) // Get the current Jump List settings. v8::Local GetJumpListSettings(); @@ -163,6 +166,17 @@ class App : public AtomBrowserClient::Delegate, DISALLOW_COPY_AND_ASSIGN(App); }; +class AppIdProcessIterator : public base::ProcessIterator { + public: + AppIdProcessIterator() : base::ProcessIterator(NULL) {} + + protected: + bool IncludeEntry() override { + return (entry().parent_pid() == base::GetCurrentProcId() || + entry().pid() == base::GetCurrentProcId()); + } +}; + } // namespace api } // namespace atom diff --git a/docs/api/app.md b/docs/api/app.md index e3160e9053..facc18ec38 100644 --- a/docs/api/app.md +++ b/docs/api/app.md @@ -760,6 +760,23 @@ Disables hardware acceleration for current app. This method can only be called before app is ready. +### `app.getAppMemoryInfo()` + +Returns `Object[]`: + +* `pid` Integer - The process id for which memory info is collected for + * `workingSetSize` Integer - The amount of memory currently pinned to actual physical + RAM. + * `peakWorkingSetSize` Integer - The maximum amount of memory that has ever been 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 all the processes associated with +the app. Note that all statistics are reported in Kilobytes. + ### `app.setBadgeCount(count)` _Linux_ _macOS_ * `count` Integer From 27aad902b8d933f34904518315b8a40650a9d8a7 Mon Sep 17 00:00:00 2001 From: Hari Krishna Reddy Juturu Date: Wed, 26 Apr 2017 21:04:53 -0700 Subject: [PATCH 02/11] Adding docs, specs and fixing object returned --- atom/browser/api/atom_api_app.cc | 40 +++++++++++++++------- atom/browser/api/atom_api_app.h | 11 ------ docs/api/app.md | 15 +------- docs/api/structures/memory-info.md | 12 +++++++ docs/api/structures/process-memory-info.md | 4 +++ spec/api-app-spec.js | 10 ++++++ 6 files changed, 54 insertions(+), 38 deletions(-) create mode 100644 docs/api/structures/memory-info.md create mode 100644 docs/api/structures/process-memory-info.md diff --git a/atom/browser/api/atom_api_app.cc b/atom/browser/api/atom_api_app.cc index a990b5c1bd..825fa42d49 100644 --- a/atom/browser/api/atom_api_app.cc +++ b/atom/browser/api/atom_api_app.cc @@ -337,6 +337,17 @@ namespace api { namespace { +class AppIdProcessIterator : public base::ProcessIterator { + public: + AppIdProcessIterator() : base::ProcessIterator(nullptr) {} + + protected: + bool IncludeEntry() override { + return (entry().parent_pid() == base::GetCurrentProcId() || + entry().pid() == base::GetCurrentProcId()); + } +}; + IconLoader::IconSize GetIconSizeByString(const std::string& size) { if (size == "small") { return IconLoader::IconSize::SMALL; @@ -913,35 +924,38 @@ void App::GetFileIcon(const base::FilePath& path, } v8::Local App::GetAppMemoryInfo(v8::Isolate* isolate) { - AppIdProcessIterator processIterator; - auto processEntry = processIterator.NextProcessEntry(); - mate::Dictionary result = mate::Dictionary::CreateEmpty(isolate); + AppIdProcessIterator process_iterator; + auto processEntry = process_iterator.NextProcessEntry(); + std::vector result; - while(processEntry != nullptr) { + while (processEntry != nullptr) { int64_t pid = processEntry->pid(); auto process = base::Process::OpenWithExtraPrivileges(pid); std::unique_ptr metrics( base::ProcessMetrics::CreateProcessMetrics(process.Handle())); - mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate); - - dict.Set("workingSetSize", + mate::Dictionary pidDict = mate::Dictionary::CreateEmpty(isolate); + mate::Dictionary memoryDict = mate::Dictionary::CreateEmpty(isolate); + + memoryDict.Set("workingSetSize", static_cast(metrics->GetWorkingSetSize() >> 10)); - dict.Set("peakWorkingSetSize", + memoryDict.Set("peakWorkingSetSize", static_cast(metrics->GetPeakWorkingSetSize() >> 10)); size_t private_bytes, shared_bytes; if (metrics->GetMemoryBytes(&private_bytes, &shared_bytes)) { - dict.Set("privateBytes", static_cast(private_bytes >> 10)); - dict.Set("sharedBytes", static_cast(shared_bytes >> 10)); + memoryDict.Set("privateBytes", static_cast(private_bytes >> 10)); + memoryDict.Set("sharedBytes", static_cast(shared_bytes >> 10)); } - result.Set(std::to_string(pid).c_str(), dict); - processEntry = processIterator.NextProcessEntry(); + pidDict.Set("memory", memoryDict); + pidDict.Set("pid", std::to_string(pid)); + result.push_back(pidDict); + processEntry = process_iterator.NextProcessEntry(); } - return result.GetHandle(); + return mate::ConvertToV8(isolate, result); } // static diff --git a/atom/browser/api/atom_api_app.h b/atom/browser/api/atom_api_app.h index 9c35d91af7..240c3b2006 100644 --- a/atom/browser/api/atom_api_app.h +++ b/atom/browser/api/atom_api_app.h @@ -166,17 +166,6 @@ class App : public AtomBrowserClient::Delegate, DISALLOW_COPY_AND_ASSIGN(App); }; -class AppIdProcessIterator : public base::ProcessIterator { - public: - AppIdProcessIterator() : base::ProcessIterator(NULL) {} - - protected: - bool IncludeEntry() override { - return (entry().parent_pid() == base::GetCurrentProcId() || - entry().pid() == base::GetCurrentProcId()); - } -}; - } // namespace api } // namespace atom diff --git a/docs/api/app.md b/docs/api/app.md index facc18ec38..cf537474af 100644 --- a/docs/api/app.md +++ b/docs/api/app.md @@ -762,20 +762,7 @@ This method can only be called before app is ready. ### `app.getAppMemoryInfo()` -Returns `Object[]`: - -* `pid` Integer - The process id for which memory info is collected for - * `workingSetSize` Integer - The amount of memory currently pinned to actual physical - RAM. - * `peakWorkingSetSize` Integer - The maximum amount of memory that has ever been 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 all the processes associated with -the app. Note that all statistics are reported in Kilobytes. +Returns [ProcessMemoryInfo[]](structures/process-memory-info.md): Array of `ProcessMemoryInfo` objects that correspond to memory usage statistics of all the processes associated with the app. ### `app.setBadgeCount(count)` _Linux_ _macOS_ diff --git a/docs/api/structures/memory-info.md b/docs/api/structures/memory-info.md new file mode 100644 index 0000000000..69c67f16cc --- /dev/null +++ b/docs/api/structures/memory-info.md @@ -0,0 +1,12 @@ +# MemoryInfo Object + +* `workingSetSize` Integer - Process id of the process. +* `workingSetSize` Integer - The amount of memory currently pinned to actual physical RAM. +* `peakWorkingSetSize` Integer - The maximum amount of memory that has ever been 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 + +Note that all statistics are reported in Kilobytes. \ No newline at end of file diff --git a/docs/api/structures/process-memory-info.md b/docs/api/structures/process-memory-info.md new file mode 100644 index 0000000000..5083aaa663 --- /dev/null +++ b/docs/api/structures/process-memory-info.md @@ -0,0 +1,4 @@ +# ProcessMemoryInfo Object + +* `pid` Integer - Process id of the process. +* `memory` MemoryInfo - Memory information of the process. \ No newline at end of file diff --git a/spec/api-app-spec.js b/spec/api-app-spec.js index 9a9b4334bc..e210c2205d 100644 --- a/spec/api-app-spec.js +++ b/spec/api-app-spec.js @@ -532,5 +532,15 @@ describe('app module', function () { }) }) }) + + describe('getAppMemoryInfo API', function () { + it('returns the process memory of all running electron processes', function () { + const appMemoryInfo = app.getAppMemoryInfo(); + assert.ok(appMemoryInfo.length > 0, 'App memory info object is not > 0') + assert.ok(appMemoryInfo[0].memory.workingSetSize > 0, 'working set size is not > 0') + assert.ok(appMemoryInfo[0].memory.peakWorkingSetSize > 0, 'peak working set size is not > 0') + assert.ok(appMemoryInfo[0].pid > 0, 'pid is not > 0') + }) + }) }) }) From d77c1319f46a186c727edef771a183702db6d0b7 Mon Sep 17 00:00:00 2001 From: Hari Krishna Reddy Juturu Date: Thu, 27 Apr 2017 08:38:17 -0700 Subject: [PATCH 03/11] Fixing lint error --- spec/api-app-spec.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/spec/api-app-spec.js b/spec/api-app-spec.js index e210c2205d..80b9bf48e2 100644 --- a/spec/api-app-spec.js +++ b/spec/api-app-spec.js @@ -532,15 +532,15 @@ describe('app module', function () { }) }) }) + }) - describe('getAppMemoryInfo API', function () { - it('returns the process memory of all running electron processes', function () { - const appMemoryInfo = app.getAppMemoryInfo(); - assert.ok(appMemoryInfo.length > 0, 'App memory info object is not > 0') - assert.ok(appMemoryInfo[0].memory.workingSetSize > 0, 'working set size is not > 0') - assert.ok(appMemoryInfo[0].memory.peakWorkingSetSize > 0, 'peak working set size is not > 0') - assert.ok(appMemoryInfo[0].pid > 0, 'pid is not > 0') - }) + describe.only('getAppMemoryInfo() API', function () { + it('returns the process memory of all running electron processes', function () { + const appMemoryInfo = app.getAppMemoryInfo() + assert.ok(appMemoryInfo.length > 0, 'App memory info object is not > 0') + assert.ok(appMemoryInfo[0].memory.workingSetSize > 0, 'working set size is not > 0') + assert.ok(appMemoryInfo[0].memory.peakWorkingSetSize > 0, 'peak working set size is not > 0') + assert.ok(appMemoryInfo[0].pid > 0, 'pid is not > 0') }) }) }) From 3d12440a4a7fcabe2453d9a7e71027ccd3db0816 Mon Sep 17 00:00:00 2001 From: Hari Krishna Reddy Juturu Date: Thu, 27 Apr 2017 08:52:37 -0700 Subject: [PATCH 04/11] Fixing mac build --- atom/browser/api/atom_api_app.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/atom/browser/api/atom_api_app.cc b/atom/browser/api/atom_api_app.cc index 825fa42d49..54c0ce0ac8 100644 --- a/atom/browser/api/atom_api_app.cc +++ b/atom/browser/api/atom_api_app.cc @@ -932,8 +932,13 @@ v8::Local App::GetAppMemoryInfo(v8::Isolate* isolate) { int64_t pid = processEntry->pid(); auto process = base::Process::OpenWithExtraPrivileges(pid); +#if defined(OS_MACOSX) + std::unique_ptr metrics( + base::ProcessMetrics::CreateProcessMetrics(process.Handle(), nullptr)); +#else std::unique_ptr metrics( base::ProcessMetrics::CreateProcessMetrics(process.Handle())); +#endif mate::Dictionary pidDict = mate::Dictionary::CreateEmpty(isolate); mate::Dictionary memoryDict = mate::Dictionary::CreateEmpty(isolate); From 81bd9fa3a215b1413f25aa2c835deeba1b9d2d41 Mon Sep 17 00:00:00 2001 From: HariJ Date: Thu, 27 Apr 2017 11:09:27 -0700 Subject: [PATCH 05/11] fixing mac ut failure --- atom/browser/api/atom_api_app.cc | 4 +++- spec/api-app-spec.js | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/atom/browser/api/atom_api_app.cc b/atom/browser/api/atom_api_app.cc index 54c0ce0ac8..d2fb15fa79 100644 --- a/atom/browser/api/atom_api_app.cc +++ b/atom/browser/api/atom_api_app.cc @@ -34,6 +34,7 @@ #include "chrome/browser/icon_manager.h" #include "chrome/common/chrome_paths.h" #include "content/public/browser/browser_accessibility_state.h" +#include "content/public/browser/browser_child_process_host.h" #include "content/public/browser/client_certificate_delegate.h" #include "content/public/browser/gpu_data_manager.h" #include "content/public/browser/render_frame_host.h" @@ -934,7 +935,8 @@ v8::Local App::GetAppMemoryInfo(v8::Isolate* isolate) { #if defined(OS_MACOSX) std::unique_ptr metrics( - base::ProcessMetrics::CreateProcessMetrics(process.Handle(), nullptr)); + base::ProcessMetrics::CreateProcessMetrics( + process.Handle(), content::BrowserChildProcessHost::GetPortProvider())); #else std::unique_ptr metrics( base::ProcessMetrics::CreateProcessMetrics(process.Handle())); diff --git a/spec/api-app-spec.js b/spec/api-app-spec.js index 80b9bf48e2..5f348f9c18 100644 --- a/spec/api-app-spec.js +++ b/spec/api-app-spec.js @@ -539,7 +539,8 @@ describe('app module', function () { const appMemoryInfo = app.getAppMemoryInfo() assert.ok(appMemoryInfo.length > 0, 'App memory info object is not > 0') assert.ok(appMemoryInfo[0].memory.workingSetSize > 0, 'working set size is not > 0') - assert.ok(appMemoryInfo[0].memory.peakWorkingSetSize > 0, 'peak working set size is not > 0') + assert.ok(appMemoryInfo[0].memory.privateBytes > 0, 'private bytes is not > 0') + assert.ok(appMemoryInfo[0].memory.sharedBytes > 0, 'shared bytes is not > 0') assert.ok(appMemoryInfo[0].pid > 0, 'pid is not > 0') }) }) From 88ad28b2a5525197a86f0c9959ea6c53cbf920f8 Mon Sep 17 00:00:00 2001 From: HariJ Date: Thu, 27 Apr 2017 11:32:20 -0700 Subject: [PATCH 06/11] Removing describe.only --- spec/api-app-spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/api-app-spec.js b/spec/api-app-spec.js index 5f348f9c18..7e2430ef37 100644 --- a/spec/api-app-spec.js +++ b/spec/api-app-spec.js @@ -534,7 +534,7 @@ describe('app module', function () { }) }) - describe.only('getAppMemoryInfo() API', function () { + describe('getAppMemoryInfo() API', function () { it('returns the process memory of all running electron processes', function () { const appMemoryInfo = app.getAppMemoryInfo() assert.ok(appMemoryInfo.length > 0, 'App memory info object is not > 0') From 07b53c02846626990a19615f83b2e24fe211fd51 Mon Sep 17 00:00:00 2001 From: Hari Krishna Reddy Juturu Date: Thu, 27 Apr 2017 21:07:35 -0700 Subject: [PATCH 07/11] Return mate::Dictionary instead of v8::value --- atom/browser/api/atom_api_app.cc | 5 ++--- atom/browser/api/atom_api_app.h | 3 ++- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/atom/browser/api/atom_api_app.cc b/atom/browser/api/atom_api_app.cc index d2fb15fa79..dd03e1802f 100644 --- a/atom/browser/api/atom_api_app.cc +++ b/atom/browser/api/atom_api_app.cc @@ -40,7 +40,6 @@ #include "content/public/browser/render_frame_host.h" #include "content/public/common/content_switches.h" #include "media/audio/audio_manager.h" -#include "native_mate/dictionary.h" #include "native_mate/object_template_builder.h" #include "net/ssl/ssl_cert_request_info.h" #include "ui/base/l10n/l10n_util.h" @@ -924,7 +923,7 @@ void App::GetFileIcon(const base::FilePath& path, } } -v8::Local App::GetAppMemoryInfo(v8::Isolate* isolate) { +std::vector App::GetAppMemoryInfo(v8::Isolate* isolate) { AppIdProcessIterator process_iterator; auto processEntry = process_iterator.NextProcessEntry(); std::vector result; @@ -962,7 +961,7 @@ v8::Local App::GetAppMemoryInfo(v8::Isolate* isolate) { processEntry = process_iterator.NextProcessEntry(); } - return mate::ConvertToV8(isolate, result); + return result; } // static diff --git a/atom/browser/api/atom_api_app.h b/atom/browser/api/atom_api_app.h index 240c3b2006..9543e4b74b 100644 --- a/atom/browser/api/atom_api_app.h +++ b/atom/browser/api/atom_api_app.h @@ -18,6 +18,7 @@ #include "chrome/browser/icon_manager.h" #include "chrome/browser/process_singleton.h" #include "content/public/browser/gpu_data_manager_observer.h" +#include "native_mate/dictionary.h" #include "native_mate/handle.h" #include "net/base/completion_callback.h" @@ -142,7 +143,7 @@ class App : public AtomBrowserClient::Delegate, void GetFileIcon(const base::FilePath& path, mate::Arguments* args); - v8::Local GetAppMemoryInfo(v8::Isolate* isolate); + std::vector GetAppMemoryInfo(v8::Isolate* isolate); #if defined(OS_WIN) // Get the current Jump List settings. From e206aae9fca38676f3e9666068460c1353b25dbf Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 4 May 2017 13:27:35 -0700 Subject: [PATCH 08/11] :art: Use snake case --- atom/browser/api/atom_api_app.cc | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/atom/browser/api/atom_api_app.cc b/atom/browser/api/atom_api_app.cc index dd03e1802f..eb08b77cdd 100644 --- a/atom/browser/api/atom_api_app.cc +++ b/atom/browser/api/atom_api_app.cc @@ -925,11 +925,11 @@ void App::GetFileIcon(const base::FilePath& path, std::vector App::GetAppMemoryInfo(v8::Isolate* isolate) { AppIdProcessIterator process_iterator; - auto processEntry = process_iterator.NextProcessEntry(); + auto process_entry = process_iterator.NextProcessEntry(); std::vector result; - while (processEntry != nullptr) { - int64_t pid = processEntry->pid(); + while (process_entry != nullptr) { + int64_t pid = process_entry->pid(); auto process = base::Process::OpenWithExtraPrivileges(pid); #if defined(OS_MACOSX) @@ -941,24 +941,24 @@ std::vector App::GetAppMemoryInfo(v8::Isolate* isolate) { base::ProcessMetrics::CreateProcessMetrics(process.Handle())); #endif - mate::Dictionary pidDict = mate::Dictionary::CreateEmpty(isolate); - mate::Dictionary memoryDict = mate::Dictionary::CreateEmpty(isolate); + mate::Dictionary pid_dict = mate::Dictionary::CreateEmpty(isolate); + mate::Dictionary memory_dict = mate::Dictionary::CreateEmpty(isolate); - memoryDict.Set("workingSetSize", + memory_dict.Set("workingSetSize", static_cast(metrics->GetWorkingSetSize() >> 10)); - memoryDict.Set("peakWorkingSetSize", + memory_dict.Set("peakWorkingSetSize", static_cast(metrics->GetPeakWorkingSetSize() >> 10)); size_t private_bytes, shared_bytes; if (metrics->GetMemoryBytes(&private_bytes, &shared_bytes)) { - memoryDict.Set("privateBytes", static_cast(private_bytes >> 10)); - memoryDict.Set("sharedBytes", static_cast(shared_bytes >> 10)); + memory_dict.Set("privateBytes", static_cast(private_bytes >> 10)); + memory_dict.Set("sharedBytes", static_cast(shared_bytes >> 10)); } - pidDict.Set("memory", memoryDict); - pidDict.Set("pid", std::to_string(pid)); - result.push_back(pidDict); - processEntry = process_iterator.NextProcessEntry(); + pid_dict.Set("memory", memory_dict); + pid_dict.Set("pid", std::to_string(pid)); + result.push_back(pid_dict); + process_entry = process_iterator.NextProcessEntry(); } return result; From edd28c9a913d458a586ddb3ea0c74b5919d1c084 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 4 May 2017 13:35:12 -0700 Subject: [PATCH 09/11] Link to MemoryInfo structure --- docs/api/structures/process-memory-info.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/api/structures/process-memory-info.md b/docs/api/structures/process-memory-info.md index 5083aaa663..68198f2d45 100644 --- a/docs/api/structures/process-memory-info.md +++ b/docs/api/structures/process-memory-info.md @@ -1,4 +1,4 @@ # ProcessMemoryInfo Object * `pid` Integer - Process id of the process. -* `memory` MemoryInfo - Memory information of the process. \ No newline at end of file +* `memory` [MemoryInfo](memory-info.md) - Memory information of the process. From ab1bcefe9eba9d7531695f03eaa476614ddc5ee6 Mon Sep 17 00:00:00 2001 From: Hari Krishna Reddy Juturu Date: Thu, 4 May 2017 13:37:43 -0700 Subject: [PATCH 10/11] Make pid an integer --- atom/browser/api/atom_api_app.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/atom/browser/api/atom_api_app.cc b/atom/browser/api/atom_api_app.cc index eb08b77cdd..1024bb0c6c 100644 --- a/atom/browser/api/atom_api_app.cc +++ b/atom/browser/api/atom_api_app.cc @@ -956,7 +956,7 @@ std::vector App::GetAppMemoryInfo(v8::Isolate* isolate) { } pid_dict.Set("memory", memory_dict); - pid_dict.Set("pid", std::to_string(pid)); + pid_dict.Set("pid", pid); result.push_back(pid_dict); process_entry = process_iterator.NextProcessEntry(); } From 3b3e7cc14eda20ac6a8bbbcda08daf7826d7e2c0 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 4 May 2017 13:43:45 -0700 Subject: [PATCH 11/11] Assert memory info for all returned processes --- spec/api-app-spec.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/spec/api-app-spec.js b/spec/api-app-spec.js index 7e2430ef37..1bcc1a5c62 100644 --- a/spec/api-app-spec.js +++ b/spec/api-app-spec.js @@ -538,10 +538,12 @@ describe('app module', function () { it('returns the process memory of all running electron processes', function () { const appMemoryInfo = app.getAppMemoryInfo() assert.ok(appMemoryInfo.length > 0, 'App memory info object is not > 0') - assert.ok(appMemoryInfo[0].memory.workingSetSize > 0, 'working set size is not > 0') - assert.ok(appMemoryInfo[0].memory.privateBytes > 0, 'private bytes is not > 0') - assert.ok(appMemoryInfo[0].memory.sharedBytes > 0, 'shared bytes is not > 0') - assert.ok(appMemoryInfo[0].pid > 0, 'pid is not > 0') + for (const {memory, pid} of appMemoryInfo) { + assert.ok(memory.workingSetSize > 0, 'working set size is not > 0') + assert.ok(memory.privateBytes > 0, 'private bytes is not > 0') + assert.ok(memory.sharedBytes > 0, 'shared bytes is not > 0') + assert.ok(pid > 0, 'pid is not > 0') + } }) }) })