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