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

Side by Side Diff: base/process/process_metrics_linux.cc

Issue 2859763002: Use another file and field for wakeups count (Closed)
Patch Set: Created 3 years, 7 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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 } 86 }
87 return value; 87 return value;
88 } 88 }
89 } 89 }
90 // This can be reached if the process dies when proc is read -- in that case, 90 // This can be reached if the process dies when proc is read -- in that case,
91 // the kernel can return missing fields. 91 // the kernel can return missing fields.
92 return 0; 92 return 0;
93 } 93 }
94 94
95 #if defined(OS_LINUX) || defined(OS_AIX) 95 #if defined(OS_LINUX) || defined(OS_AIX)
96 // Read /proc/<pid>/sched and look for |field|. On succes, return true and 96 // Read /proc/<pid>/status and look for |field|. On succes, return true and
97 // write the value for |field| into |result|. 97 // write the value for |field| into |result|.
98 // Only works for fields in the form of "field : uint_value" 98 // Only works for fields in the form of "field : uint_value"
99 bool ReadProcSchedAndGetFieldAsUint64(pid_t pid, 99 bool ReadProcStatusAndGetFieldAsUint64(pid_t pid,
100 const std::string& field, 100 const std::string& field,
101 uint64_t* result) { 101 uint64_t* result) {
102 std::string sched_data; 102 std::string stat_data;
Mark Mentovai 2017/05/03 03:17:17 /proc/pid/stat and /proc/pid/status are distinct.
sabbakumov 2017/05/03 03:21:02 I used the convention from the ReadProcStatusAndGe
sabbakumov 2017/05/03 05:20:05 Done.
103 { 103 {
104 // Synchronously reading files in /proc does not hit the disk. 104 // Synchronously reading files in /proc does not hit the disk.
105 ThreadRestrictions::ScopedAllowIO allow_io; 105 ThreadRestrictions::ScopedAllowIO allow_io;
106 FilePath sched_file = internal::GetProcPidDir(pid).Append("sched"); 106 FilePath stat_file = internal::GetProcPidDir(pid).Append("status");
107 if (!ReadFileToString(sched_file, &sched_data)) 107 if (!ReadFileToString(stat_file, &stat_data))
108 return false; 108 return false;
109 } 109 }
110 110
111 StringPairs pairs; 111 StringPairs pairs;
112 SplitStringIntoKeyValuePairs(sched_data, ':', '\n', &pairs); 112 SplitStringIntoKeyValuePairs(stat_data, ':', '\n', &pairs);
113 TrimKeyValuePairs(&pairs); 113 TrimKeyValuePairs(&pairs);
114 for (size_t i = 0; i < pairs.size(); ++i) { 114 for (size_t i = 0; i < pairs.size(); ++i) {
115 const std::string& key = pairs[i].first; 115 const std::string& key = pairs[i].first;
116 const std::string& value_str = pairs[i].second; 116 const std::string& value_str = pairs[i].second;
117 if (key == field) { 117 if (key == field) {
118 uint64_t value; 118 uint64_t value;
119 if (!StringToUint64(value_str, &value)) 119 if (!StringToUint64(value_str, &value))
120 return false; 120 return false;
121 *result = value; 121 *result = value;
122 return true; 122 return true;
(...skipping 829 matching lines...) Expand 10 before | Expand all | Expand 10 after
952 swap_info->num_writes = ReadFileToUint64(zram_path.Append("num_writes")); 952 swap_info->num_writes = ReadFileToUint64(zram_path.Append("num_writes"));
953 swap_info->compr_data_size = 953 swap_info->compr_data_size =
954 ReadFileToUint64(zram_path.Append("compr_data_size")); 954 ReadFileToUint64(zram_path.Append("compr_data_size"));
955 swap_info->mem_used_total = 955 swap_info->mem_used_total =
956 ReadFileToUint64(zram_path.Append("mem_used_total")); 956 ReadFileToUint64(zram_path.Append("mem_used_total"));
957 } 957 }
958 #endif // defined(OS_CHROMEOS) 958 #endif // defined(OS_CHROMEOS)
959 959
960 #if defined(OS_LINUX) || defined(OS_AIX) 960 #if defined(OS_LINUX) || defined(OS_AIX)
961 int ProcessMetrics::GetIdleWakeupsPerSecond() { 961 int ProcessMetrics::GetIdleWakeupsPerSecond() {
962 uint64_t wake_ups; 962 uint64_t num_switches;
963 const char kWakeupStat[] = "se.statistics.nr_wakeups"; 963 static const char kSwitchStat[] = "voluntary_ctxt_switches";
Mark Mentovai 2017/05/03 03:17:18 I haven’t (yet?) verified that this is equivalent
964 return ReadProcSchedAndGetFieldAsUint64(process_, kWakeupStat, &wake_ups) ? 964 return ReadProcStatusAndGetFieldAsUint64(process_, kSwitchStat, &num_switches)
965 CalculateIdleWakeupsPerSecond(wake_ups) : 0; 965 ? CalculateIdleWakeupsPerSecond(num_switches)
966 : 0;
966 } 967 }
967 #endif // defined(OS_LINUX) || defined(OS_AIX) 968 #endif // defined(OS_LINUX) || defined(OS_AIX)
968 969
969 } // namespace base 970 } // 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