OLD | NEW |
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 <windows.h> | 7 #include <windows.h> |
8 #include <psapi.h> | 8 #include <psapi.h> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 return 0; | 218 return 0; |
219 } | 219 } |
220 | 220 |
221 int64 system_time_delta = system_time - last_system_time_; | 221 int64 system_time_delta = system_time - last_system_time_; |
222 // FILETIME is in 100-nanosecond units, so this needs microseconds times 10. | 222 // FILETIME is in 100-nanosecond units, so this needs microseconds times 10. |
223 int64 time_delta = (time - last_cpu_time_).InMicroseconds() * 10; | 223 int64 time_delta = (time - last_cpu_time_).InMicroseconds() * 10; |
224 DCHECK_NE(0U, time_delta); | 224 DCHECK_NE(0U, time_delta); |
225 if (time_delta == 0) | 225 if (time_delta == 0) |
226 return 0; | 226 return 0; |
227 | 227 |
228 // We add time_delta / 2 so the result is rounded. | |
229 int cpu = static_cast<int>((system_time_delta * 100 + time_delta / 2) / | |
230 time_delta); | |
231 | 228 |
232 last_system_time_ = system_time; | 229 last_system_time_ = system_time; |
233 last_cpu_time_ = time; | 230 last_cpu_time_ = time; |
234 | 231 |
235 return cpu; | 232 return static_cast<double>(system_time_delta * 100.0) / time_delta; |
236 } | 233 } |
237 | 234 |
238 bool ProcessMetrics::GetIOCounters(IoCounters* io_counters) const { | 235 bool ProcessMetrics::GetIOCounters(IoCounters* io_counters) const { |
239 return GetProcessIoCounters(process_, io_counters) != FALSE; | 236 return GetProcessIoCounters(process_, io_counters) != FALSE; |
240 } | 237 } |
241 | 238 |
242 ProcessMetrics::ProcessMetrics(ProcessHandle process) | 239 ProcessMetrics::ProcessMetrics(ProcessHandle process) |
243 : process_(process), | 240 : process_(process), |
244 processor_count_(base::SysInfo::NumberOfProcessors()), | 241 processor_count_(base::SysInfo::NumberOfProcessors()), |
245 last_system_time_(0) { | 242 last_system_time_(0) { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 return 0; | 279 return 0; |
283 } | 280 } |
284 return (info.CommitTotal * system_info.dwPageSize) / 1024; | 281 return (info.CommitTotal * system_info.dwPageSize) / 1024; |
285 } | 282 } |
286 | 283 |
287 size_t GetPageSize() { | 284 size_t GetPageSize() { |
288 return PAGESIZE_KB * 1024; | 285 return PAGESIZE_KB * 1024; |
289 } | 286 } |
290 | 287 |
291 } // namespace base | 288 } // namespace base |
OLD | NEW |