Android Trace埋点beginSection打tag标签,Kotlin

Android Trace埋点beginSection打tag标签,Kotlin

Kotlin 复制代码
import android.os.Bundle
import android.os.Trace
import android.util.Log
import androidx.appcompat.app.AppCompatActivity

class ImageActivity : AppCompatActivity() {
    companion object {
        const val TRACE_TAG = "fly_tag"
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        //检测手机的trace功能是否开启
        Log.d("fly", "${Trace.isEnabled()}")

        Trace.beginSection(TRACE_TAG)
        Thread.sleep(2000)
        Trace.endSection()
    }
}

上面trace打好tag标签后用,用

Android adb shell命令捕获systemtrace_android 抓trace-CSDN博客文章浏览阅读2.6k次,点赞2次,收藏8次。本文介绍了如何使用adbshell命令配合perfetto工具来捕获Android设备的systemtrace文件,包括设置跟踪时长、保存文件路径、将文件从设备拉取到电脑以及通过PerfettoUI分析trace文件。这个过程对于性能优化和问题排查非常有用。https://blog.csdn.net/zhangphil/article/details/131249820抓trace是没有显示 fly_tag 这段trace的,并且,程序跑起来,

复制代码
Trace.isEnabled()

返回的是false,原因是需要手机在 开发者选项 - 系统跟踪 - 录制轨迹 ,勾选后,才会有自己打的tag标签。开启 录制轨迹 后,再次抓trace,就有了自定义的trace tag:

如果使用androidx的Trace类,需要:

Kotlin 复制代码
implementation "androidx.tracing:tracing:1.2.0"

参考官方文档:

https://developer.android.com/jetpack/androidx/releases/tracinghttps://developer.android.com/jetpack/androidx/releases/tracing?hl=zh-cn

相关推荐
YB13751 天前
jetpack compose 副作用 SideEffect
android·kotlin
CHB1 天前
uni-app x 蒸汽模式 性能测试基准报告 Benchmark【Android版】
android·ios·uni-app
带娃的IT创业者1 天前
拆掉那堵墙:LibrePods 如何让 AirPods 在 Android 上重获新生
android·开源项目·airpods·librepods·生态解锁
_阿南_1 天前
flutter 展示的字体突然奔放了
android·flutter·ios
唐青枫1 天前
Kotlin interface 详解:别再把接口写成空壳和万能开关
kotlin
文人sec1 天前
MySQL事务与索引做了什么?
android·笔记·mysql
刘洋浪子2 天前
AndroidStudio保存日志菜单
android
朱涛的自习室2 天前
从 Prompt 到 Graph:AI 工程的进化史
android·前端·人工智能
2501_932750262 天前
Android 中 Serializable 与 Parcelable 的对比与选择
android
FungLeo2 天前
Flutter 两个反直觉布局坑:ListTile 水波纹 / VerticalDivider 踩坑实录
android·flutter