instrumentsbatteryios15xcode13

How to measure energy usage in Xcode 13 / iOS15?


I'd like to confirm the battery usage of an app I am developing on iOS, specifically on Xcode 13 and iOS 15. (Note: This app previously showed no issues with battery usage on previous versions of iOS.)

Previously, it seems that there were two ways to gather energy usage information:

#1. On the device under Settings > Developer > Logging

#2. Profiling via Instruments using the "Energy Log" template

Digging through the Xcode 13 release notes, I found the following:

Instruments no longer includes the Energy template; use metrics reporting in the Xcode Organizer instead. (74161279)

When I access the Organizer in Xcode (12 or 13), select an app and click "Energy" for all versions of the app, it shows the following:

No Energy Logs Reported

Apple's documentation for "Analyzing the Performance of Your Shipping App" says:

"In some cases the pane shows “Insufficient usage data available,” because there may not be enough anonymized data reported by participating user devices. When this happens, try checking back in a few days."

Well over a year into production and having sufficient install numbers, I have a feeling that waiting a few days might not do much.

I would like to determine if this is a bug in my app or a bug in iOS15. How can energy usage data be gathered using Xcode 13 on iOS 15?


Solution

  • After contacting Apple Developer Technical Support (DTS) regarding this issue, they provided me with the following guidance:

    Regarding "insufficient usage data available" for energy logs (or reports) accessible via the Xcode Energy Organizer:

    DTS indicated that they do not publish the thresholds for active users, and usage logs would be expected to be present if you consistently have more than a few thousand active users on each app version. If your app meets this criteria and still does not show energy logs, DTS recommends opening a bug report with them.

    Note the "Energy Organizer" is accessed in Xcode via the Window toolbar → Organizer → Reports → Energy.

    Regarding how to collect energy log data for your app:

    DTS recommended using MetricKit to get daily metric payloads. Payloads are delivered to your app every 24 hours, and it is then possible to consume them and send them off the device.

    The instantiation of this is:

    import MetricKit
    
    ...
    
    // Somewhere in your application startup sequence:
    MXMetricManager.shared.add(someObjectYouWantToHaveThisResponsibility)
    
    ...
    
    extension SomeObjectYouWantToHaveThisResponsibility: MXMetricManagerSubscriber {
       func didReceive(_ payloads: [MXMetricPayload]) {
           for payload in payloads {
               // Parse the payload here
           }
       }
    }
    

    For a full list of metrics, see the MXMetricPayload class.

    Regarding the two documentation links that I included above:

    Apple asked me to open feedback tickets to get them updated. I opened both tickets (FB9665186, FB9665194) on September 30, 2021 and they are both still in an "Open" status as of today.

    In the case of my app and the problem I had encountered, it turns out that battery drain was just a symptom and not the actual problem, so it wouldn't be helpful to include any of those details here.

    Apple Documentation (as of Jan 2024)