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
16 #if defined(GP_OS_windows)
19 struct CPUCounterInfo
{
23 DWORD nominalFrequency
= 0;
27 #if defined(GP_OS_linux) || defined(GP_OS_android)
28 struct CPUCounterInfo
{
33 class ProfilerCPUFreq
{
35 #if defined(HAVE_CPU_FREQ_SUPPORT)
36 explicit ProfilerCPUFreq();
38 # if defined(GP_OS_windows)
40 uint32_t GetCPUSpeedMHz(unsigned cpuId
) {
41 MOZ_ASSERT(cpuId
< mCPUCounters
.length());
42 return mCPUCounters
[cpuId
].freq
;
46 uint32_t GetCPUSpeedMHz(unsigned cpuId
);
49 explicit ProfilerCPUFreq() {};
50 ~ProfilerCPUFreq() {};
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;
64 mozilla::Vector
<CPUCounterInfo
> mCPUCounters
;
68 #endif /* ndef TOOLS_PROFILERCPUFREQ_H_ */