File: atrace-uncompress.py

package info (click to toggle)
android-platform-system-extras 7.0.0%2Br33-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 4,136 kB
  • sloc: cpp: 28,180; ansic: 14,543; python: 5,376; sh: 2,441; java: 908; asm: 299; makefile: 19; xml: 12
file content (35 lines) | stat: -rw-r--r-- 642 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#
# Uncompress a file generated via atrace -z
#
# Usage: python atrace-uncompress.py infile > outfile
#
import sys, zlib

def main():

	if len(sys.argv) != 2:
		print >> sys.stderr, ('Usage: %s inputfile' % sys.argv[0])
		sys.exit(1)

	infile = open(sys.argv[1], "rb")
	out = infile.read()
	parts = out.split('\nTRACE:', 1)

	data = ''.join(parts[1])

	# Remove CR characters
	if data.startswith('\r\n'):
		data = data.replace('\r\n', '\n')

	# Skip the initial newline.
	data = data[1:]

	if not data:
		print >> sys.stderr, ('No trace data found')
		sys.exit(1)

	out = zlib.decompress(data)
	print(out)

if __name__ == '__main__':
	main()