| 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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 // Split the rest. | 99 // Split the rest. |
| 100 std::vector<std::string> other_stats; | 100 std::vector<std::string> other_stats; |
| 101 SplitString(stats_data.substr(close_parens_idx + 2), ' ', &other_stats); | 101 SplitString(stats_data.substr(close_parens_idx + 2), ' ', &other_stats); |
| 102 for (size_t i = 0; i < other_stats.size(); ++i) | 102 for (size_t i = 0; i < other_stats.size(); ++i) |
| 103 proc_stats->push_back(other_stats[i]); | 103 proc_stats->push_back(other_stats[i]); |
| 104 return true; | 104 return true; |
| 105 } | 105 } |
| 106 | 106 |
| 107 typedef std::map<std::string, std::string> ProcStatMap; | 107 typedef std::map<std::string, std::string> ProcStatMap; |
| 108 void ParseProcStat(const std::string& contents, ProcStatMap* output) { | 108 void ParseProcStat(const std::string& contents, ProcStatMap* output) { |
| 109 typedef std::pair<std::string, std::string> StringPair; | 109 base::StringPairs key_value_pairs; |
| 110 std::vector<StringPair> key_value_pairs; | |
| 111 SplitStringIntoKeyValuePairs(contents, ' ', '\n', &key_value_pairs); | 110 SplitStringIntoKeyValuePairs(contents, ' ', '\n', &key_value_pairs); |
| 112 for (size_t i = 0; i < key_value_pairs.size(); ++i) { | 111 for (size_t i = 0; i < key_value_pairs.size(); ++i) { |
| 113 const StringPair& key_value_pair = key_value_pairs[i]; | 112 output->insert(key_value_pairs[i]); |
| 114 output->insert(key_value_pair); | |
| 115 } | 113 } |
| 116 } | 114 } |
| 117 | 115 |
| 118 int64 GetProcStatsFieldAsInt64(const std::vector<std::string>& proc_stats, | 116 int64 GetProcStatsFieldAsInt64(const std::vector<std::string>& proc_stats, |
| 119 ProcStatsFields field_num) { | 117 ProcStatsFields field_num) { |
| 120 DCHECK_GE(field_num, VM_PPID); | 118 DCHECK_GE(field_num, VM_PPID); |
| 121 CHECK_LT(static_cast<size_t>(field_num), proc_stats.size()); | 119 CHECK_LT(static_cast<size_t>(field_num), proc_stats.size()); |
| 122 | 120 |
| 123 int64 value; | 121 int64 value; |
| 124 return StringToInt64(proc_stats[field_num], &value) ? value : 0; | 122 return StringToInt64(proc_stats[field_num], &value) ? value : 0; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 // which means the answer is 100. | 178 // which means the answer is 100. |
| 181 // It may be the case that this value is always 100. | 179 // It may be the case that this value is always 100. |
| 182 static const int kHertz = sysconf(_SC_CLK_TCK); | 180 static const int kHertz = sysconf(_SC_CLK_TCK); |
| 183 | 181 |
| 184 return TimeDelta::FromMicroseconds( | 182 return TimeDelta::FromMicroseconds( |
| 185 Time::kMicrosecondsPerSecond * clock_ticks / kHertz); | 183 Time::kMicrosecondsPerSecond * clock_ticks / kHertz); |
| 186 } | 184 } |
| 187 | 185 |
| 188 } // namespace internal | 186 } // namespace internal |
| 189 } // namespace base | 187 } // namespace base |
| OLD | NEW |