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

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

Issue 10916197: Implement querying CPU time on Windows for systemInfo.cpu API (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: updated patch Created 8 years, 3 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
« no previous file with comments | « chrome/browser/extensions/api/system_info_cpu/cpu_info_provider.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "chrome/browser/extensions/api/system_info_cpu/cpu_info_provider.h" 5 #include "chrome/browser/extensions/api/system_info_cpu/cpu_info_provider.h"
6 6
7 #include <windows.h>
8 #include <winternl.h>
9
10 #include "base/sys_info.h"
11
7 namespace extensions { 12 namespace extensions {
8 13
14 namespace {
15
16 const wchar_t kNtdll[] = L"ntdll.dll";
17 const char kNtQuerySystemInformationName[] = "NtQuerySystemInformation";
18
19 // See MSDN about NtQuerySystemInformation definition.
20 typedef DWORD (WINAPI *NtQuerySystemInformationPF)(DWORD system_info_class,
21 PVOID system_info,
22 ULONG system_info_length,
23 PULONG return_length);
24
25 } // namespace
26
9 bool CpuInfoProvider::QueryCpuTimePerProcessor(std::vector<CpuTime>* times) { 27 bool CpuInfoProvider::QueryCpuTimePerProcessor(std::vector<CpuTime>* times) {
10 // TODO(hongbo): use NtQuerySystemInformation to query the cpu time. 28 if (!times)
alexeypa (please no reviews) 2012/09/12 15:41:55 Actually, you don't need to test |times| for being
Hongbo Min 2012/09/13 13:16:59 What does AV stand for? Although it is too easy, i
alexeypa (please no reviews) 2012/09/13 16:45:48 Access violation.
11 return false; 29 return false;
30
31 std::vector<CpuTime> results;
32
33 HMODULE ntdll = GetModuleHandle(kNtdll);
34 DCHECK(ntdll != NULL);
alexeypa (please no reviews) 2012/09/12 15:41:55 DCHECK -> CHECK
Hongbo Min 2012/09/13 13:16:59 Done.
35 NtQuerySystemInformationPF NtQuerySystemInformation =
36 reinterpret_cast<NtQuerySystemInformationPF>(
37 ::GetProcAddress(ntdll, kNtQuerySystemInformationName));
38
39 if (!NtQuerySystemInformation)
alexeypa (please no reviews) 2012/09/12 15:41:55 This also can be CHECK(NtQuerySystemInformation !=
Hongbo Min 2012/09/13 13:16:59 Done.
40 return false;
41
42 int num_of_processors = base::SysInfo::NumberOfProcessors();
43 scoped_array<SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION> processor_info(
44 new SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION[num_of_processors]);
45
46 ULONG bytes = 0;
alexeypa (please no reviews) 2012/09/12 15:41:55 You can merge this line with line #48.
Hongbo Min 2012/09/13 13:16:59 Done.
47 ULONG returned_bytes = 0;
48 bytes = sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION) * num_of_processors;
49 if (NtQuerySystemInformation(SystemProcessorPerformanceInformation,
alexeypa (please no reviews) 2012/09/12 15:41:55 Use NT_SUCCESS macro to test whether NtQuerySystem
Hongbo Min 2012/09/13 13:16:59 Done.
50 processor_info.get(),
51 bytes,
52 &returned_bytes) != 0)
53 return false;
54
55 int returned_num_of_processors =
56 returned_bytes / sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION);
57 DCHECK(returned_num_of_processors == num_of_processors);
alexeypa (please no reviews) 2012/09/12 15:41:55 Remove this DCHECK. It is legal (though unlikely)
Hongbo Min 2012/09/13 13:16:59 Removed the DCHECK stmt, but still return false if
58 if (returned_num_of_processors != num_of_processors)
59 return false;
60
61 for (int i = 0; i < returned_num_of_processors; ++i) {
alexeypa (please no reviews) 2012/09/12 15:41:55 Since you know the number of elements you are goin
Hongbo Min 2012/09/13 13:16:59 Done.
62 CpuTime time;
63 time.kernel = processor_info[i].KernelTime.QuadPart;
64 time.user = processor_info[i].UserTime.QuadPart;
65 time.idle = processor_info[i].IdleTime.QuadPart;
66 results.push_back(time);
67 }
68
69 results.swap(*times);
70 return true;
12 } 71 }
13 72
14 } // namespace extensions 73 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/system_info_cpu/cpu_info_provider.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698