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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/api/system_info_cpu/cpu_info_provider_win.cc
diff --git a/chrome/browser/extensions/api/system_info_cpu/cpu_info_provider_win.cc b/chrome/browser/extensions/api/system_info_cpu/cpu_info_provider_win.cc
index 7a9e086cb03bbfcc4786c00908242fefc30f12ca..0490b54e8d3ea439cec8544ad2c8c4ebbcb96121 100644
--- a/chrome/browser/extensions/api/system_info_cpu/cpu_info_provider_win.cc
+++ b/chrome/browser/extensions/api/system_info_cpu/cpu_info_provider_win.cc
@@ -4,11 +4,70 @@
#include "chrome/browser/extensions/api/system_info_cpu/cpu_info_provider.h"
+#include <windows.h>
+#include <winternl.h>
+
+#include "base/sys_info.h"
+
namespace extensions {
+namespace {
+
+const wchar_t kNtdll[] = L"ntdll.dll";
+const char kNtQuerySystemInformationName[] = "NtQuerySystemInformation";
+
+// See MSDN about NtQuerySystemInformation definition.
+typedef DWORD (WINAPI *NtQuerySystemInformationPF)(DWORD system_info_class,
+ PVOID system_info,
+ ULONG system_info_length,
+ PULONG return_length);
+
+} // namespace
+
bool CpuInfoProvider::QueryCpuTimePerProcessor(std::vector<CpuTime>* times) {
- // TODO(hongbo): use NtQuerySystemInformation to query the cpu time.
- return false;
+ 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.
+ return false;
+
+ std::vector<CpuTime> results;
+
+ HMODULE ntdll = GetModuleHandle(kNtdll);
+ DCHECK(ntdll != NULL);
alexeypa (please no reviews) 2012/09/12 15:41:55 DCHECK -> CHECK
Hongbo Min 2012/09/13 13:16:59 Done.
+ NtQuerySystemInformationPF NtQuerySystemInformation =
+ reinterpret_cast<NtQuerySystemInformationPF>(
+ ::GetProcAddress(ntdll, kNtQuerySystemInformationName));
+
+ 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.
+ return false;
+
+ int num_of_processors = base::SysInfo::NumberOfProcessors();
+ scoped_array<SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION> processor_info(
+ new SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION[num_of_processors]);
+
+ 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.
+ ULONG returned_bytes = 0;
+ bytes = sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION) * num_of_processors;
+ 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.
+ processor_info.get(),
+ bytes,
+ &returned_bytes) != 0)
+ return false;
+
+ int returned_num_of_processors =
+ returned_bytes / sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION);
+ 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
+ if (returned_num_of_processors != num_of_processors)
+ return false;
+
+ 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.
+ CpuTime time;
+ time.kernel = processor_info[i].KernelTime.QuadPart;
+ time.user = processor_info[i].UserTime.QuadPart;
+ time.idle = processor_info[i].IdleTime.QuadPart;
+ results.push_back(time);
+ }
+
+ results.swap(*times);
+ return true;
}
} // namespace extensions
« 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