Bug 1931425 - Limit how often moz-label's #setStyles runs r=reusable-components-revie...
[gecko.git] / tools / profiler / core / ProfilerCPUFreq.h
blob00a1e596b227a671244d110c6ebb874b2ce22f7b
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #ifndef TOOLS_PROFILERCPUFREQ_H_
6 #define TOOLS_PROFILERCPUFREQ_H_
8 #include "PlatformMacros.h"
9 #include "mozilla/UniquePtr.h"
10 #include "mozilla/Vector.h"
12 #if defined(GP_OS_windows) || defined(GP_OS_linux) || defined(GP_OS_android)
13 # define HAVE_CPU_FREQ_SUPPORT
14 #endif
16 #if defined(GP_OS_windows)
17 # include <windows.h>
19 struct CPUCounterInfo {
20 ULONGLONG data = 0;
21 DWORD base = 0;
22 uint32_t freq = 0;
23 DWORD nominalFrequency = 0;
25 #endif
27 #if defined(GP_OS_linux) || defined(GP_OS_android)
28 struct CPUCounterInfo {
29 int fd = 0;
31 #endif
33 class ProfilerCPUFreq {
34 public:
35 #if defined(HAVE_CPU_FREQ_SUPPORT)
36 explicit ProfilerCPUFreq();
37 ~ProfilerCPUFreq();
38 # if defined(GP_OS_windows)
39 void Sample();
40 uint32_t GetCPUSpeedMHz(unsigned cpuId) {
41 MOZ_ASSERT(cpuId < mCPUCounters.length());
42 return mCPUCounters[cpuId].freq;
44 # else
45 void Sample() {}
46 uint32_t GetCPUSpeedMHz(unsigned cpuId);
47 # endif
48 #else
49 explicit ProfilerCPUFreq() {};
50 ~ProfilerCPUFreq() {};
51 void Sample() {};
52 #endif
54 private:
55 #if defined(HAVE_CPU_FREQ_SUPPORT)
56 # if defined(GP_OS_windows)
57 LPWSTR mBlockIndex = nullptr;
58 DWORD mCounterNameIndex = 0;
59 // The size of the counter block is about 8kB for a machine with 20 cores,
60 // so 32kB should be plenty.
61 DWORD mBufferSize = 32768;
62 LPBYTE mBuffer = nullptr;
63 # endif
64 mozilla::Vector<CPUCounterInfo> mCPUCounters;
65 #endif
68 #endif /* ndef TOOLS_PROFILERCPUFREQ_H_ */