Android systrace不显示我的应用程序的自定义部分

时间:2018-11-09 13:59:05

标签: android performance systrace

使用systrace在RecyclerView中滚动时尝试分析滞后:

python systrace.py -o ~/tmp/newtrace.html -app=<my package>

但是没有用于自定义跟踪部分的条目。 No entry for my custom sections

我正在使用以下代码进行跟踪

override fun onCreateViewHolder(parent: ViewGroup): RecyclerView.ViewHolder {
    trace(sectionName = "GalleryDelegate.onCreateViewHolder") {
        val view = layoutInflater.inflate(R.layout.item_upload, parent, false)
        return ProfileMediaHolder(view, delegate)
    }
}

override fun onBindViewHolder(items: List<ProfileDataEntry>, position: Int, holder: RecyclerView.ViewHolder, payloads: MutableList<Any>) {
    trace(sectionName = "GalleryDelegate.onBindViewHolder") {
        val item = items[position] as ProfileDataEntry.MediaItem
        val castedHolder = holder as ProfileMediaHolder
        when (item) {
            is ProfileDataEntry.MediaItem.Item -> {
                castedHolder.bind(item.value)
            }
            is ProfileDataEntry.MediaItem.Placeholder -> {
                castedHolder.bind(item.type)
            }
        }
    }
}

1 个答案:

答案 0 :(得分:1)

您需要使用以下命令为您的应用启用systrace

adb shell "setprop debug.atrace.app_number 1" adb shell "setprop debug.atrace.app_0 appname"

默认情况下处于禁用状态。为了获取systrace,只需在命令行中指定您的应用程序名称即可。

python systrace.py -t 4 -a appname -o mynewtrace.html perf sched gfx