如何从我的自动化脚本捕获Android Systrace [英] How to capture Android Systrace from my automation script

查看:73
本文介绍了如何从我的自动化脚本捕获Android Systrace的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在运行自动化测试时捕获Android systrace.由于我不知道测试的持续时间,因此无法使用参数"-t"

I am trying to capture Android systrace while running my automation tests. Since i dont know the duration of my tests so i cannot use param "-t" .

我使用以下命令进行跟踪-

I use below command for tracing -

python systrace.py -a com.myapp -o testauto.html

手动停止跟踪,我们需要按Enter键.我该怎么做 ?如何停止捕获跟踪,以便它自动创建跟踪文件?

Manually to stop the trace we need to press enter. How do i do it ? How do i stop capturing the traces so that it automatically creates the trace file ?

推荐答案

systrace.py是要手动运行的,因此,如果要使其自动化,可以使用基础的 atrace 命令.有点令人费解,所以我将最后包括这些步骤.

systrace.py is meant to be run manually so if you want to automate it you could use the underlying atrace command. It's somewhat convoluted so I'll include the steps in the end.

我强烈建议您研究 Perfetto 命令行工具.您可以在此处找到更详细的文档: https://perfetto.dev/docs/quickstart/android-跟踪.

I strongly recommend that you look into the Perfetto command line tool. You can find more detailed documentation here: https://perfetto.dev/docs/quickstart/android-tracing.

TLDR:

adb shell perfetto -o /data/misc/perfetto-traces/trace_file.pftrace -b 32mb <add_list_of_categories>

然后发送终止信号(即Ctrl + C)以停止跟踪.要根据您的主机操作系统进行自动化,应该很简单.

Then send the termination signal (i.e. Ctrl+C) to stop tracing. Should be trivial to automate based on your host OS.

另一个值得研究的资源是用于CI/CD集成的AndroidX Benchmark库: https://developer.android.com/studio/profile/benchmark .

Another resource worth looking into is the AndroidX Benchmark library for CI/CD integration: https://developer.android.com/studio/profile/benchmark.

-附录-

要直接运行 atrace :

adb shell /system/bin/atrace -z -b <buffer_size_in_kb> -a <app_name> -o /data/local/tmp/test.trace --async_start

然后停止跟踪:

adb shell /system/bin/atrace -z -a <app_name> -o /data/local/tmp/test.trace0 --async_stop

最后,您需要合并文件:

Finally you need to combine the files:

cat test.trace test.trace0 > combined.trace

这篇关于如何从我的自动化脚本捕获Android Systrace的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆