How to get MetricKit SignPost Metrics data formulated into battery usage % for feature wise usage in iOS app?

21 Views Asked by At

I am trying to access feature-wise battery usage in my app. For this I used MetricKit and put signposts at start and end of a flow of feature. I got one of the payloads like this:

{
      "signpostIntervalData" : {
        "histogrammedSignpostDurations" : {
          "histogramNumBuckets" : 4,
          "histogramValue" : {
            "3" : {
              "bucketCount" : 1,
              "bucketStart" : "40000 ms",
              "bucketEnd" : "40099 ms"
            },
            "1" : {
              "bucketCount" : 1,
              "bucketStart" : "6100 ms",
              "bucketEnd" : "6199 ms"
            },
            "2" : {
              "bucketCount" : 1,
              "bucketStart" : "6700 ms",
              "bucketEnd" : "6799 ms"
            },
            "0" : {
              "bucketCount" : 1,
              "bucketStart" : "2800 ms",
              "bucketEnd" : "2899 ms"
            }
          }
        },
        "signpostCumulativeCPUTime" : "9049 ms",
        "signpostAverageMemory" : "180842 kB",
        "signpostCumulativeLogicalWrites" : "10436 kB"
      },
      "signpostCategory" : "My feature in app",
      "signpostName" : "My feature flow",
      "totalSignpostCount" : 4
    }

As above, All I have got from signpost metrics is :

 "signpostCumulativeCPUTime" : "9049 ms",
 "signpostAverageMemory" : "180842 kB",
 "signpostCumulativeLogicalWrites" : "10436 kB"

I am unable to formulate on basis of this information, how much of battery consumption happened for the usage of this feature in this particular usage scenario. Can anyone suggest if I am missing some key to be set while initiating signpost to get direct battery consumption, or if not, how can I translate this limited raw information that I got from MetricKit payload into battery consumption % for this particular usage?

I have initiated and ended signPosts for MetricKit for feature usage as follows:

let featureLogHandle  = MXMetricManager.makeLogHandle(category: "My feature in app")

mxSignpost(.begin, log: featureLogHandle!, name: "My feature flow")

mxSignpost(.end, log: featureLogHandle!, name: "My feature flow")


Complete Payload response:

{
  "locationActivityMetrics" : {
    "cumulativeBestAccuracyForNavigationTime" : "0 sec",
    "cumulativeBestAccuracyTime" : "331 sec",
    "cumulativeHundredMetersAccuracyTime" : "0 sec",
    "cumulativeNearestTenMetersAccuracyTime" : "0 sec",
    "cumulativeKilometerAccuracyTime" : "0 sec",
    "cumulativeThreeKilometersAccuracyTime" : "0 sec"
  },
  "cellularConditionMetrics" : {
    "cellConditionTime" : {
      "histogramNumBuckets" : 1,
      "histogramValue" : {
        "0" : {
          "bucketCount" : 100,
          "bucketStart" : "0 bars",
          "bucketEnd" : "0 bars"
        }
      }
    }
  },
  "metaData" : {
    "appBuildVersion" : "120",
    "osVersion" : "iPhone OS 16.5.1",
    "regionFormat" : "My Nation",
    "platformArchitecture" : "arm64e",
    "bundleIdentifier" : "com.help.me",
    "deviceType" : "iPhone13,2"
  },
  "gpuMetrics" : {
    "cumulativeGPUTime" : "4 sec"
  },
  "memoryMetrics" : {
    "peakMemoryUsage" : "577699 kB",
    "averageSuspendedMemory" : {
      "averageValue" : "168279 kB",
      "standardDeviation" : 125806.6191229174784,
      "sampleCount" : 17
    }
  },
  "applicationExitMetrics" : {
    "backgroundExitData" : {
      "cumulativeNormalAppExitCount" : 2
    },
    "foregroundExitData" : {

    }
  },
  "displayMetrics" : {
    "averagePixelLuminance" : {
      "averageValue" : "69 apl",
      "standardDeviation" : -1,
      "sampleCount" : 16309
    }
  },
  "signpostMetrics" : [
    {
      "signpostIntervalData" : {
        "histogrammedSignpostDurations" : {
          "histogramNumBuckets" : 4,
          "histogramValue" : {
            "3" : {
              "bucketCount" : 1,
              "bucketStart" : "40000 ms",
              "bucketEnd" : "40099 ms"
            },
            "1" : {
              "bucketCount" : 1,
              "bucketStart" : "6100 ms",
              "bucketEnd" : "6199 ms"
            },
            "2" : {
              "bucketCount" : 1,
              "bucketStart" : "6700 ms",
              "bucketEnd" : "6799 ms"
            },
            "0" : {
              "bucketCount" : 1,
              "bucketStart" : "2800 ms",
              "bucketEnd" : "2899 ms"
            }
          }
        },
        "signpostCumulativeCPUTime" : "9049 ms",
        "signpostAverageMemory" : "180842 kB",
        "signpostCumulativeLogicalWrites" : "10436 kB"
      },
      "signpostCategory" : "My feature in app",
      "signpostName" : "My feature flow",
      "totalSignpostCount" : 4
    },
    {
      "signpostIntervalData" : {
        "histogrammedSignpostDurations" : {
          "histogramNumBuckets" : 1,
          "histogramValue" : {
            "0" : {
              "bucketCount" : 1,
              "bucketStart" : "53800 ms",
              "bucketEnd" : "53899 ms"
            }
          }
        },
        "signpostCumulativeCPUTime" : "7966 ms",
        "signpostAverageMemory" : "224258 kB",
        "signpostCumulativeLogicalWrites" : "14572 kB"
      },
      "signpostCategory" : "My feature in app 2",
      "signpostName" : "My feature flow 2",
      "totalSignpostCount" : 1
    },
    {
      "signpostCategory" : "Help",
      "totalSignpostCount" : 1,
      "signpostName" : "Help me"
    }
  ],
  "cpuMetrics" : {
    "cumulativeCPUTime" : "50 sec",
    "cumulativeCPUInstructions" : "106189176 kiloinstructions"
  },
  "networkTransferMetrics" : {
    "cumulativeCellularDownload" : "0 kB",
    "cumulativeWifiDownload" : "149238 kB",
    "cumulativeCellularUpload" : "0 kB",
    "cumulativeWifiUpload" : "2954 kB"
  },
  "diskIOMetrics" : {
    "cumulativeLogicalWrites" : "174052 kB"
  },
  "applicationLaunchMetrics" : {
    "histogrammedTimeToFirstDrawKey" : {
      "histogramNumBuckets" : 2,
      "histogramValue" : {
        "0" : {
          "bucketCount" : 1,
          "bucketStart" : "410 ms",
          "bucketEnd" : "419 ms"
        },
        "1" : {
          "bucketCount" : 1,
          "bucketStart" : "1800 ms",
          "bucketEnd" : "1809 ms"
        }
      }
    },
    "histogrammedResumeTime" : {
      "histogramNumBuckets" : 3,
      "histogramValue" : {
        "0" : {
          "bucketCount" : 2,
          "bucketStart" : "10 ms",
          "bucketEnd" : "19 ms"
        },
        "1" : {
          "bucketCount" : 2,
          "bucketStart" : "20 ms",
          "bucketEnd" : "29 ms"
        },
        "2" : {
          "bucketCount" : 1,
          "bucketStart" : "50 ms",
          "bucketEnd" : "59 ms"
        }
      }
    },
    "histogrammedExtendedLaunch" : {
      "histogramNumBuckets" : 0,
      "histogramValue" : {

      }
    },
    "histogrammedOptimizedTimeToFirstDrawKey" : {
      "histogramNumBuckets" : 0,
      "histogramValue" : {

      }
    }
  },
  "applicationTimeMetrics" : {
    "cumulativeForegroundTime" : "272 sec",
    "cumulativeBackgroundTime" : "107 sec",
    "cumulativeBackgroundAudioTime" : "0 sec",
    "cumulativeBackgroundLocationTime" : "0 sec"
  },
  "timeStampEnd" : "2024-03-01 00:00:00",
  "animationMetrics" : {
    "scrollHitchTimeRatio" : "7 ms per s"
  },
  "applicationResponsivenessMetrics" : {
    "histogrammedAppHangTime" : {
      "histogramNumBuckets" : 4,
      "histogramValue" : {
        "3" : {
          "bucketCount" : 1,
          "bucketStart" : "810 ms",
          "bucketEnd" : "819 ms"
        },
        "1" : {
          "bucketCount" : 2,
          "bucketStart" : "300 ms",
          "bucketEnd" : "309 ms"
        },
        "2" : {
          "bucketCount" : 2,
          "bucketStart" : "540 ms",
          "bucketEnd" : "549 ms"
        },
        "0" : {
          "bucketCount" : 1,
          "bucketStart" : "290 ms",
          "bucketEnd" : "299 ms"
        }
      }
    }
  },
  "appVersion" : "1.2.3",
  "timeStampBegin" : "2024-02-29 00:00:00"
}
0

There are 0 best solutions below