Debian Codegraph @

testing/performance/android-resource/collect-proc-info-cpu.sh

raw
1 #!/bin/bash
2 # This Source Code Form is subject to the terms of the Mozilla Public
3 # License, v. 2.0. If a copy of the MPL was not distributed with this
4 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 source $1/common.sh
6
7 TEST_TIME=$2
8
9 # waiting for test start signal
10 while true; do
11 if [ -f $TESTING_DIR/test_start.signal ]; then
12 break
13 fi
14 done
15
16 get_cpu_info(){
17 # name: process name
18 # res: rss
19 # shr: shared memory
20 # swap: swap I/O
21 # cpu: processor being used
22 # c: total %CPU used since start
23 # time: CPU time consumed
24 # %cpu: percentage of CPU time used
25 adb shell ps -p "$1" -o name=,cpu=,c=,time+=,%cpu= >> $2
26 }
27
28 collect_cpu_at() {
29 for pid in $(get_process_ids $BROWSER_BINARY); do
30 echo "Collecting cpu info at $1s for $pid"
31 get_cpu_info "$pid" $TESTING_DIR/cpu_info_$2.txt &
32 done
33 }
34
35 collect_resources_at() {
36 sleep $1
37 collect_cpu_at $1 $2
38 }
39
40 collect_resources_info() {
41 collect_resources_at 0 "01" & # at start
42 collect_resources_at $(($TEST_TIME/10)) "02" & # at 10%
43 collect_resources_at $(($TEST_TIME/2)) "03" & # at 50%
44 collect_resources_at $TEST_TIME "04" # at test end
45 }
46
47 print_info "$1" & print_info_pid=$!
48 collect_resources_info
49 kill "$print_info_pid"