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