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

Side by Side 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 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 684 matching lines...) Expand 10 before | Expand all | Expand 10 after
695 meminfo->pswpin = val; 695 meminfo->pswpin = val;
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 const std::string GetCgroupMemoryPathString() {
706 std::string cgroup_memory_path = "";
707 std::string mount_info;
708 FilePath mount_file("/proc/mounts");
709 if (!ReadFileToString(mount_file, &mount_info)) {
710 DLOG(WARNING) << "Failed to open " << mount_file.value();
711 return "";
712 }
713 else{
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(tokens[3].find("memory") != std::string::npos) {
725 cgroup_memory_path = tokens[1].data();
726 }
727 }
728 }
729 }
730 return cgroup_memory_path;
731 }
732
733 long IfOnCgroup(std::string cgroup_memory_path_string){
734 bool on_cgroup = false;
735 std::string cgroup_limits_in_bytes = "";
736 // First, cheking if we're on a cgroup
737 if (cgroup_memory_path_string == ""){
738 on_cgroup = false;}
739 else{
740 FilePath cgroup_memory_file((cgroup_memory_path_string+"memory.limit_in_byte s").c_str());
741 std::string cgroup_memory_file_info;
742 if (!ReadFileToString(cgroup_memory_file, &cgroup_memory_file_info)) {
743 on_cgroup =false;}
744 else{
745 cgroup_limits_in_bytes = cgroup_memory_file_info;
746 //file.close();
747 // TODO: is 9223372036854771712 a const?
748 if (cgroup_limits_in_bytes != "9223372036854771712"){
749 on_cgroup = true;}
750 else{
751 on_cgroup = false;}
752 }
753 }
754 if (!on_cgroup){
755 return 0;}
756 else{
757 return (atol(cgroup_limits_in_bytes.c_str()) / 1024);}
758 }
705 759
706 bool GetSystemMemoryInfo(SystemMemoryInfoKB* meminfo) { 760 bool GetSystemMemoryInfo(SystemMemoryInfoKB* meminfo) {
707 // Synchronously reading files in /proc and /sys are safe. 761 // Synchronously reading files in /proc and /sys are safe.
708 ThreadRestrictions::ScopedAllowIO allow_io; 762 ThreadRestrictions::ScopedAllowIO allow_io;
709 763
710 // Used memory is: total - free - buffers - caches 764 // Used memory is: total - free - buffers - caches
711 FilePath meminfo_file("/proc/meminfo"); 765 FilePath meminfo_file("/proc/meminfo");
712 std::string meminfo_data; 766 std::string meminfo_data;
713 if (!ReadFileToString(meminfo_file, &meminfo_data)) { 767 if (!ReadFileToString(meminfo_file, &meminfo_data)) {
714 DLOG(WARNING) << "Failed to open " << meminfo_file.value(); 768 DLOG(WARNING) << "Failed to open " << meminfo_file.value();
715 return false; 769 return false;
716 } 770 }
717 771
718 if (!ParseProcMeminfo(meminfo_data, meminfo)) { 772 if (!ParseProcMeminfo(meminfo_data, meminfo)) {
719 DLOG(WARNING) << "Failed to parse " << meminfo_file.value(); 773 DLOG(WARNING) << "Failed to parse " << meminfo_file.value();
720 return false; 774 return false;
721 } 775 }
722 776 else{
777 std::string cgroup_memory_path_string = GetCgroupMemoryPathString();
778 long total_memory_kb = IfOnCgroup(cgroup_memory_path_string);
779 if (total_memory_kb > 0)
780 {
781 meminfo->total = total_memory_kb;
782 }
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
732 std::string geminfo_data; 793 std::string geminfo_data;
(...skipping 233 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