Skip to content
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

Merged
merged 11 commits into from
May 4, 2017
Merged

Conversation

juturu
Copy link
Contributor

@juturu juturu commented Apr 17, 2017

Adding api which will help apps to get memory info for all processes.

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[]`:
Copy link
Member

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 👍

@@ -157,6 +160,17 @@ class App : public AtomBrowserClient::Delegate,
DISALLOW_COPY_AND_ASSIGN(App);
};

class AppIdProcessIterator : public base::ProcessIterator {
Copy link
Contributor

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?

@@ -904,6 +904,38 @@ void App::GetFileIcon(const base::FilePath& path,
}
}

v8::Local<v8::Value> App::GetAppMemoryInfo(v8::Isolate* isolate) {
AppIdProcessIterator processIterator;
Copy link
Contributor

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.
Copy link
Contributor

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.

@anaisbetts
Copy link
Contributor

This seems super similar to https://github.com/electron/electron/blob/master/docs/api/process.md#processgetsystemmemoryinfo, maybe we can unify these?

@poiru poiru mentioned this pull request Apr 18, 2017
2 tasks
docs/api/app.md Outdated

Returns `Object[]`:

* `pid` Integer - The process id for which memory info is collected for
Copy link
Contributor

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)?

@zcbenz zcbenz self-assigned this Apr 25, 2017
Copy link
Contributor

@kevinsawicki kevinsawicki left a 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

dict.Set("sharedBytes", static_cast<double>(shared_bytes >> 10));
}

result.Set(std::to_string(pid).c_str(), dict);
Copy link
Contributor

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()`
Copy link
Contributor

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.

@@ -157,6 +160,17 @@ class App : public AtomBrowserClient::Delegate,
DISALLOW_COPY_AND_ASSIGN(App);
};

class AppIdProcessIterator : public base::ProcessIterator {
public:
AppIdProcessIterator() : base::ProcessIterator(NULL) {}
Copy link
Contributor

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?

@juturu
Copy link
Contributor Author

juturu commented Apr 27, 2017

@MarshallOfSound @poiru @kevinsawicki made the changes requested and fixed other spec issues. Please take a look.
@alexstrat this returns memory info of all the process corresponding to the app. You can iterate over the array to get the memory info for the pid you are interested in. Does that help?
@paulcbetts yes it is similar for the part of memory retrieve from a process. We can unify it. Any suggestion on where the utility method could go to?

processEntry = process_iterator.NextProcessEntry();
}

return mate::ConvertToV8(isolate, result);
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, this works. updated.

@juturu
Copy link
Contributor Author

juturu commented May 3, 2017

@zcbenz anything blocking in merging this PR?

base::ProcessMetrics::CreateProcessMetrics(process.Handle()));
#endif

mate::Dictionary pidDict = mate::Dictionary::CreateEmpty(isolate);
Copy link
Contributor

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. 🙃)

@kevinsawicki kevinsawicki merged commit 5951135 into master May 4, 2017
@kevinsawicki kevinsawicki deleted the app-memoryinfo branch May 4, 2017 21:00
@kevinsawicki
Copy link
Contributor

Thanks for this @juturu 👍 🚢

@alexstrat
Copy link
Contributor

alexstrat commented May 15, 2017

@juturu app.getAppMemoryInfo actually returns the actual OS process id as pid, and on webContents there is no method (documented or undocumented) to get the actual OS process id. Therefore I don't see a way to make a link between a webContents and the associated process memory metrics coming from getAppMemoryInfo => FUP in #9222

@juturu
Copy link
Contributor Author

juturu commented May 16, 2017

@alexstrat please look at #9486 to see if that help with what you want to achieve.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants