Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


EnergyUsageReading

The energy consumed by a single device subsystem since energy-usage tracking was started or reset, together with the time interval over which it was measured.
Read time 2 minutesLast updated 6 days ago

Definition

public readonly struct EnergyUsageReading

Remarks

Get a reading for a subsystem with EnergyUsage.Get. Readings are cumulative rather than absolute: EnergyUsageReading.Energy covers the period that starts when tracking was started or reset with IEnergyUsageControl.StartEnergyUsageTracking and ends when the system last updated the reading, and EnergyUsageReading.Interval is the length of that same period.
Check EnergyUsageReading.Available first, because it gates the other two values: when it's false, the device didn't report this subsystem and EnergyUsageReading.Energy and EnergyUsageReading.Interval are meaningless. Divide EnergyUsageReading.Energy by EnergyUsageReading.Interval to get the average power the subsystem drew over the period, in milliwatts.
The following example tracks energy usage while a component is enabled and logs the average power the GPU subsystem drew since tracking started.

Examples

using UnityEngine;using UnityEngine.AdaptivePerformance;public class GpuEnergyReadingExample : 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.Gpu); // Energy and Interval are only meaningful when the device reported this subsystem. if (!reading.Available) return; // Microwatt-seconds divided by milliseconds gives average power in milliwatts. float averagePower = (float)reading.Energy / reading.Interval; Debug.Log($"The GPU averaged {averagePower} mW since tracking started."); } void OnDisable() { energyUsageControl?.StopEnergyUsageTracking(); }}

Constructors

Properties

Property

Description

AvailableTrue if the device reported data for this subsystem in the current sample, false otherwise. When false, EnergyUsageReading.Energy and EnergyUsageReading.Interval are not meaningful.
EnergyThe energy consumed in microwatt-seconds since energy-usage tracking was started or reset.
IntervalThe measurement interval in milliseconds that EnergyUsageReading.Energy covers, measured from the start or last reset of energy-usage tracking until the system last updated the reading.