1#!/usr/bin/python
2# Copyright (c) 2011 The Native Client 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.
5
6import re
7import sys
8
9# Combine chromium-style perf log output from multiple runs.
10# Input is text *containing* the chrome buildbot perf format (may contain more)
11# but the output is only the merged perf data (throws away the rest).
12
13def ListToString(l):
14  return '[%s]' % (','.join(l))
15
16
17def Main():
18  usage = 'usage: %prog < stdin\n'
19  if len(sys.argv) != 1:
20    sys.stderr.write(usage)
21    sys.stderr.write('Instead, argv was %s\n' % str(sys.argv))
22    return 1
23  accumulated_times = {}
24  result_matcher = re.compile(r'^RESULT (.*): (.*)= (.*) (.*)$')
25  for line in sys.stdin.readlines():
26    match = result_matcher.match(line)
27    if match:
28      graph, trace, value, unit = match.groups()
29      key = (graph, trace)
30      value_list, old_unit = accumulated_times.get(key, ([], None))
31      if old_unit is not None:
32        assert(unit == old_unit), (unit, old_unit)
33      if isinstance(value, list):
34        value_list += value
35      else:
36        value_list.append(value)
37      accumulated_times[key] = (value_list, unit)
38  for ((graph, trace), (values, unit)) in accumulated_times.iteritems():
39    sys.stdout.write('RESULT %s: %s= %s %s\n' %
40                     (graph, trace, ListToString(values), unit))
41  return 0
42
43
44if __name__ == '__main__':
45  sys.exit(Main())
46