OLD | NEW |
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 |
9 # The profiling data is saved to directory /sdcard/Download. The files | 9 # The profiling data is saved to directory /sdcard/Download. The files |
10 # are named beginning chrome-profile-results- | 10 # are named beginning chrome-profile-results- |
(...skipping 25 matching lines...) Expand all Loading... |
36 | 36 |
37 send_intent() { | 37 send_intent() { |
38 local PACKAGE=$1 | 38 local PACKAGE=$1 |
39 local INTENT=$2 | 39 local INTENT=$2 |
40 shift | 40 shift |
41 shift | 41 shift |
42 adb shell am broadcast -a $PACKAGE.$INTENT $* | 42 adb shell am broadcast -a $PACKAGE.$INTENT $* |
43 } | 43 } |
44 | 44 |
45 download_latest_trace() { | 45 download_latest_trace() { |
46 TRACE_FILE=$(adb logcat -d | \ | 46 (adb logcat -d | grep -q "Logging performance trace to file") || { |
47 grep "Logging performance trace to file: " | \ | 47 echo "WARNING: Trace start marker not found. Is the correct version of Chrom
e running?" |
48 tail -1 | \ | 48 } |
49 perl -pi -e "s/.*\/storage\/emulated\/.+\/([^\r]+).*/\/sdcard\/Download\/\
\1/g") | 49 |
50 if [ -z "$TRACE_FILE" ]; then | 50 local ITERATION=0 |
51 echo "Unable to determine trace file name" | 51 while true; do |
52 exit 1 | 52 # Chrome logs two different messages related to tracing: |
53 fi | 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 |
54 | 85 |
55 adb pull $TRACE_FILE 2> /dev/null | 86 adb pull $TRACE_FILE 2> /dev/null |
56 LOCAL_TRACE_FILE=$(basename $TRACE_FILE) | 87 LOCAL_TRACE_FILE=$(basename $TRACE_FILE) |
57 if [ ! -f "$LOCAL_TRACE_FILE" ]; then | 88 if [ ! -f "$LOCAL_TRACE_FILE" ]; then |
58 echo "Unable to download trace file" | 89 echo "Unable to download trace file" |
59 exit 1 | 90 exit 1 |
60 fi | 91 fi |
61 } | 92 } |
62 | 93 |
63 do_timed_capture() { | 94 do_timed_capture() { |
64 local PACKAGE=$1 | 95 local PACKAGE=$1 |
65 local INTERVAL=$2 | 96 local INTERVAL=$2 |
66 shift | 97 shift |
67 shift | 98 shift |
68 echo -n "Capturing trace..." | 99 echo -n "Capturing trace..." |
69 send_intent ${PACKAGE} "GPU_PROFILER_START" $* > /dev/null | 100 send_intent ${PACKAGE} "GPU_PROFILER_START" $* > /dev/null |
70 sleep ${INTERVAL} | 101 sleep ${INTERVAL} |
71 send_intent ${PACKAGE} "GPU_PROFILER_STOP" > /dev/null | 102 send_intent ${PACKAGE} "GPU_PROFILER_STOP" > /dev/null |
72 echo "done" | 103 echo "done" |
73 | 104 |
74 echo -n "Downloading trace..." | 105 echo -n "Downloading trace..." |
75 sleep $[${INTERVAL} / 4 + 1] | |
76 download_latest_trace | 106 download_latest_trace |
77 echo "done" | 107 echo "done" |
78 | 108 |
79 echo "Trace written to ${PWD}/${LOCAL_TRACE_FILE}" | 109 echo "Trace written to ${PWD}/${LOCAL_TRACE_FILE}" |
80 } | 110 } |
81 | 111 |
82 PACKAGE=${DEFAULT_PACKAGE:-com.android.chrome} | 112 PACKAGE=${DEFAULT_PACKAGE:-com.android.chrome} |
83 | 113 |
84 while test -n "$1"; do | 114 while test -n "$1"; do |
85 case "$1" in | 115 case "$1" in |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 if [ -z "${INTERVAL}" ] ; then | 163 if [ -z "${INTERVAL}" ] ; then |
134 if [ -z "${FUNCTION}" ] ; then | 164 if [ -z "${FUNCTION}" ] ; then |
135 usage | 165 usage |
136 else | 166 else |
137 send_intent ${PACKAGE} ${FUNCTION} ${OUTPUT} ${CATEGORIES} ${CONTINUOUS} | 167 send_intent ${PACKAGE} ${FUNCTION} ${OUTPUT} ${CATEGORIES} ${CONTINUOUS} |
138 fi | 168 fi |
139 else | 169 else |
140 do_timed_capture ${PACKAGE} ${INTERVAL} ${CATEGORIES} ${CONTINUOUS} | 170 do_timed_capture ${PACKAGE} ${INTERVAL} ${CATEGORIES} ${CONTINUOUS} |
141 fi | 171 fi |
142 exit 0 | 172 exit 0 |
OLD | NEW |