Recently my game has shown considerable rise in frozen frames on android vitals after introduction of ads.
I want to use FrameMetricsAggregator for monitoring which ad activities are causing this issue(app rendering is based on open gl apart from ads).
I added monitoring in my code as per documentation but the results are always null if i dont specify any activity in the construtor. Since ad show calls are void return types , im not sure how to monitor those specific activities.
Any ideas about how to achieve this?
Yaay found something to help my self,
https://stackoverflow.com/a/11082332/6053599
Using the code in the above answer I can get lifecycle callbacks of ad activities ``which can be used to start and stop the trace and frame metrics.
This works like this,
When the ad is shown a new activity created and we are notified by onActivityCreated(activity,bundle)
callback, add the activity recieved in the callback into frame metrics by calling frameMetrics.add(activity)
After that when ad is closed we are notified by onActivityStop(activity)
in which simply call frameMetrics.stop()
to get the sparseArray of frame stats from which i can count the janky frames , frozen frames etc.
Will update the answer with final code if anybody is interested.