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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/process/process_metrics.h" 5 #include "base/process/process_metrics.h"
6 6
7 #include <dirent.h> 7 #include <dirent.h>
8 #include <fcntl.h> 8 #include <fcntl.h>
9 #include <stddef.h> 9 #include <stddef.h>
10 #include <stdint.h> 10 #include <stdint.h>
(...skipping 685 matching lines...) Expand 10 before | Expand all | Expand 10 after
696 } else if (tokens[0] == "pswpout") { 696 } else if (tokens[0] == "pswpout") {
697 meminfo->pswpout = val; 697 meminfo->pswpout = val;
698 } else if (tokens[0] == "pgmajfault") { 698 } else if (tokens[0] == "pgmajfault") {
699 meminfo->pgmajfault = val; 699 meminfo->pgmajfault = val;
700 } 700 }
701 } 701 }
702 702
703 return true; 703 return true;
704 } 704 }
705 705
706 const char * GetCgroupMemoryPathString() {
707 char* cgroup_memory_path = "";
708 std::string& mount_info
709 Filepath mount_file("/proc/mounts")
710 if (!ReadFileToString(mount_file, &mount_info)) {
711 DLOG(WARNING) << "Failed to open " << mount_file.value();
712 return "";
713 }
714 for (const StringPiece& line : SplitStringPiece(
715 mount_info, "\n", KEEP_WHITESPACE, SPLIT_WANT_NONEMPTY)) {
716 std::vector<StringPiece> tokens = SplitStringPiece(
717 line, kWhitespaceASCII, TRIM_WHITESPACE, SPLIT_WANT_NONEMPTY);
718 if (tokens.size() <= 1) {
719 DLOG(WARNING) << "mount: tokens: " << tokens.size()
720 << " malformed line: " << line.as_string();
721 continue;
722 }
723 if (tokens[0] == "cgroup"){
724 if(strstr(tokens[3], 'memory') != NULL) {
725 cgroup_memory_path = tokens[1];
726 }
727 }
728 }
729 return cgroup_memory_path;
730 }
731
732 long IfOnCgroup(cgroup_memory_path_string){
733 bool on_cgroup = false
734 // If we're on a cgroup, use alternative method
735 // First, cheking if we're on a cgroup
736 if (cgroup_memory_path_string == "")
737 on_cgroup = false
738 else{
739 // only part that matters is, we have memory limitations on the cgroup
740 FILE* file = fopen(cgroup_memory_path_string+"memory.limit_in_bytes", "r");
741 if (!file)
742 on_cgroup =false
743 else{
744 char * cgroup_limits_in_bytes = file.read()
745 file.close()
746 // TODO: is 9223372036854771712 a const?
747 if (cgroup_limits_in_bytes != "9223372036854771712")
748 on_cgroup = true
749 else
750 on_cgroup = false
751 }
752 }
753 if (!on_cgroup)
754 return 0
755 else
756 return cgroup_limits_in_bytes / 1024
757 }
758
706 bool GetSystemMemoryInfo(SystemMemoryInfoKB* meminfo) { 759 bool GetSystemMemoryInfo(SystemMemoryInfoKB* meminfo) {
707 // Synchronously reading files in /proc and /sys are safe. 760 // Synchronously reading files in /proc and /sys are safe.
708 ThreadRestrictions::ScopedAllowIO allow_io; 761 ThreadRestrictions::ScopedAllowIO allow_io;
709 762
710 // Used memory is: total - free - buffers - caches 763 // Used memory is: total - free - buffers - caches
711 FilePath meminfo_file("/proc/meminfo"); 764 FilePath meminfo_file("/proc/meminfo");
712 std::string meminfo_data; 765 std::string meminfo_data;
713 if (!ReadFileToString(meminfo_file, &meminfo_data)) { 766 if (!ReadFileToString(meminfo_file, &meminfo_data)) {
714 DLOG(WARNING) << "Failed to open " << meminfo_file.value(); 767 DLOG(WARNING) << "Failed to open " << meminfo_file.value();
715 return false; 768 return false;
716 } 769 }
717 770
718 if (!ParseProcMeminfo(meminfo_data, meminfo)) { 771 if (!ParseProcMeminfo(meminfo_data, meminfo)) {
719 DLOG(WARNING) << "Failed to parse " << meminfo_file.value(); 772 DLOG(WARNING) << "Failed to parse " << meminfo_file.value();
720 return false; 773 return false;
721 } 774 }
775 else{
776 cgroup_memory_path_string = GetCgroupMemoryPathString()
777 long total_memory_kb = on_cgroup(cgroup_memory_path_string)
778 if (total_memory_kb > 0):
779 {
780 &meminfo->total = total_memory_kb
781 }
782 }
722 783
723 #if defined(OS_CHROMEOS) 784 #if defined(OS_CHROMEOS)
724 // Report on Chrome OS GEM object graphics memory. /run/debugfs_gpu is a 785 // Report on Chrome OS GEM object graphics memory. /run/debugfs_gpu is a
725 // bind mount into /sys/kernel/debug and synchronously reading the in-memory 786 // bind mount into /sys/kernel/debug and synchronously reading the in-memory
726 // files in /sys is fast. 787 // files in /sys is fast.
727 #if defined(ARCH_CPU_ARM_FAMILY) 788 #if defined(ARCH_CPU_ARM_FAMILY)
728 FilePath geminfo_file("/run/debugfs_gpu/exynos_gem_objects"); 789 FilePath geminfo_file("/run/debugfs_gpu/exynos_gem_objects");
729 #else 790 #else
730 FilePath geminfo_file("/run/debugfs_gpu/i915_gem_objects"); 791 FilePath geminfo_file("/run/debugfs_gpu/i915_gem_objects");
731 #endif 792 #endif
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
966 #if defined(OS_LINUX) 1027 #if defined(OS_LINUX)
967 int ProcessMetrics::GetIdleWakeupsPerSecond() { 1028 int ProcessMetrics::GetIdleWakeupsPerSecond() {
968 uint64_t wake_ups; 1029 uint64_t wake_ups;
969 const char kWakeupStat[] = "se.statistics.nr_wakeups"; 1030 const char kWakeupStat[] = "se.statistics.nr_wakeups";
970 return ReadProcSchedAndGetFieldAsUint64(process_, kWakeupStat, &wake_ups) ? 1031 return ReadProcSchedAndGetFieldAsUint64(process_, kWakeupStat, &wake_ups) ?
971 CalculateIdleWakeupsPerSecond(wake_ups) : 0; 1032 CalculateIdleWakeupsPerSecond(wake_ups) : 0;
972 } 1033 }
973 #endif // defined(OS_LINUX) 1034 #endif // defined(OS_LINUX)
974 1035
975 } // namespace base 1036 } // namespace base
OLDNEW
« 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