blob: d15073c0bad44cdcc3798365870813a4bd8f107e [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001// This file contains a Windows implementation of CpuWrapper.
2// Note: Windows XP, Windows Server 2003 are the minimum requirements.
3// The requirements are due to the implementation being based on
4// WMI.
5/*
6 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
7 *
8 * Use of this source code is governed by a BSD-style license
9 * that can be found in the LICENSE file in the root of the source
10 * tree. An additional intellectual property rights grant can be found
11 * in the file PATENTS. All contributing project authors may
12 * be found in the AUTHORS file in the root of the source tree.
13 */
14
15#ifndef WEBRTC_SYSTEM_WRAPPERS_SOURCE_CPU_WINDOWS_NO_CPOL_H_
16#define WEBRTC_SYSTEM_WRAPPERS_SOURCE_CPU_WINDOWS_NO_CPOL_H_
17
18#include "cpu_wrapper.h"
19
20#include <Wbemidl.h>
21
22namespace webrtc {
23class ConditionVariableWrapper;
24class CriticalSectionWrapper;
25class EventWrapper;
26class ThreadWrapper;
27
28class CpuWindows : public CpuWrapper
29{
30public:
31 virtual WebRtc_Word32 CpuUsage();
32 virtual WebRtc_Word32 CpuUsage(WebRtc_Word8* /*pProcessName*/,
33 WebRtc_UWord32 /*length*/) {return -1;}
34 virtual WebRtc_Word32 CpuUsage(WebRtc_UWord32 /*dwProcessID*/) {return -1;}
35
36 virtual WebRtc_Word32 CpuUsageMultiCore(WebRtc_UWord32& num_cores,
37 WebRtc_UWord32*& cpu_usage);
38
39 virtual void Reset() {}
40 virtual void Stop() {}
41
42 CpuWindows();
43 virtual ~CpuWindows();
44private:
45 bool AllocateComplexDataTypes();
46 void DeAllocateComplexDataTypes();
47
henrike@webrtc.org3798ecb2011-11-18 16:25:54 +000048 void StartPollingCpu();
niklase@google.com470e71d2011-07-07 08:21:25 +000049 bool StopPollingCpu();
50
51 static bool Process(void* thread_object);
52 bool ProcessImpl();
53
54 bool CreateWmiConnection();
55 bool CreatePerfOsRefresher();
56 bool CreatePerfOsCpuHandles();
57 bool Initialize();
58 bool Terminate();
59
60 bool UpdateCpuUsage();
61
62 ThreadWrapper* cpu_polling_thread;
63
64 bool initialize_;
65 bool has_initialized_;
66 CriticalSectionWrapper* init_crit_;
67 ConditionVariableWrapper* init_cond_;
68
69 bool terminate_;
70 bool has_terminated_;
71 CriticalSectionWrapper* terminate_crit_;
72 ConditionVariableWrapper* terminate_cond_;
73
74 // For sleep with wake-up functionality.
75 EventWrapper* sleep_event;
76
77 // Will be an array. Just care about CPU 0 for now.
78 WebRtc_UWord32* cpu_usage_;
79
80 // One IWbemObjectAccess for each processor and one for the total.
81 // 0-n-1 is the individual processors.
82 // n is the total.
83 IWbemObjectAccess** wbem_enum_access_;
84 DWORD number_of_objects_;
85
86 // Cpu timestamp
87 long cpu_usage_handle_;
88 unsigned __int64* previous_processor_timestamp_;
89
90 // Timestamp
91 long timestamp_sys_100_ns_handle_;
92 unsigned __int64* previous_100ns_timestamp_;
93
94 IWbemServices* wbem_service_;
95 IWbemServices* wbem_service_proxy_;
96
97 IWbemRefresher* wbem_refresher_;
98
99 IWbemHiPerfEnum* wbem_enum_;
100
101};
102} // namespace webrtc
103#endif // WEBRTC_SYSTEM_WRAPPERS_SOURCE_CPU_WINDOWS_NO_CPOL_H_