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

Unified Diff: base/process/process_metrics_linux.cc

Issue 2745473002: Cgroup-awareness for chromium (Closed)
Patch Set: minor fix Created 3 years, 9 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/process/process_metrics_linux.cc
diff --git a/base/process/process_metrics_linux.cc b/base/process/process_metrics_linux.cc
index b14aa210bd57af5bd53c6581590fa221f355d9bb..37760e12cd234e0a1b2a977e3142b166f7739f7c 100644
--- a/base/process/process_metrics_linux.cc
+++ b/base/process/process_metrics_linux.cc
@@ -703,6 +703,59 @@ bool ParseProcVmstat(const std::string& vmstat_data,
return true;
}
+const char * GetCgroupMemoryPathString() {
+ char* cgroup_memory_path = "";
+ std::string& mount_info
+ Filepath mount_file("/proc/mounts")
+ if (!ReadFileToString(mount_file, &mount_info)) {
+ DLOG(WARNING) << "Failed to open " << mount_file.value();
+ return "";
+ }
+ for (const StringPiece& line : SplitStringPiece(
+ mount_info, "\n", KEEP_WHITESPACE, SPLIT_WANT_NONEMPTY)) {
+ std::vector<StringPiece> tokens = SplitStringPiece(
+ line, kWhitespaceASCII, TRIM_WHITESPACE, SPLIT_WANT_NONEMPTY);
+ if (tokens.size() <= 1) {
+ DLOG(WARNING) << "mount: tokens: " << tokens.size()
+ << " malformed line: " << line.as_string();
+ continue;
+ }
+ if (tokens[0] == "cgroup"){
+ if(strstr(tokens[3], 'memory') != NULL) {
+ cgroup_memory_path = tokens[1];
+ }
+ }
+ }
+ return cgroup_memory_path;
+}
+
+long IfOnCgroup(cgroup_memory_path_string){
+ bool on_cgroup = false
+ // If we're on a cgroup, use alternative method
+ // First, cheking if we're on a cgroup
+ if (cgroup_memory_path_string == "")
+ on_cgroup = false
+ else{
+ // only part that matters is, we have memory limitations on the cgroup
+ FILE* file = fopen(cgroup_memory_path_string+"memory.limit_in_bytes", "r");
+ if (!file)
+ on_cgroup =false
+ else{
+ char * cgroup_limits_in_bytes = file.read()
+ file.close()
+ // TODO: is 9223372036854771712 a const?
+ if (cgroup_limits_in_bytes != "9223372036854771712")
+ on_cgroup = true
+ else
+ on_cgroup = false
+ }
+ }
+ if (!on_cgroup)
+ return 0
+ else
+ return cgroup_limits_in_bytes / 1024
+}
+
bool GetSystemMemoryInfo(SystemMemoryInfoKB* meminfo) {
// Synchronously reading files in /proc and /sys are safe.
ThreadRestrictions::ScopedAllowIO allow_io;
@@ -719,6 +772,14 @@ bool GetSystemMemoryInfo(SystemMemoryInfoKB* meminfo) {
DLOG(WARNING) << "Failed to parse " << meminfo_file.value();
return false;
}
+ else{
+ cgroup_memory_path_string = GetCgroupMemoryPathString()
+ long total_memory_kb = on_cgroup(cgroup_memory_path_string)
+ if (total_memory_kb > 0):
+ {
+ &meminfo->total = total_memory_kb
+ }
+ }
#if defined(OS_CHROMEOS)
// Report on Chrome OS GEM object graphics memory. /run/debugfs_gpu is a
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698