Update sdk/platform-tools to version 26.0.0.
[android_tools.git] / sdk / platform-tools / systrace / catapult / telemetry / list_telemetry_unittests
blob8f420c63ff32ed2da85da578b079a0d25ac87b34
1 #!/usr/bin/env python
2 # Copyright 2015 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
6 import argparse
7 import sys
10 def _ExtractQueuedTestName(line):
11 _, test_name, _ = line.split(' ')
12 return test_name
15 def _ExtractPassedTestNameAndTime(line):
16 _, test_name, _, test_time_string = line.split(' ')
17 if test_time_string.endswith(':'):
18 test_time = float(test_time_string[:-2])
19 else:
20 test_time = float(test_time_string[:-1])
21 return test_name, test_time
24 def _IsQueued(line):
25 return line.endswith(' queued')
28 def _IsPassed(line):
29 return 'passed' in line.split(' ')
32 def _ProcessLogFile(file_path):
33 passed_unittests = []
34 queued_unittests = []
35 with open(file_path, 'r') as f:
36 for line in f:
37 line = line.strip()
38 if not line.startswith('['):
39 continue
40 if _IsQueued(line):
41 queued_unittests.append(_ExtractQueuedTestName(line))
42 elif _IsPassed(line):
43 passed_unittests.append(_ExtractPassedTestNameAndTime(line))
44 queued_unittests.sort()
45 passed_unittests.sort(key=lambda v: -v[1])
46 return queued_unittests, passed_unittests
49 def main(args):
50 parser = argparse.ArgumentParser(
51 description=('Process telemetry unittests log to print out passed '
52 'or queued tests.'))
53 parser.add_argument(
54 'filepath', help='path to log file of telemetry unittest')
55 parser.add_argument(
56 '-q', '--list-queued-tests', action='store_true',
57 help='Also list all the queued telemetry unittests')
58 options = parser.parse_args(args)
59 queued_unittests, passed_unittests = _ProcessLogFile(options.filepath)
60 print 'All passed telemetry unittests:\n'
61 for test, time in passed_unittests:
62 print test, time
63 if options.list_queued_tests:
64 print 'All queued telemetry unittests:\n'
65 print '\n'.join(queued_unittests)
66 return 0
69 if __name__ == '__main__':
70 sys.exit(main(sys.argv[1:]))