systrace: add support for using a trace file
Change-Id: I58f210f3f67a2de92b93829856c9a969906946c3
diff --git a/systrace.py b/systrace.py
index ddc6d3e..87905fc 100755
--- a/systrace.py
+++ b/systrace.py
@@ -67,6 +67,8 @@
parser.add_option('--link-assets', dest='link_assets', default=False,
action='store_true', help='link to original CSS or JS resources '
'instead of embedding them')
+ parser.add_option('--from-file', dest='from_file', action='store',
+ help='read the trace from a file rather than running a live trace')
parser.add_option('--asset-dir', dest='asset_dir', default='trace-viewer',
type='string', help='')
parser.add_option('-e', '--serial', dest='device_serial', type='string',
@@ -122,6 +124,9 @@
else:
parser.error('the trace buffer size must be a positive number')
+ if options.from_file is not None:
+ atrace_args = ['cat', options.from_file]
+
script_dir = os.path.dirname(os.path.abspath(sys.argv[0]))
if options.link_assets:
@@ -154,7 +159,8 @@
sys.stderr.flush()
if adb.stdout in ready[0]:
out = leftovers + os.read(adb.stdout.fileno(), 4096)
- out = out.replace('\r\n', '\n')
+ if options.from_file is None:
+ out = out.replace('\r\n', '\n')
if out.endswith('\r'):
out = out[:-1]
leftovers = '\r'