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

Side by Side Diff: build/android/adb_profile_chrome

Issue 25044004: android: Reimplement adb_profile_chrome in Python (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Nits picked. Created 7 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | build/android/adb_profile_chrome.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/bin/bash 1 #!/bin/bash
2 # 2 #
3 # Copyright 2013 The Chromium Authors. All rights reserved. 3 # Copyright 2013 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 # 6 #
7 # Start / stop profiling in chrome. 7 # Start / stop profiling in chrome.
8 8 exec $(dirname $0)/adb_profile_chrome.py $@
9 # The profiling data is saved to directory /sdcard/Download. The files
10 # are named beginning chrome-profile-results-
11 #
12 # Assumes you have sourced the android build environment script
13 # (e.g. 'adb' is on your path).
14 set -e
15
16 usage() {
17 echo "adb_profile_chrome [--start [-o file] [-c C]|--stop|-d|-t N] [-v N]"
18 echo "See http://dev.chromium.org/developers/how-tos/trace-event-profiling-too l for detailed instructions on profiling."
19 echo ""
20 echo " --start Start profiling."
21 echo " --output|-o file Save profile output to file. "
22 echo " (Default is /sdcard/Download/chrome-profile-results -*)"
23 echo " --categories|-c C Select categories to trace with comma-delimited wil dcards."
24 echo " e.g. '*', 'cat1*,-cat1a'. Default is '*'."
25 echo " --continuous Using the trace buffer as a ring buffer, continuous ly"
26 echo " profile until stopped."
27 echo " --stop Stop profiling."
28 echo " --download|-d Download latest trace."
29 echo " --time|-t N Profile for N seconds and download the resulting tr ace."
30 echo " --version|v N Select among installed browsers."
31 echo " One of stable (default), beta, dev, build"
32 echo ""
33 echo "Profiling data is saved to the device."
34 exit 0
35 }
36
37 send_intent() {
38 local PACKAGE=$1
39 local INTENT=$2
40 shift
41 shift
42 adb shell am broadcast -a $PACKAGE.$INTENT $*
43 }
44
45 download_latest_trace() {
46 (adb logcat -d | grep -q "Logging performance trace to file") || {
47 echo "WARNING: Trace start marker not found. Is the correct version of Chrom e running?"
48 }
49
50 local ITERATION=0
51 while true; do
52 # Chrome logs two different messages related to tracing:
53 #
54 # 1. "Logging performance trace to file [...]"
55 # 2. "Profiler finished. Results are in [...]"
56 #
57 # The first one is printed when tracing starts and the second one indicates
58 # that the trace file is ready to be downloaded.
59 #
60 # We have to look for both of these messages to make sure we get the results
61 # from the latest trace and that the trace file is complete. This is done by
62 # first looking for the last instance of the first message and then checking
63 # for the second message in the remaining part of the log.
64 TRACE_FILE=$(adb logcat -d | \
65 tac | \
66 grep --max-count=1 --before-context=100000 "Logging performance trace to file" | \
67 tac | \
68 grep "Profiler finished[.] Results are in " | \
69 perl -pi -e "s{.*/storage/emulated/.+/([^\r]+)[.].*}{/sdcard/Download/\\ 1}g")
70 if [ -n "$TRACE_FILE" ]; then
71 break
72 fi
73 if [ $ITERATION -eq 0 ]; then
74 echo -n "Waiting for Chrome to finish tracing..."
75 else
76 echo -n "."
77 fi
78 let ITERATION=ITERATION+1
79 if [ $ITERATION -eq 60 ]; then
80 echo "Timed out"
81 exit 1
82 fi
83 sleep 1
84 done
85
86 adb pull $TRACE_FILE 2> /dev/null
87 LOCAL_TRACE_FILE=$(basename $TRACE_FILE)
88 if [ ! -f "$LOCAL_TRACE_FILE" ]; then
89 echo "Unable to download trace file"
90 exit 1
91 fi
92 }
93
94 do_timed_capture() {
95 local PACKAGE=$1
96 local INTERVAL=$2
97 shift
98 shift
99 echo -n "Capturing trace..."
100 send_intent ${PACKAGE} "GPU_PROFILER_START" $* > /dev/null
101 sleep ${INTERVAL}
102 send_intent ${PACKAGE} "GPU_PROFILER_STOP" > /dev/null
103 echo "done"
104
105 echo -n "Downloading trace..."
106 sleep $[${INTERVAL} / 4 + 1]
107 download_latest_trace
108 echo "done"
109
110 echo "Trace written to ${PWD}/${LOCAL_TRACE_FILE}"
111 }
112
113 PACKAGE=${DEFAULT_PACKAGE:-com.android.chrome}
114
115 while test -n "$1"; do
116 case "$1" in
117 -v|--version)
118 if [[ -z "$2" ]] ; then
119 usage
120 fi
121 shift
122 case "$1" in
123 stable) PACKAGE="com.android.chrome" ;;
124 beta) PACKAGE="com.chrome.beta" ;;
125 dev) PACKAGE="com.google.android.apps.chrome_dev" ;;
126 build) PACKAGE="com.google.android.apps.chrome" ;;
127 *) usage ;;
128 esac
129 ;;
130 --start) FUNCTION="GPU_PROFILER_START" ;;
131 --stop) FUNCTION="GPU_PROFILER_STOP" ;;
132 -o|--output)
133 if [ -z "$2" ] ; then
134 usage
135 fi
136 OUTPUT="-e file '$2'"
137 shift
138 ;;
139 -c|--categories)
140 if [ -z "$2" ]; then
141 usage
142 fi
143 CATEGORIES="-e categories '$2'"
144 shift
145 ;;
146 --continuous) CONTINUOUS="-e continuous ." ;;
147 -t|--time)
148 shift
149 if [ -z "$1" ] ; then
150 usage
151 fi
152 INTERVAL="$1"
153 ;;
154 -d|--download)
155 shift
156 download_latest_trace
157 echo "Trace written to ${PWD}/${LOCAL_TRACE_FILE}"
158 ;;
159 *) usage ;;
160 esac
161 shift
162 done
163
164 if [ -z "${INTERVAL}" ] ; then
165 if [ -z "${FUNCTION}" ] ; then
166 usage
167 else
168 send_intent ${PACKAGE} ${FUNCTION} ${OUTPUT} ${CATEGORIES} ${CONTINUOUS}
169 fi
170 else
171 do_timed_capture ${PACKAGE} ${INTERVAL} ${CATEGORIES} ${CONTINUOUS}
172 fi
173 exit 0
OLDNEW
« no previous file with comments | « no previous file | build/android/adb_profile_chrome.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698