summaryrefslogtreecommitdiffstats
path: root/build/android/adb_profile_chrome
diff options
context:
space:
mode:
authorskyostil@chromium.org <skyostil@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-29 14:38:51 +0000
committerskyostil@chromium.org <skyostil@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-29 14:38:51 +0000
commit4eb59ffc6ecab88cfad8e6dfc4ffcd74a26a7329 (patch)
treec159423eff23b9538438bf9ca284a5502dd2e4e5 /build/android/adb_profile_chrome
parent8c0bb39e6dd9dde57aebd869a6b7dead9549975b (diff)
downloadchromium_src-4eb59ffc6ecab88cfad8e6dfc4ffcd74a26a7329.zip
chromium_src-4eb59ffc6ecab88cfad8e6dfc4ffcd74a26a7329.tar.gz
chromium_src-4eb59ffc6ecab88cfad8e6dfc4ffcd74a26a7329.tar.bz2
android: Wait for Chrome to finish writing trace file before downloading
When downloading the latest trace file from Chrome, wait for Chrome to actually finish writing it to avoid getting back a partially written trace. Chrome logs two different messages related to tracing: 1. "Logging performance trace to file [...]" 2. "Profiler finished. Results are in [...]" The first one is printed when tracing starts and the second one indicates that the trace file is ready to be downloaded. We have to look for both of these messages to make sure we get the results from the latest trace and that the trace file is complete. This is done by first looking for the last instance of the first message and then checking for the second message in the remaining part of the log. Review URL: https://chromiumcodereview.appspot.com/23477016 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@220298 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'build/android/adb_profile_chrome')
-rwxr-xr-xbuild/android/adb_profile_chrome48
1 files changed, 39 insertions, 9 deletions
diff --git a/build/android/adb_profile_chrome b/build/android/adb_profile_chrome
index 79a3d5d..0a7199f 100755
--- a/build/android/adb_profile_chrome
+++ b/build/android/adb_profile_chrome
@@ -43,14 +43,45 @@ send_intent() {
}
download_latest_trace() {
- TRACE_FILE=$(adb logcat -d | \
- grep "Logging performance trace to file: " | \
- tail -1 | \
- perl -pi -e "s/.*\/storage\/emulated\/.+\/([^\r]+).*/\/sdcard\/Download\/\\1/g")
- if [ -z "$TRACE_FILE" ]; then
- echo "Unable to determine trace file name"
- exit 1
- fi
+ (adb logcat -d | grep -q "Logging performance trace to file") || {
+ echo "WARNING: Trace start marker not found. Is the correct version of Chrome running?"
+ }
+
+ local ITERATION=0
+ while true; do
+ # Chrome logs two different messages related to tracing:
+ #
+ # 1. "Logging performance trace to file [...]"
+ # 2. "Profiler finished. Results are in [...]"
+ #
+ # The first one is printed when tracing starts and the second one indicates
+ # that the trace file is ready to be downloaded.
+ #
+ # We have to look for both of these messages to make sure we get the results
+ # from the latest trace and that the trace file is complete. This is done by
+ # first looking for the last instance of the first message and then checking
+ # for the second message in the remaining part of the log.
+ TRACE_FILE=$(adb logcat -d | \
+ tac | \
+ grep --max-count=1 --before-context=100000 "Logging performance trace to file" | \
+ tac | \
+ grep "Profiler finished[.] Results are in " | \
+ perl -pi -e "s{.*/storage/emulated/.+/([^\r]+)[.].*}{/sdcard/Download/\\1}g")
+ if [ -n "$TRACE_FILE" ]; then
+ break
+ fi
+ if [ $ITERATION -eq 0 ]; then
+ echo -n "Waiting for Chrome to finish tracing..."
+ else
+ echo -n "."
+ fi
+ let ITERATION=ITERATION+1
+ if [ $ITERATION -eq 60 ]; then
+ echo "Timed out"
+ exit 1
+ fi
+ sleep 1
+ done
adb pull $TRACE_FILE 2> /dev/null
LOCAL_TRACE_FILE=$(basename $TRACE_FILE)
@@ -72,7 +103,6 @@ do_timed_capture() {
echo "done"
echo -n "Downloading trace..."
- sleep $[${INTERVAL} / 4 + 1]
download_latest_trace
echo "done"