如何在android中测量视图或查看组充气时间?

时间:2022-06-01 23:45:00

I am looking for utility or any way how can I measure the time required for inflater to inflate some portion (view or viewgroup or whole screen) in Android.

我正在寻找实用程序或任何方式我如何测量inflater在Android中膨胀某些部分(视图或视图组或整个屏幕)所需的时间。

I know there is default feature in debug mode that shows overdraw, but I need to have measure the time taken to inflate view.

我知道调试模式中有默认功能显示透支,但我需要测量充气视图所需的时间。

What is the best way to do this. Thx.

做这个的最好方式是什么。谢谢。

2 个解决方案

#1


Check out lucasr/probe. Here is a blog post by a Facebook engineer on improving view measure time.

检查lucasr / probe。这是Facebook工程师关于改进视图测量时间的博客文章。

Hierarchy Viewer is also a useful visual tool to see which part of your layout can be improved.

层次结构查看器也是一个有用的可视化工具,可以查看可以改进布局的哪个部分。

#2


In 2019, you can use android x benchmark library easy for benchmark inflate time. android doc write-benchmark

在2019年,您可以使用android x基准库轻松进行基准测试充气时间。 android doc write-benchmark

@RunWith(AndroidJUnit4::class)
class ViewBenchmark {
    @get:Rule
    val benchmarkRule = BenchmarkRule()

    @Test
    fun simpleViewInflate() {
        val context = ApplicationProvider.getApplicationContext()
        val inflater = LayoutInflater.from(context)
        val root = FrameLayout(context)

        benchmarkRule.keepRunning {
            inflater.inflate(R.layout.test_simple_view, root, false)
        }
    }
}

or you can use system trace to benchmark only inflate layout code

或者您可以使用系统跟踪来仅对基础布局代码进行基准测试

#1


Check out lucasr/probe. Here is a blog post by a Facebook engineer on improving view measure time.

检查lucasr / probe。这是Facebook工程师关于改进视图测量时间的博客文章。

Hierarchy Viewer is also a useful visual tool to see which part of your layout can be improved.

层次结构查看器也是一个有用的可视化工具,可以查看可以改进布局的哪个部分。

#2


In 2019, you can use android x benchmark library easy for benchmark inflate time. android doc write-benchmark

在2019年,您可以使用android x基准库轻松进行基准测试充气时间。 android doc write-benchmark

@RunWith(AndroidJUnit4::class)
class ViewBenchmark {
    @get:Rule
    val benchmarkRule = BenchmarkRule()

    @Test
    fun simpleViewInflate() {
        val context = ApplicationProvider.getApplicationContext()
        val inflater = LayoutInflater.from(context)
        val root = FrameLayout(context)

        benchmarkRule.keepRunning {
            inflater.inflate(R.layout.test_simple_view, root, false)
        }
    }
}

or you can use system trace to benchmark only inflate layout code

或者您可以使用系统跟踪来仅对基础布局代码进行基准测试