Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(38)

Side by Side Diff: tools-webrtc/android/profiling/utilities.sh

Issue 2705063002: Adding support for native profiling of AppRTCMobile (Closed)
Patch Set: nit Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 #!/bin/bash
2
3 # Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
4 #
5 # Use of this source code is governed by a BSD-style license
6 # that can be found in the LICENSE file in the root of the source
7 # tree. An additional intellectual property rights grant can be found
8 # in the file PATENTS. All contributing project authors may
9 # be found in the AUTHORS file in the root of the source tree.
10
11 # Utility functions to be used by perf_setup.sh.
12 # Contains helper methods and functions that wraps usage of adb.
13
14 function error() {
15 echo "[ERROR] "$@"" >&2
16 }
17
18 function warning() {
19 echo "[WARNING] "$@"" >&1
20 }
21
22 function ok() {
23 echo "[OK] "$@"" >&1
24 }
25
26 function abs_path {
27 (cd $1; pwd)
28 }
29
30 function is_set() {
31 local var="$1"
32 [[ -n "${var}" ]]
33 }
34
35 function is_file() {
36 local file="$1"
37 [[ -f "${file}" ]]
38 }
39
40 function is_not_file() {
41 local file="$1"
42 [[ ! -f "${file}" ]]
43 }
44
45 function is_dir() {
46 local dir="$1"
47 [[ -d "${dir}" ]]
48 }
49
50 function is_not_dir() {
51 local dir="$1"
52 [[ ! -d "${dir}" ]]
53 }
54
55 # Updates the PATH environment variable while avoid duplicates.
56 function path_update() {
57 case ":${PATH:=$1}:" in
58 *:$1:*) ;;
59 *) PATH="$1:$PATH" ;;
60 esac
61 }
62
63 function find_app_pid() {
kjellander_webrtc 2017/02/22 14:46:57 Maybe document what argument is expected to be pas
henrika_webrtc 2017/02/22 15:47:11 Done.
64 local app_name="$1"
65 adb shell ps | grep "${app_name}" | awk '{print $2}'
66 }
67
68 function app_is_installed() {
69 local app_name="$1"
70 local installed_app_name=$(adb shell pm list packages \
71 | grep "${app_name}" | awk -F':' '{print $2}')
72 is_set "${installed_app_name}" \
73 && [[ "${installed_app_name}" = "${app_name}" ]]
74 }
75
76 function app_is_running() {
77 local app_name="$1"
78 local app_pid=$(find_app_pid "${app_name}")
79 is_set "${app_pid}"
80 }
81
82 function app_start() {
83 local app_name="$1"
84 adb shell am start \
85 -n "${app_name}/.ConnectActivity" \
86 -a android.intent.action.MAIN
87 }
88
89 function app_stop() {
90 local app_name="$1"
91 adb shell am force-stop "${app_name}"
92 }
93
94 function app_uninstall() {
95 local app_name="$1"
96 adb uninstall "${app_name}"
97 }
98
99 function dev_arch() {
100 adb shell uname -m
101 }
102
103 function dev_ls() {
104 local dir="$1"
105 adb shell ls "${dir}"
106 }
107
108 # Returns true if exactly on device is connected.
109 function one_device_connected() {
110 [[ $(adb devices | wc -l) = 3 ]]
111 }
112
113 # Returns true if device is rooted.
114 function image_is_root() {
115 [[ $(adb shell getprop ro.build.type) = "userdebug" ]]
116 }
117
118 # Returns true if device is not rooted.
119 function image_is_not_root() {
120 [[ $(adb shell getprop ro.build.type) = "user" ]]
121 }
122
123 # Returns true if adb is not already running as root.
124 # Should only be called on rooted devices.
125 function adb_has_no_root_permissions() {
126 [[ $(adb shell getprop service.adb.root) = 0 ]]
127 }
128
129 # Android devices may disable profiling by default. We must enable it.
130 function enable_profiling() {
131 adb shell setprop security.perf_harden 0
kjellander_webrtc 2017/02/22 14:46:57 If the below checks for root, maybe this one also
henrika_webrtc 2017/02/22 15:47:11 Good point. Will fix and align with function below
132 }
133
134 # To make the report of symbols on device successful, we need to execute
135 # `echo 0 >/proc/sys/kernel/kptr_restrict`.
136 # Only needed if we run report commands on the same machine as we run
137 # record commands.
138 function enable_report_symbols() {
139 image_is_root \
kjellander_webrtc 2017/02/22 14:46:57 If the device is not rooted this will just silentl
henrika_webrtc 2017/02/22 15:47:11 As you say. Not really needed since we check that
140 && adb shell "echo 0 > /proc/sys/kernel/kptr_restrict"
141 }
OLDNEW
« tools-webrtc/android/profiling/perf_setup.sh ('K') | « tools-webrtc/android/profiling/perf_setup.sh ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698