Update rive-cpp to 2.0 version
[platform/core/uifw/rive-tizen.git] / submodule / skia / platform_tools / android / bin / android_perf
1 #!/bin/bash
2 #
3 # android_perf: utility for running perf on an android device
4 #
5 # The basic usage sequence is to run...
6 #  1) perf record [gm/tests/bench] # runs profiler on specified app
7 #  2) perf report # prints profiler results
8 #  3) perf clean # cleans the temporary directory used to store results
9 #
10
11 SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
12 source $SCRIPT_DIR/utils/android_setup.sh
13 source $SCRIPT_DIR/utils/setup_adb.sh
14
15 # grab and remove the perf command from the input args
16 PERF_CMD=${APP_ARGS[0]}
17 unset APP_ARGS[0]
18 runVars=("${APP_ARGS[@]}")  # shift array indices
19
20 # We need the debug symbols from these files
21 PERF_TMP_DIR=$(pwd)/android_perf_tmp
22
23 TMP_SYS_BIN=$PERF_TMP_DIR/system/bin
24 TMP_SYS_LIB=$PERF_TMP_DIR/system/lib
25 TMP_APP_LOC=$PERF_TMP_DIR/data/local/tmp
26
27 perf_setup() {
28
29     mkdir -p $TMP_SYS_BIN
30     mkdir -p $TMP_SYS_LIB
31     mkdir -p $TMP_APP_LOC
32
33     echo "Copying symbol files"
34     adb_pull_if_needed /system/lib/libc.so $TMP_SYS_LIB
35     adb_pull_if_needed /system/lib/libstdc++.so $TMP_SYS_LIB
36     adb_pull_if_needed /system/lib/libGLESv2.so $TMP_SYS_LIB
37     adb_pull_if_needed /system/lib/libandroid.so $TMP_SYS_LIB
38     adb_pull_if_needed /system/lib/libm.so $TMP_SYS_LIB
39     adb_pull_if_needed /system/lib/libz.so $TMP_SYS_LIB
40
41     # SKIA_OUT variable is set by android_setup.sh
42     if [ ! -f "${SKIA_OUT}/${runVars[0]}" ];
43     then
44       echo "Unable to find the ${runVars[0]} executable"
45       exit 1
46     fi
47
48     echo "Pushing simpleperf..."
49     adb_push_if_needed $SKIA_OUT/simpleperf /data/local/tmp
50
51     echo "Pushing app..."
52     adb_push_if_needed "${SKIA_OUT}/${runVars[0]}" /data/local/tmp
53     cp "${SKIA_OUT}/${runVars[0]}" $TMP_APP_LOC
54 }
55
56 perf_record() {
57
58     echo "Killing any running Skia processes."
59     $ADB shell ps | grep ${runVars[0]} | awk '{print $2}' | xargs $ADB shell kill
60
61     echo "Starting application"
62     $ADB shell /data/local/tmp/${runVars[@]} &
63
64     # WE REALLY REALLY WANT TO BE ABLE TO PASS THE SKIA_LAUNCHER APP DIRECTLY TO
65     # PERF, BUT AT THIS POINT THE DATA FILE WE GET WHEN GOING THAT ROUTE IS UNABLE
66     # TO BE READ BY THE REPORTING TOOL
67     echo "Starting profiler"
68     APP_PID=$($ADB shell ps | grep ${runVars[0]} | awk '{print $2}')
69     $ADB shell /data/local/tmp/simpleperf record -p ${APP_PID} -o /data/local/tmp/perf.data sleep 70
70
71     $ADB pull /data/local/tmp/perf.data $PERF_TMP_DIR/perf.data
72
73     exit 0;
74 }
75
76 perf_report() {
77     adb_pull_if_needed /data/local/tmp/perf.data $PERF_TMP_DIR/perf.data
78     $SKIA_OUT/perfhost_report.py -i $PERF_TMP_DIR/perf.data --symfs=$PERF_TMP_DIR ${runVars[@]}
79 }
80
81 # Clean up
82 perf_clean() {
83     rm -rf $PERF_TMP_DIR
84 }
85
86 case $PERF_CMD in
87   setup)
88       perf_setup ${runVars[@]}
89       ;;
90   record)
91       perf_setup ${runVars[@]}
92       perf_record ${runVars[@]}
93       ;;
94   report)
95       perf_report
96       ;;
97   clean)
98       perf_clean
99       ;;
100     *)
101       echo -n "ERROR: unknown perf command ($PERF_CMD), valid values: "
102       echo "setup, record, report, clean"
103       exit 1;
104       ;;
105 esac
106
107 exit 0;