/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include"PowerCounters.h" #include"nsXULAppAPI.h"// for XRE_IsParentProcess #include"nsString.h"
#include <windows.h> #include <devioctl.h> #include <setupapi.h> // for SetupDi* // LogSeverity, defined by setupapi.h to DWORD, messes with other code. #undef LogSeverity
#include <emi.h>
usingnamespace mozilla;
// This is a counter to collect power utilization during profiling. // It cannot be a raw `ProfilerCounter` because we need to manually add/remove // it while the profiler lock is already held. class PowerMeterChannel final : public BaseProfilerCount { public: explicit PowerMeterChannel(const WCHAR* aChannelName, ULONGLONG aInitialValue,
ULONGLONG aInitialTime)
: BaseProfilerCount(nullptr, "power", "Power utilization"),
mChannelName(NS_ConvertUTF16toUTF8(aChannelName)),
mPreviousValue(aInitialValue),
mPreviousTime(aInitialTime),
mIsSampleNew(true) { if (mChannelName.Equals("RAPL_Package0_PKG")) {
mLabel = "Power: CPU package";
mDescription = mChannelName.get();
} elseif (mChannelName.Equals("RAPL_Package0_PP0")) {
mLabel = "Power: CPU cores";
mDescription = mChannelName.get();
} elseif (mChannelName.Equals("RAPL_Package0_PP1")) {
mLabel = "Power: iGPU";
mDescription = mChannelName.get();
} elseif (mChannelName.Equals("RAPL_Package0_DRAM")) {
mLabel = "Power: DRAM";
mDescription = mChannelName.get();
} else { unsignedint coreId; if (sscanf(mChannelName.get(), "RAPL_Package0_Core%u_CORE", &coreId) ==
1) {
mLabelString = "Power: CPU core ";
mLabelString.AppendInt(coreId);
mLabel = mLabelString.get();
mDescription = mChannelName.get();
} else {
mLabel = mChannelName.get();
}
}
}
void AddSample(ULONGLONG aAbsoluteEnergy, ULONGLONG aAbsoluteTime) { // aAbsoluteTime is the time since the system start in 100ns increments. if (aAbsoluteTime == mPreviousTime) { return;
}
if (!XRE_IsParentProcess()) { // Energy meters are global, so only sample them on the parent. return;
}
// Energy Metering Device Interface // {45BD8344-7ED6-49cf-A440-C276C933B053} // // Using GUID_DEVICE_ENERGY_METER does not compile as the symbol does not // exist before Windows 10.
GUID my_GUID_DEVICE_ENERGY_METER = {
0x45bd8344,
0x7ed6,
0x49cf,
{0xa4, 0x40, 0xc2, 0x76, 0xc9, 0x33, 0xb0, 0x53}};
UniquePtr<PowerMeterDevice> pmd =
MakeUnique<PowerMeterDevice>(pdidd->DevicePath); if (!pmd->HasChannels() ||
!mPowerMeterDevices.emplaceBack(std::move(pmd))) {
NS_WARNING("PowerMeterDevice without measurement channel (or OOM)");
}
}
for (auto& device : mPowerMeterDevices) {
device->AppendCountersTo(mCounters);
}
}
// This default destructor can not be defined in the header file as it depends // on the full definition of PowerMeterDevice which lives in this file.
PowerCounters::~PowerCounters() {}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.