-
Notifications
You must be signed in to change notification settings - Fork 15.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
API to get memory of all processes of the app #9214
Conversation
docs/api/app.md
Outdated
@@ -760,6 +760,23 @@ Disables hardware acceleration for current app. | |||
|
|||
This method can only be called before app is ready. | |||
|
|||
### `app.getAppMemoryInfo()` | |||
|
|||
Returns `Object[]`: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be a new structure, maybe ProcessMemoryInfo[]
Then the object described below should be moved to a new structure markdown file 👍
atom/browser/api/atom_api_app.h
Outdated
@@ -157,6 +160,17 @@ class App : public AtomBrowserClient::Delegate, | |||
DISALLOW_COPY_AND_ASSIGN(App); | |||
}; | |||
|
|||
class AppIdProcessIterator : public base::ProcessIterator { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need to be in the header or could it be moved into the .cc file?
atom/browser/api/atom_api_app.cc
Outdated
@@ -904,6 +904,38 @@ void App::GetFileIcon(const base::FilePath& path, | |||
} | |||
} | |||
|
|||
v8::Local<v8::Value> App::GetAppMemoryInfo(v8::Isolate* isolate) { | |||
AppIdProcessIterator processIterator; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Please use snake_case
docs/api/app.md
Outdated
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems weird to me that sharedBytes represents kilobytes instead of bytes. Is there a reason for that? If not, it might make more sense to just use bytes and perform the division in the app code.
This seems super similar to https://github.com/electron/electron/blob/master/docs/api/process.md#processgetsystemmemoryinfo, maybe we can unify these? |
docs/api/app.md
Outdated
|
||
Returns `Object[]`: | ||
|
||
* `pid` Integer - The process id for which memory info is collected for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this allow to link to a specific web-contents
? Can I use webContents.fromId(pid)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a few minor comments
atom/browser/api/atom_api_app.cc
Outdated
dict.Set("sharedBytes", static_cast<double>(shared_bytes >> 10)); | ||
} | ||
|
||
result.Set(std::to_string(pid).c_str(), dict); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you need the .c_str()
here, result.Set
should handle std::string
as the first argument.
@@ -760,6 +760,23 @@ Disables hardware acceleration for current app. | |||
|
|||
This method can only be called before app is ready. | |||
|
|||
### `app.getAppMemoryInfo()` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should add a spec for this.
atom/browser/api/atom_api_app.h
Outdated
@@ -157,6 +160,17 @@ class App : public AtomBrowserClient::Delegate, | |||
DISALLOW_COPY_AND_ASSIGN(App); | |||
}; | |||
|
|||
class AppIdProcessIterator : public base::ProcessIterator { | |||
public: | |||
AppIdProcessIterator() : base::ProcessIterator(NULL) {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could nullptr
be used here instead?
@MarshallOfSound @poiru @kevinsawicki made the changes requested and fixed other spec issues. Please take a look. |
atom/browser/api/atom_api_app.cc
Outdated
processEntry = process_iterator.NextProcessEntry(); | ||
} | ||
|
||
return mate::ConvertToV8(isolate, result); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this method can just have a return type of std::vector<mate::Dictionary>
and then you don't need to do this explicit conversion here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep, this works. updated.
@zcbenz anything blocking in merging this PR? |
atom/browser/api/atom_api_app.cc
Outdated
base::ProcessMetrics::CreateProcessMetrics(process.Handle())); | ||
#endif | ||
|
||
mate::Dictionary pidDict = mate::Dictionary::CreateEmpty(isolate); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you're bored, you could change processEntry
, pidDict
, and memoryDict
to use snake case. (Sorry. 🙃)
Thanks for this @juturu 👍 🚢 |
@juturu |
@alexstrat please look at #9486 to see if that help with what you want to achieve. |
Adding api which will help apps to get memory info for all processes.