Identifies a device hardware subsystem that can report energy consumption through EnergyUsage.
Pass a value from this enum to EnergyUsage.Get to read how much energy a single subsystem consumed
since energy-usage tracking was started or reset with IEnergyUsageControl.StartEnergyUsageTracking.
Each subsystem reports independently of the others, because devices expose different sets of power monitors.
A platform reports only the subsystems its monitors cover and returns an unavailable reading for the rest, so
check EnergyUsageReading.Available on each reading before you use its values instead of assuming
that a subsystem missing on one device is missing on all devices.
The following example tracks energy usage while a component is enabled and logs how much energy the CPU
subsystem consumed since tracking started.
using UnityEngine; using UnityEngine.AdaptivePerformance;
public class CpuEnergyUsageExample : MonoBehaviour { IAdaptivePerformance adaptivePerformance; IEnergyUsageControl energyUsageControl;
void OnEnable() { adaptivePerformance = Holder.Instance; if (adaptivePerformance == null || !adaptivePerformance.Initialized) return;
energyUsageControl = adaptivePerformance.EnergyUsageControl(); if (energyUsageControl == null || !energyUsageControl.StartEnergyUsageTracking()) Debug.Log("Energy-usage tracking isn't available on this device."); }
void Update() { if (energyUsageControl == null || !energyUsageControl.EnergyUsageTrackingActive) return;
EnergyUsage energyUsage = adaptivePerformance.PerformanceStatus.PerformanceMetrics.EnergyUsage; EnergyUsageReading reading = energyUsage.Get(EnergyUsageSubsystem.Cpu);
// This device doesn't report energy for this subsystem, so skip it. if (!reading.Available) return;
Debug.Log($"The CPU used {reading.Energy} microwatt-seconds over {reading.Interval} ms."); }
void OnDisable() { energyUsageControl?.StopEnergyUsageTracking(); } }