赞
踩
进入到 cmd 中,敲入下面的命令
H:
cd H:\Sdk\emulator
.\emulator.exe -list-avds
.\emulator.exe -writable-system -avd Pixel_XL_API_32_6 -no-snapshot-load -qemu
adb shell setprop persist.traced.enable 1
adb shell
getprop persist.traced.enable
ps -A|grep -i trace
adb shell perfetto -o /data/misc/perfetto-traces/trace_file.perfetto-trace -t 10s sched freq idle am wm gfx view binder_driver hal dalvik camera input res memory
其中 -o /data/misc/perfetto-traces/trace_file.perfetto-trace 意思就是说 将 trace 保存到手机的 /data/misc/perfetto-traces/ 路径下,且文件名为 trace_file.perfetto-trace
-t 10s 意思就是抓取 10 秒
点击照相APP,操作几下, 10秒后会自动停止抓取
adb pull /data/misc/perfetto-traces/trace_file.perfetto-trace
在哪个路径执行的 上面的命令,文件就会被保存到哪里
可以看到拷贝好的 trace 文件
https://ui.perfetto.dev/
然后把 trace 文件拖进来
这里 GeekCamera2Trace 类是直接调用 Android 系统的 Trace 类的各种函数
package com.deepinout.geekcamera; import android.os.Build; import android.os.Trace; public class GeekCamera2Trace { ... public static void beginAsyncSection(String methodName, int cookie) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && Trace.isEnabled()) { Trace.beginAsyncSection(methodName, cookie); } } public static void endAsyncSection(String methodName, int cookie) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && Trace.isEnabled()) { Trace.endAsyncSection(methodName, cookie); } } public static void beginSection(String sectionName) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q &&Trace.isEnabled()) { Trace.beginSection(sectionName); } } public static void endSection() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q &&Trace.isEnabled()) { Trace.endSection(); } } public static void setCounter(String counterName, long counterValue) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q &&Trace.isEnabled()) { Trace.setCounter(counterName, counterValue); } } }
打开下面的网址
https://ui.perfetto.dev/
选取下面的选项
选好以后,复制下面的内容到一个文件
buffers: { size_kb: 63488 fill_policy: DISCARD } buffers: { size_kb: 2048 fill_policy: DISCARD } data_sources: { config { name: "android.gpu.memory" } } data_sources: { config { name: "linux.process_stats" target_buffer: 1 process_stats_config { scan_all_processes_on_start: true } } } data_sources: { config { name: "linux.sys_stats" sys_stats_config { meminfo_period_ms: 1000 meminfo_counters: MEMINFO_MEM_FREE meminfo_counters: MEMINFO_MEM_TOTAL meminfo_counters: MEMINFO_SWAP_FREE meminfo_counters: MEMINFO_SWAP_TOTAL stat_period_ms: 1000 stat_counters: STAT_CPU_TIMES stat_counters: STAT_FORK_COUNT cpufreq_period_ms: 1000 } } } data_sources: { config { name: "linux.ftrace" ftrace_config { ftrace_events: "sched/sched_switch" ftrace_events: "power/suspend_resume" ftrace_events: "sched/sched_wakeup" ftrace_events: "sched/sched_wakeup_new" ftrace_events: "sched/sched_waking" ftrace_events: "power/cpu_frequency" ftrace_events: "power/cpu_idle" ftrace_events: "power/gpu_frequency" ftrace_events: "gpu_mem/gpu_mem_total" ftrace_events: "sched/sched_process_exit" ftrace_events: "sched/sched_process_free" ftrace_events: "task/task_newtask" ftrace_events: "task/task_rename" ftrace_events: "lowmemorykiller/lowmemory_kill" ftrace_events: "oom/oom_score_adj_update" ftrace_events: "ftrace/print" atrace_categories: "camera" atrace_categories: "gfx" atrace_categories: "hal" atrace_categories: "input" atrace_categories: "ss" atrace_categories: "view" atrace_categories: "wm" atrace_apps: "*" } } } duration_ms: 10000
改成自己的 app 的名字
我保存到了 H:\Sdk\emulator 下面,文件名字叫做 record_camera.config
(大家可以按照自己的喜好选择路径和设置文件名字)
在 cmd 或者 Android Studio 的 Terminal 中输入下面的命令
adb push record_camera.config /data/local/tmp/record_camera.config
adb shell “cat /data/local/tmp/record_camera.config | perfetto --txt -c - -o /data/misc/perfetto-traces/trace.perfetto-trace”
报错:
解决办法:
保存
重新 Push 到模拟器
重复执行上面两行命令
adb push record_camera.config /data/local/tmp/record_camera.config
adb shell “cat /data/local/tmp/record_camera.config | perfetto --txt -c - -o /data/misc/perfetto-traces/trace.perfetto-trace”
可以看到可以运行正常
点开 app ,然后点击拍照
这样就抓取好了 trace
拷贝trace 到电脑
adb pull /data/misc/perfetto-traces/trace.perfetto-trace
可以看到抓取的 trace 文件
将这个文件拖到网页
https://ui.perfetto.dev/
搜索 GC2_App_openCamera
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。