systrace: fix pipe reading

This change fixes a bug where systrace.py would neglect to read the end of the
data coming from its subprocess pipe.  This caused the --from-file argument to
produce HTML files containing truncated traces.

Change-Id: I265c9000ceff27debe2965a402fead4ff7ff8644
diff --git a/systrace.py b/systrace.py
index 83033e0..3b2585e 100755
--- a/systrace.py
+++ b/systrace.py
@@ -137,15 +137,23 @@
     result = adb.poll()
 
   # Read and buffer the data portion of the output.
-  while result is None:
+  while True:
     ready = select.select([adb.stdout, adb.stderr], [], [adb.stdout, adb.stderr])
+    keepReading = False
     if adb.stderr in ready[0]:
       err = os.read(adb.stderr.fileno(), 4096)
-      sys.stderr.write(err)
-      sys.stderr.flush()
+      if len(err) > 0:
+        keepReading = True
+        sys.stderr.write(err)
+        sys.stderr.flush()
     if adb.stdout in ready[0]:
       out = os.read(adb.stdout.fileno(), 4096)
-      data.append(out)
+      if len(out) > 0:
+        keepReading = True
+        data.append(out)
+
+    if result is not None and not keepReading:
+      break
 
     result = adb.poll()