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

Unified Diff: base/process/process_metrics_linux.cc

Issue 2746793004: Added cgroup-awareness to Chromium (second draft)
Patch Set: 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 5d542cc67527dad91035dcfc076e4f28b22ba25f..afc650802228833ee11edfc011b25c02db1ecb29 100644
--- a/base/process/process_metrics_linux.cc
+++ b/base/process/process_metrics_linux.cc
@@ -702,6 +702,60 @@ bool ParseProcVmstat(const std::string& vmstat_data,
return true;
}
+const std::string GetCgroupMemoryPathString() {
+ std::string 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 "";
+ }
+ else{
+ 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(tokens[3].find("memory") != std::string::npos) {
+ cgroup_memory_path = tokens[1].data();
+ }
+ }
+ }
+ }
+ return cgroup_memory_path;
+}
+
+long IfOnCgroup(std::string cgroup_memory_path_string){
+ bool on_cgroup = false;
+ std::string cgroup_limits_in_bytes = "";
+ // First, cheking if we're on a cgroup
+ if (cgroup_memory_path_string == ""){
+ on_cgroup = false;}
+ else{
+ FilePath cgroup_memory_file((cgroup_memory_path_string+"memory.limit_in_bytes").c_str());
+ std::string cgroup_memory_file_info;
+ if (!ReadFileToString(cgroup_memory_file, &cgroup_memory_file_info)) {
+ on_cgroup =false;}
+ else{
+ cgroup_limits_in_bytes = cgroup_memory_file_info;
+ //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 (atol(cgroup_limits_in_bytes.c_str()) / 1024);}
+}
bool GetSystemMemoryInfo(SystemMemoryInfoKB* meminfo) {
// Synchronously reading files in /proc and /sys are safe.
@@ -719,7 +773,14 @@ bool GetSystemMemoryInfo(SystemMemoryInfoKB* meminfo) {
DLOG(WARNING) << "Failed to parse " << meminfo_file.value();
return false;
}
-
+ else{
+ std::string cgroup_memory_path_string = GetCgroupMemoryPathString();
+ long total_memory_kb = IfOnCgroup(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
// bind mount into /sys/kernel/debug and synchronously reading the in-memory
« 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