Skip to content

Way to track the frozen frames #1

@hellosagar

Description

@hellosagar
val aggregator: FrameMetricsAggregator = FrameMetricsAggregator()
  private var totalFrames = 0L
  private var slowFrames = 0L
  private var frozenFrames = 0L
  
   override fun onStart() {
    super.onStart()
    this.lifecycleScope.launch(Dispatchers.Default) {
      aggregator.add(this@MainActivity)
    }
  }
  
  override fun onStop() {
    super.onStop()

    this.lifecycleScope.launch(Dispatchers.Default) {
      val data = aggregator.metrics ?: return@launch

      totalFrames = 0L
      slowFrames = 0L
      frozenFrames = 0L

      data[FrameMetricsAggregator.TOTAL_INDEX].let { distributions ->
        for (i in 0 until distributions.size()) {
          val duration = distributions.keyAt(i)
          val frameCount = distributions.valueAt(i)
          totalFrames += frameCount
          if (duration > 16)
            slowFrames += frameCount
          if (duration > 700)
            frozenFrames += frameCount
        }
      }
      aggregator.reset()
      println("totalFrames: $totalFrames, slowFrames: $slowFrames, frozenFrames: $frozenFrames")
    }
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions