perfetto: Use push --sync where possible in tools/tmux

adb push --sync doesn't send the file if the host version
hasn't been updated. This is much faster when repeatedly running
tools/tmux however the feature is only available in recent adb
versions. This Cl makes tools/tmux use it where it is available.

TBR: primiano@google.com
Change-Id: Ieb20e980b7d5c75919ec620d7e01fc9e25ca61e2
diff --git a/tools/tmux b/tools/tmux
index 1c5c371..b10ff5e 100755
--- a/tools/tmux
+++ b/tools/tmux
@@ -14,12 +14,25 @@
 # limitations under the License.
 set -e
 
-function is_monolithic() {
+function is_monolithic {
   local out=$1
   gn args $out --list --short | grep 'monolithic_binaries = true' > /dev/null
   return $?
 }
 
+function adb_supports_push_sync {
+  adb --help | grep 'push.*\[--sync\]'
+}
+
+function push {
+  local maybe_sync=''
+  if adb_supports_push_sync; then
+    maybe_sync='--sync '
+  fi
+  echo adb push $maybe_sync $1 $2
+  adb push $maybe_sync $1 $2
+}
+
 # If not set guess the OUT dir using the latest directory.
 if [ ! -f "$OUT/args.gn" ]; then
   echo "OUT=$OUT doesn't look like an output directory."
@@ -33,11 +46,9 @@
 
 ninja -C $OUT traced traced_probes perfetto trace_to_text test/configs
 
-set -x
-adb push $OUT/traced /data/local/tmp/
-adb push $OUT/traced_probes /data/local/tmp/
-adb push $OUT/perfetto /data/local/tmp/
-set +x
+push $OUT/traced /data/local/tmp/
+push $OUT/traced_probes /data/local/tmp/
+push $OUT/perfetto /data/local/tmp/
 
 PREFIX=""
 if ! is_monolithic $OUT;  then