惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

M
MIT News - Artificial intelligence
罗磊的独立博客
Hugging Face - Blog
Hugging Face - Blog
Apple Machine Learning Research
Apple Machine Learning Research
Last Week in AI
Last Week in AI
S
SegmentFault 最新的问题
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
美团技术团队
人人都是产品经理
人人都是产品经理
WordPress大学
WordPress大学
The Cloudflare Blog
IT之家
IT之家
雷峰网
雷峰网
小众软件
小众软件
博客园 - 叶小钗
博客园 - 聂微东
爱范儿
爱范儿
博客园 - 司徒正美
博客园 - 三生石上(FineUI控件)
V
Visual Studio Blog
博客园 - 【当耐特】
V
V2EX
博客园_首页
T
Tailwind CSS Blog

博客园 - 蓝天上的云℡

简洁低消耗字节内存池设计 ARM崩溃堆栈报错寄存器分析定位 ARM NEON&Thumb加速指令集 事件编程之eventfd 事件驱动编程模式之EventLoop syslog日志查看器GUI图形界面,支持Windows/Linux/Macos开箱即用 ERRNO链条分析 ARM AMBA总线之AXI系 Linux Kernel Init Bootstrap 内核初始化启动 RK芯片平台GPIO控制 Linux USB子系统之Gadget设备端驱动 远程调试桥接-网络-ADB-GDB 斐讯N1盒子安装飞牛FNOS NAS 安卓以太网链路检测 安卓原生开发-Recovery使用minui绘制图形 蓝牙音频协议——安卓开发 RKxx系列的RK628摄像头配置影响HDMI出图 usb储存之BOT/UAS内核驱动 现代操作系统-音频处理技术1 Linux驱动底层 Linux驱动适配I2C/SPI例子 模块编译的pr_debug Linux内核/GKI内核主线更新-usb网卡名称变更引出的BUG 为Kernel代码生成VSCODE索引,快速跳转 Linux/Golang/glibC系统调用 SGDMA与普通DMA Linux内核源码-存储驱动之 QSPI Flash golang数据转换技巧
安卓开机时间/性能优化
蓝天上的云℡ · 2025-07-08 · via 博客园 - 蓝天上的云℡

rc启动规则:
https://android.googlesource.com/platform/external/perfetto/+/40a2915a619414d58ec47bfa176490380f0f63ad/perfetto.rc

开机时间追踪:
https://perfetto.dev/docs/case-studies/android-boot-tracing

然后设置几个属性用于开机启动追踪

setprop persist.debug.atrace.boottrace 1
setprop persist.debug.perfetto.boottrace 1
setprop persist.traced.enable 1 

增加追踪项配置到/data/misc/perfetto-configs/boottrace.pbtxt

# https://perfetto.dev/docs/case-studies/android-boot-tracing
#
# /data/misc/perfetto-configs/boottrace.pbtxt
# setprop persist.debug.perfetto.boottrace 1

buffers {
  size_kb: 65536
  fill_policy: DISCARD
}
buffers {
  size_kb: 4096
  fill_policy: DISCARD
}
data_sources {
  config {
    name: "linux.ftrace"
    ftrace_config {
      ftrace_events: "sched/sched_process_exit"
      ftrace_events: "sched/sched_process_free"
      ftrace_events: "task/task_newtask"
      ftrace_events: "task/task_rename"
      ftrace_events: "sched/sched_switch"
      ftrace_events: "power/suspend_resume"
      ftrace_events: "sched/sched_blocked_reason"
      ftrace_events: "sched/sched_wakeup"
      ftrace_events: "sched/sched_wakeup_new"
      ftrace_events: "sched/sched_waking"
      ftrace_events: "sched/sched_process_exit"
      ftrace_events: "sched/sched_process_free"
      ftrace_events: "task/task_newtask"
      ftrace_events: "task/task_rename"
      ftrace_events: "power/cpu_frequency"
      ftrace_events: "power/cpu_idle"
      ftrace_events: "power/suspend_resume"
      ftrace_events: "ftrace/print"
      atrace_categories: "adb"
      atrace_categories: "aidl"
      atrace_categories: "am"
      atrace_categories: "audio"
      atrace_categories: "binder_driver"
      atrace_categories: "binder_lock"
      atrace_categories: "bionic"
      atrace_categories: "database"
      atrace_categories: "gfx"
      atrace_categories: "hal"
      atrace_categories: "input"
      atrace_categories: "pm"
      atrace_categories: "power"
      atrace_categories: "res"
      atrace_categories: "ss"
      atrace_categories: "view"
      atrace_categories: "wm"
      disable_generic_events: true
    }
  }
}
data_sources {
  config {
    name: "linux.process_stats"
    process_stats_config {
    }
  }
}
data_sources {
  config {
    name: "linux.sys_stats"
    sys_stats_config {
      stat_period_ms: 500
      stat_counters: STAT_CPU_TIMES
      stat_counters: STAT_FORK_COUNT
      cpufreq_period_ms: 500
    }
  }
}
duration_ms: 30000

打开 https://ui.perfetto.dev/
将安卓目录下的 /data/misc/perfetto-traces/boottrace.perfetto-trace 复制出来导入
加载数据,即可看到整个开机过程的线程资源占用分布:
image

点开里面分析占用时间较长的进程,
logcat --pid=xxx
查看pid对应日志

结合各部分开机时间统计
https://juejin.cn/post/7345379878240206859

logcat -b events | grep -E "boot_progress|sf_stop_bootanim|wm_boot_animation_done"

发现在boot_progress_pms_ready到boot_progress_ams_ready耗时高达30s,大大影响了安卓开机到桌面的时间。
这个结果和上面trace图表现一致,system_server在堵塞,startService MTKTVINPUT服务过程时长高达24s。

接下来就只分析该服务就可以了

logcat分析服务

匹配启动时间较长的日志正则表达式如下(匹配1000ms以上的)

##(匹配10000ms即10s以上的)
took to complete: [1-9][0-9][0-9][0-9][0-9]+ms

Also

--------蓝天上的云_转载请注明出处.