• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // 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 
22 namespace webrtc {
23 class ConditionVariableWrapper;
24 class CriticalSectionWrapper;
25 class EventWrapper;
26 class ThreadWrapper;
27 
28 class CpuWindows : public CpuWrapper
29 {
30 public:
31     virtual WebRtc_Word32 CpuUsage();
CpuUsage(WebRtc_Word8 *,WebRtc_UWord32)32     virtual WebRtc_Word32 CpuUsage(WebRtc_Word8* /*pProcessName*/,
33                                    WebRtc_UWord32 /*length*/) {return -1;}
CpuUsage(WebRtc_UWord32)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 
Reset()39     virtual void Reset() {}
Stop()40     virtual void Stop() {}
41 
42     CpuWindows();
43     virtual ~CpuWindows();
44 private:
45     bool AllocateComplexDataTypes();
46     void DeAllocateComplexDataTypes();
47 
48     void StartPollingCpu();
49     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_
104