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 <mach/mach.h> | 7 #include <mach/mach.h> |
8 #include <mach/mach_vm.h> | 8 #include <mach/mach_vm.h> |
9 #include <mach/shared_region.h> | 9 #include <mach/shared_region.h> |
10 #include <sys/sysctl.h> | 10 #include <sys/sysctl.h> |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 mach_msg_type_number_t power_info_count = TASK_POWER_INFO_COUNT; | 292 mach_msg_type_number_t power_info_count = TASK_POWER_INFO_COUNT; |
293 kern_return_t kr = task_info(task, | 293 kern_return_t kr = task_info(task, |
294 TASK_POWER_INFO, | 294 TASK_POWER_INFO, |
295 reinterpret_cast<task_info_t>(&power_info_data), | 295 reinterpret_cast<task_info_t>(&power_info_data), |
296 &power_info_count); | 296 &power_info_count); |
297 if (kr != KERN_SUCCESS) { | 297 if (kr != KERN_SUCCESS) { |
298 // Most likely cause: |task| is a zombie, or this is on a pre-10.8.4 system | 298 // Most likely cause: |task| is a zombie, or this is on a pre-10.8.4 system |
299 // where TASK_POWER_INFO isn't supported yet. | 299 // where TASK_POWER_INFO isn't supported yet. |
300 return 0; | 300 return 0; |
301 } | 301 } |
302 uint64_t absolute_idle_wakeups = power_info_data.task_platform_idle_wakeups; | 302 return CalculateIdleWakeupsPerSecond( |
303 | 303 power_info_data.task_platform_idle_wakeups); |
304 TimeTicks time = TimeTicks::Now(); | |
305 | |
306 if (last_absolute_idle_wakeups_ == 0) { | |
307 // First call, just set the last values. | |
308 last_idle_wakeups_time_ = time; | |
309 last_absolute_idle_wakeups_ = absolute_idle_wakeups; | |
310 return 0; | |
311 } | |
312 | |
313 int64 wakeups_delta = absolute_idle_wakeups - last_absolute_idle_wakeups_; | |
314 int64 time_delta = (time - last_idle_wakeups_time_).InMicroseconds(); | |
315 if (time_delta == 0) { | |
316 NOTREACHED(); | |
317 return 0; | |
318 } | |
319 | |
320 last_idle_wakeups_time_ = time; | |
321 last_absolute_idle_wakeups_ = absolute_idle_wakeups; | |
322 | |
323 // Round to average wakeups per second. | |
324 const int kMicrosecondsPerSecond = 1000 * 1000; | |
325 return (wakeups_delta * kMicrosecondsPerSecond + time_delta/2) / time_delta; | |
326 } | 304 } |
327 | 305 |
328 bool ProcessMetrics::GetIOCounters(IoCounters* io_counters) const { | 306 bool ProcessMetrics::GetIOCounters(IoCounters* io_counters) const { |
329 return false; | 307 return false; |
330 } | 308 } |
331 | 309 |
332 ProcessMetrics::ProcessMetrics(ProcessHandle process, | 310 ProcessMetrics::ProcessMetrics(ProcessHandle process, |
333 ProcessMetrics::PortProvider* port_provider) | 311 ProcessMetrics::PortProvider* port_provider) |
334 : process_(process), | 312 : process_(process), |
335 last_system_time_(0), | 313 last_system_time_(0), |
(...skipping 21 matching lines...) Expand all Loading... |
357 &count); | 335 &count); |
358 if (kr != KERN_SUCCESS) { | 336 if (kr != KERN_SUCCESS) { |
359 MACH_DLOG(WARNING, kr) << "host_statistics"; | 337 MACH_DLOG(WARNING, kr) << "host_statistics"; |
360 return 0; | 338 return 0; |
361 } | 339 } |
362 | 340 |
363 return (data.active_count * PAGE_SIZE) / 1024; | 341 return (data.active_count * PAGE_SIZE) / 1024; |
364 } | 342 } |
365 | 343 |
366 } // namespace base | 344 } // namespace base |
OLD | NEW |