OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/internal_linux.h" | 5 #include "base/process/internal_linux.h" |
6 | 6 |
7 #include <unistd.h> | 7 #include <unistd.h> |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <string> | 10 #include <string> |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 | 107 |
108 typedef std::map<std::string, std::string> ProcStatMap; | 108 typedef std::map<std::string, std::string> ProcStatMap; |
109 void ParseProcStat(const std::string& contents, ProcStatMap* output) { | 109 void ParseProcStat(const std::string& contents, ProcStatMap* output) { |
110 StringPairs key_value_pairs; | 110 StringPairs key_value_pairs; |
111 SplitStringIntoKeyValuePairs(contents, ' ', '\n', &key_value_pairs); | 111 SplitStringIntoKeyValuePairs(contents, ' ', '\n', &key_value_pairs); |
112 for (size_t i = 0; i < key_value_pairs.size(); ++i) { | 112 for (size_t i = 0; i < key_value_pairs.size(); ++i) { |
113 output->insert(key_value_pairs[i]); | 113 output->insert(key_value_pairs[i]); |
114 } | 114 } |
115 } | 115 } |
116 | 116 |
117 int64 GetProcStatsFieldAsInt64(const std::vector<std::string>& proc_stats, | 117 int64_t GetProcStatsFieldAsInt64(const std::vector<std::string>& proc_stats, |
118 ProcStatsFields field_num) { | 118 ProcStatsFields field_num) { |
119 DCHECK_GE(field_num, VM_PPID); | 119 DCHECK_GE(field_num, VM_PPID); |
120 CHECK_LT(static_cast<size_t>(field_num), proc_stats.size()); | 120 CHECK_LT(static_cast<size_t>(field_num), proc_stats.size()); |
121 | 121 |
122 int64 value; | 122 int64_t value; |
123 return StringToInt64(proc_stats[field_num], &value) ? value : 0; | 123 return StringToInt64(proc_stats[field_num], &value) ? value : 0; |
124 } | 124 } |
125 | 125 |
126 size_t GetProcStatsFieldAsSizeT(const std::vector<std::string>& proc_stats, | 126 size_t GetProcStatsFieldAsSizeT(const std::vector<std::string>& proc_stats, |
127 ProcStatsFields field_num) { | 127 ProcStatsFields field_num) { |
128 DCHECK_GE(field_num, VM_PPID); | 128 DCHECK_GE(field_num, VM_PPID); |
129 CHECK_LT(static_cast<size_t>(field_num), proc_stats.size()); | 129 CHECK_LT(static_cast<size_t>(field_num), proc_stats.size()); |
130 | 130 |
131 size_t value; | 131 size_t value; |
132 return StringToSizeT(proc_stats[field_num], &value) ? value : 0; | 132 return StringToSizeT(proc_stats[field_num], &value) ? value : 0; |
133 } | 133 } |
134 | 134 |
135 int64 ReadProcStatsAndGetFieldAsInt64(pid_t pid, ProcStatsFields field_num) { | 135 int64_t ReadProcStatsAndGetFieldAsInt64(pid_t pid, ProcStatsFields field_num) { |
136 std::string stats_data; | 136 std::string stats_data; |
137 if (!ReadProcStats(pid, &stats_data)) | 137 if (!ReadProcStats(pid, &stats_data)) |
138 return 0; | 138 return 0; |
139 std::vector<std::string> proc_stats; | 139 std::vector<std::string> proc_stats; |
140 if (!ParseProcStats(stats_data, &proc_stats)) | 140 if (!ParseProcStats(stats_data, &proc_stats)) |
141 return 0; | 141 return 0; |
142 return GetProcStatsFieldAsInt64(proc_stats, field_num); | 142 return GetProcStatsFieldAsInt64(proc_stats, field_num); |
143 } | 143 } |
144 | 144 |
145 size_t ReadProcStatsAndGetFieldAsSizeT(pid_t pid, | 145 size_t ReadProcStatsAndGetFieldAsSizeT(pid_t pid, |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 // which means the answer is 100. | 179 // which means the answer is 100. |
180 // It may be the case that this value is always 100. | 180 // It may be the case that this value is always 100. |
181 static const int kHertz = sysconf(_SC_CLK_TCK); | 181 static const int kHertz = sysconf(_SC_CLK_TCK); |
182 | 182 |
183 return TimeDelta::FromMicroseconds( | 183 return TimeDelta::FromMicroseconds( |
184 Time::kMicrosecondsPerSecond * clock_ticks / kHertz); | 184 Time::kMicrosecondsPerSecond * clock_ticks / kHertz); |
185 } | 185 } |
186 | 186 |
187 } // namespace internal | 187 } // namespace internal |
188 } // namespace base | 188 } // namespace base |
OLD | NEW |