OSDN Git Service

Merge "Remove system/extras/tests/bionic." am: 1205856a99
[android-x86/system-extras.git] / tests / workloads / atrace-uncompress.py
1 #
2 # Uncompress a file generated via atrace -z
3 #
4 # Usage: python atrace-uncompress.py infile > outfile
5 #
6 import sys, zlib
7
8 def main():
9
10         if len(sys.argv) != 2:
11                 print >> sys.stderr, ('Usage: %s inputfile' % sys.argv[0])
12                 sys.exit(1)
13
14         infile = open(sys.argv[1], "rb")
15         out = infile.read()
16         parts = out.split('\nTRACE:', 1)
17
18         data = ''.join(parts[1])
19
20         # Remove CR characters
21         if data.startswith('\r\n'):
22                 data = data.replace('\r\n', '\n')
23
24         # Skip the initial newline.
25         data = data[1:]
26
27         if not data:
28                 print >> sys.stderr, ('No trace data found')
29                 sys.exit(1)
30
31         out = zlib.decompress(data)
32         print(out)
33
34 if __name__ == '__main__':
35         main()