Version: Unity 6.7 Beta (6000.7)
LanguageEnglish
  • C#

EnergyUsageReading

struct in UnityEngine.AdaptivePerformance

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Description

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.

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.

Additional resources: EnergyUsage, EnergyUsageSubsystem, IEnergyUsageControl

The following example tracks energy usage while a component is enabled and logs the average power the GPU subsystem drew since tracking started.

 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(); } }

Properties

Property Description
Available True if the device reported data for this subsystem in the current sample, false otherwise. When false, EnergyUsageReading.Energy and EnergyUsageReading.Interval are not meaningful.
Energy The energy consumed in microwatt-seconds since energy-usage tracking was started or reset.
Interval The 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.

Constructors

Constructor Description
EnergyUsageReading Initializes a new EnergyUsageReading.