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.
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>
Then send the termination signal (i.e. Ctrl+C) to stop tracing. Should be trivial to automate based on your host OS.
Another resource worth looking into is the AndroidX Benchmark library for CI/CD integration: https://developer.android.com/studio/profile/benchmark.
--Appendix--
To run atrace
directly:
adb shell /system/bin/atrace -z -b <buffer_size_in_kb> -a <app_name> -o /data/local/tmp/test.trace --async_start
Then stop the trace:
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