Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bece2b9a authored by Alec Mouri's avatar Alec Mouri
Browse files

Helper script for running TransactionFlinger CUJs

Includes Perfetto collection, IPowerStats, and simpleperf dumps

This doesn't yet try to do anything fancy like disable background
services or lock clocks in order to stabilize measurements, but should
be cool enough for a smoke test

Bug: 405591499
Flag: EXEMPT test only
Test: run script
Change-Id: Ia4dcc8939cda6323bbc57accf920f2bad1c6d6e3
parent ad8b5674
Loading
Loading
Loading
Loading
+109 −0
Original line number Diff line number Diff line
buffers {
  size_kb: 524288
  fill_policy: DISCARD
}
buffers {
  size_kb: 8192
  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: "power/gpu_frequency"
      ftrace_events: "gpu_mem/gpu_mem_total"
      ftrace_events: "regulator/regulator_set_voltage"
      ftrace_events: "regulator/regulator_set_voltage_complete"
      ftrace_events: "power/clock_enable"
      ftrace_events: "power/clock_disable"
      ftrace_events: "power/clock_set_rate"
      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: "camera"
      atrace_categories: "dalvik"
      atrace_categories: "database"
      atrace_categories: "gfx"
      atrace_categories: "hal"
      atrace_categories: "input"
      atrace_categories: "network"
      atrace_categories: "nnapi"
      atrace_categories: "pm"
      atrace_categories: "power"
      atrace_categories: "res"
      atrace_categories: "rro"
      atrace_categories: "rs"
      atrace_categories: "sm"
      atrace_categories: "ss"
      atrace_categories: "vibrator"
      atrace_categories: "video"
      atrace_categories: "view"
      atrace_categories: "webview"
      atrace_categories: "wm"
      atrace_apps: "*"
      symbolize_ksyms: true
      disable_generic_events: true
    }
  }
}
data_sources {
  config {
    name: "linux.process_stats"
    process_stats_config {
      scan_all_processes_on_start: true
    }
  }
}
data_sources {
  config {
    name: "linux.sys_stats"
    sys_stats_config {
      stat_period_ms: 250
      stat_counters: STAT_CPU_TIMES
      stat_counters: STAT_FORK_COUNT
      cpufreq_period_ms: 250
    }
  }
}
data_sources {
  config {
    name: "android.gpu.memory"
  }
}
data_sources {
  config {
    name: "android.power"
    android_power_config {
      battery_poll_ms: 500
      collect_power_rails: true
    }
  }
}
data_sources {
  config {
    name: "android.surfaceflinger.frametimeline"
  }
}
 No newline at end of file
+92 −0
Original line number Diff line number Diff line
# Copyright 2025 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

test_name=''
seconds=0
dump_powerhal=false
use_perfetto=false
use_simpleperf=false

print_usage() {
  printf 'Usage:\n    smoke.sh -n TEST_NAME -d [OPTIONAL SECONDS] \n\n'
  printf -- '-p: Enable power dumps. Only if the test duration is finite. \n\n'
  printf -- '-t: Enable perfetto tracing. Only if the test duration is finite. Only works if you run in the same directory as config.pbtx. \n\n'
  printf -- '-s: Enable simpleperf collection for surfaceflinger. Only if the test duration is finite. \n\n'
}

while getopts 'd::n:pst' flag; do
  case "${flag}" in
    d) seconds="${OPTARG}";;
    n) test_name="${OPTARG}";;
    p) dump_powerhal=true;;
    s) use_simpleperf=true;;
    t) use_perfetto=true;;
    *) print_usage
       exit 1 ;;
  esac
done

if [ -z "$test_name" ]; then
    print_usage
    exit 1
fi

if [[ ! "$seconds" =~ ^[0-9]+$ ]]; then
  echo "Seconds was not a positive integer -- defaulting to 0"
  seconds='0'
fi

echo "Launching test: $test_name"

adb shell am start -n com.android.test.transactionflinger/com.android.test.transactionflinger.activities.$test_name

if (( "$seconds" > 0 )); then
    echo "Running test for $seconds seconds"
    if (( "$seconds" < 10 )); then
        echo "Note that running a test for less than 10 seconds may not produce great power data"
    fi

    start_time=$(date +%s)
    if "$dump_powerhal" ; then
         adb shell dumpsys android.hardware.power.stats.IPowerStats/default | grep -A100 "energy meter" > before_energy.txt
         echo "Dumped initial power stats into before_energy.txt"
    fi

    if "$use_simpleperf" ; then
        $(${ANDROID_BUILD_TOP}/system/extras/simpleperf/scripts/app_profiler.py -np surfaceflinger -r "--duration ${seconds} -g --post-unwind=yes" ; ${ANDROID_BUILD_TOP}/system/extras/simpleperf/scripts/pprof_proto_generator.py -i perf.data) &
    fi

    if "$use_perfetto" ; then
        config="$(< config.pbtx)"
        config+=" duration_ms: ${seconds}000"
        echo ${config} | adb shell -t perfetto -c - --txt -o /data/misc/perfetto-traces/trace.pftrace
        adb pull /data/misc/perfetto-traces/trace.pftrace
    else
        sleep $seconds
    fi

    end_time=$(date +%s)
    elapsed=$(( end_time - start_time ))
    if "$dump_powerhal" ; then
        adb shell dumpsys android.hardware.power.stats.IPowerStats/default | grep -A100 "energy meter" > after_energy.txt
        echo "Dumped final power stats into after_energy.txt after $elapsed seconds"
    fi

    echo "Running for a few extra seconds before stopping"
    sleep 5
    echo "Stopping test: $test_name"
    adb shell am force-stop com.android.test.transactionflinger
fi