Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(293)

Unified Diff: runtime/bin/process_linux.cc

Issue 2996803002: Add current rss and embedder name to Observatory (Closed)
Patch Set: Rebase and Merge Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/bin/process_android.cc ('k') | runtime/include/dart_tools_api.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/process_linux.cc
diff --git a/runtime/bin/process_linux.cc b/runtime/bin/process_linux.cc
index 1ab9a130ae7850c9ccd128355d48bb92ad183ade..cbaa0128388a39688fdfa9826bd7f3e7bc8e4a8a 100644
--- a/runtime/bin/process_linux.cc
+++ b/runtime/bin/process_linux.cc
@@ -860,25 +860,27 @@ intptr_t Process::CurrentProcessId() {
return static_cast<intptr_t>(getpid());
}
+static void SaveErrorAndClose(FILE* file) {
+ int actual_errno = errno;
+ fclose(file);
+ errno = actual_errno;
+}
+
int64_t Process::CurrentRSS() {
// The second value in /proc/self/statm is the current RSS in pages.
- File* statm = File::Open("/proc/self/statm", File::kRead);
+ // It is not possible to use getrusage() because the interested fields are not
+ // implemented by the linux kernel.
+ FILE* statm = fopen("/proc/self/statm", "r");
if (statm == NULL) {
return -1;
}
- RefCntReleaseScope<File> releaser(statm);
- const intptr_t statm_length = 1 * KB;
- void* buffer = reinterpret_cast<void*>(Dart_ScopeAllocate(statm_length));
- const intptr_t statm_read = statm->Read(buffer, statm_length);
- if (statm_read <= 0) {
- return -1;
- }
int64_t current_rss_pages = 0;
- int matches = sscanf(reinterpret_cast<char*>(buffer), "%*s%" Pd64 "",
- &current_rss_pages);
+ int matches = fscanf(statm, "%*s%" Pd64 "", &current_rss_pages);
if (matches != 1) {
+ SaveErrorAndClose(statm);
return -1;
}
+ fclose(statm);
return current_rss_pages * getpagesize();
}
« no previous file with comments | « runtime/bin/process_android.cc ('k') | runtime/include/dart_tools_api.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698