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

Side by Side Diff: chrome/browser/extensions/api/system_info_cpu/cpu_info_provider_mac.cc

Issue 16295015: Remove onUpdate from systemInfo.cpu API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 6 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/extensions/api/system_info_cpu/cpu_info_provider.h"
6
7 #include <mach/mach_host.h>
8
9 #include "base/mac/scoped_mach_port.h"
10
11 namespace extensions {
12
13 bool CpuInfoProvider::QueryCpuTimePerProcessor(std::vector<CpuTime>* times) {
14 natural_t num_of_processors;
15 base::mac::ScopedMachPort host(mach_host_self());
16 mach_msg_type_number_t type;
17 processor_cpu_load_info_data_t* cpu_infos;
18
19 if (host_processor_info(host.get(),
20 PROCESSOR_CPU_LOAD_INFO,
21 &num_of_processors,
22 reinterpret_cast<processor_info_array_t*>(&cpu_infos),
23 &type) == KERN_SUCCESS) {
24 std::vector<CpuTime> results;
25 int64 user = 0, nice = 0, sys = 0, idle = 0;
26
27 for (natural_t i = 0; i < num_of_processors; ++i) {
28 CpuTime time;
29
30 user = static_cast<int64>(cpu_infos[i].cpu_ticks[CPU_STATE_USER]);
31 sys = static_cast<int64>(cpu_infos[i].cpu_ticks[CPU_STATE_SYSTEM]);
32 nice = static_cast<int64>(cpu_infos[i].cpu_ticks[CPU_STATE_NICE]);
33 idle = static_cast<int64>(cpu_infos[i].cpu_ticks[CPU_STATE_IDLE]);
34
35 time.kernel = sys;
36 time.user = user + nice;
37 time.idle = idle;
38 results.push_back(time);
39 }
40
41 vm_deallocate(mach_task_self(),
42 reinterpret_cast<vm_address_t>(cpu_infos),
43 num_of_processors * sizeof(processor_cpu_load_info));
44
45 times->swap(results);
46 return true;
47 }
48
49 return false;
50 }
51
52 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698