Mercurial > hg > truffle
annotate mx/outputparser.py @ 7564:c420a487b10f
changed convention for specifying constants versus named groups in a template for a value to extract from the output of a benchmark execution
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Wed, 30 Jan 2013 11:33:31 +0100 |
parents | 3aab15f42934 |
children | a8bc60aeacb8 |
rev | line source |
---|---|
4225
339cf8d4904d
Made mx.run work properly when stderr is redirected to stdout.
Doug Simon <doug.simon@oracle.com>
parents:
4219
diff
changeset
|
1 # ---------------------------------------------------------------------------------------------------- |
339cf8d4904d
Made mx.run work properly when stderr is redirected to stdout.
Doug Simon <doug.simon@oracle.com>
parents:
4219
diff
changeset
|
2 # |
339cf8d4904d
Made mx.run work properly when stderr is redirected to stdout.
Doug Simon <doug.simon@oracle.com>
parents:
4219
diff
changeset
|
3 # Copyright (c) 2007, 2012, Oracle and/or its affiliates. All rights reserved. |
339cf8d4904d
Made mx.run work properly when stderr is redirected to stdout.
Doug Simon <doug.simon@oracle.com>
parents:
4219
diff
changeset
|
4 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
339cf8d4904d
Made mx.run work properly when stderr is redirected to stdout.
Doug Simon <doug.simon@oracle.com>
parents:
4219
diff
changeset
|
5 # |
339cf8d4904d
Made mx.run work properly when stderr is redirected to stdout.
Doug Simon <doug.simon@oracle.com>
parents:
4219
diff
changeset
|
6 # This code is free software; you can redistribute it and/or modify it |
339cf8d4904d
Made mx.run work properly when stderr is redirected to stdout.
Doug Simon <doug.simon@oracle.com>
parents:
4219
diff
changeset
|
7 # under the terms of the GNU General Public License version 2 only, as |
339cf8d4904d
Made mx.run work properly when stderr is redirected to stdout.
Doug Simon <doug.simon@oracle.com>
parents:
4219
diff
changeset
|
8 # published by the Free Software Foundation. |
339cf8d4904d
Made mx.run work properly when stderr is redirected to stdout.
Doug Simon <doug.simon@oracle.com>
parents:
4219
diff
changeset
|
9 # |
339cf8d4904d
Made mx.run work properly when stderr is redirected to stdout.
Doug Simon <doug.simon@oracle.com>
parents:
4219
diff
changeset
|
10 # This code is distributed in the hope that it will be useful, but WITHOUT |
339cf8d4904d
Made mx.run work properly when stderr is redirected to stdout.
Doug Simon <doug.simon@oracle.com>
parents:
4219
diff
changeset
|
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
339cf8d4904d
Made mx.run work properly when stderr is redirected to stdout.
Doug Simon <doug.simon@oracle.com>
parents:
4219
diff
changeset
|
12 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
339cf8d4904d
Made mx.run work properly when stderr is redirected to stdout.
Doug Simon <doug.simon@oracle.com>
parents:
4219
diff
changeset
|
13 # version 2 for more details (a copy is included in the LICENSE file that |
339cf8d4904d
Made mx.run work properly when stderr is redirected to stdout.
Doug Simon <doug.simon@oracle.com>
parents:
4219
diff
changeset
|
14 # accompanied this code). |
339cf8d4904d
Made mx.run work properly when stderr is redirected to stdout.
Doug Simon <doug.simon@oracle.com>
parents:
4219
diff
changeset
|
15 # |
339cf8d4904d
Made mx.run work properly when stderr is redirected to stdout.
Doug Simon <doug.simon@oracle.com>
parents:
4219
diff
changeset
|
16 # You should have received a copy of the GNU General Public License version |
339cf8d4904d
Made mx.run work properly when stderr is redirected to stdout.
Doug Simon <doug.simon@oracle.com>
parents:
4219
diff
changeset
|
17 # 2 along with this work; if not, write to the Free Software Foundation, |
339cf8d4904d
Made mx.run work properly when stderr is redirected to stdout.
Doug Simon <doug.simon@oracle.com>
parents:
4219
diff
changeset
|
18 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
339cf8d4904d
Made mx.run work properly when stderr is redirected to stdout.
Doug Simon <doug.simon@oracle.com>
parents:
4219
diff
changeset
|
19 # |
339cf8d4904d
Made mx.run work properly when stderr is redirected to stdout.
Doug Simon <doug.simon@oracle.com>
parents:
4219
diff
changeset
|
20 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
339cf8d4904d
Made mx.run work properly when stderr is redirected to stdout.
Doug Simon <doug.simon@oracle.com>
parents:
4219
diff
changeset
|
21 # or visit www.oracle.com if you need additional information or have any |
339cf8d4904d
Made mx.run work properly when stderr is redirected to stdout.
Doug Simon <doug.simon@oracle.com>
parents:
4219
diff
changeset
|
22 # questions. |
339cf8d4904d
Made mx.run work properly when stderr is redirected to stdout.
Doug Simon <doug.simon@oracle.com>
parents:
4219
diff
changeset
|
23 # |
339cf8d4904d
Made mx.run work properly when stderr is redirected to stdout.
Doug Simon <doug.simon@oracle.com>
parents:
4219
diff
changeset
|
24 # ---------------------------------------------------------------------------------------------------- |
339cf8d4904d
Made mx.run work properly when stderr is redirected to stdout.
Doug Simon <doug.simon@oracle.com>
parents:
4219
diff
changeset
|
25 |
4151 | 26 class OutputParser: |
27 | |
7563
3aab15f42934
moved execution of a benchmark out of OutputParser
Doug Simon <doug.simon@oracle.com>
parents:
4282
diff
changeset
|
28 def __init__(self): |
4151 | 29 self.matchers = [] |
30 | |
31 def addMatcher(self, matcher): | |
32 self.matchers.append(matcher) | |
33 | |
7563
3aab15f42934
moved execution of a benchmark out of OutputParser
Doug Simon <doug.simon@oracle.com>
parents:
4282
diff
changeset
|
34 def parse(self, output): |
3aab15f42934
moved execution of a benchmark out of OutputParser
Doug Simon <doug.simon@oracle.com>
parents:
4282
diff
changeset
|
35 records = [] |
3aab15f42934
moved execution of a benchmark out of OutputParser
Doug Simon <doug.simon@oracle.com>
parents:
4282
diff
changeset
|
36 for matcher in self.matchers: |
3aab15f42934
moved execution of a benchmark out of OutputParser
Doug Simon <doug.simon@oracle.com>
parents:
4282
diff
changeset
|
37 record = matcher.parse(output) |
3aab15f42934
moved execution of a benchmark out of OutputParser
Doug Simon <doug.simon@oracle.com>
parents:
4282
diff
changeset
|
38 if record: |
3aab15f42934
moved execution of a benchmark out of OutputParser
Doug Simon <doug.simon@oracle.com>
parents:
4282
diff
changeset
|
39 records.append(record) |
3aab15f42934
moved execution of a benchmark out of OutputParser
Doug Simon <doug.simon@oracle.com>
parents:
4282
diff
changeset
|
40 return records |
4151 | 41 |
7564
c420a487b10f
changed convention for specifying constants versus named groups in a template for a value to extract from the output of a benchmark execution
Doug Simon <doug.simon@oracle.com>
parents:
7563
diff
changeset
|
42 """ |
c420a487b10f
changed convention for specifying constants versus named groups in a template for a value to extract from the output of a benchmark execution
Doug Simon <doug.simon@oracle.com>
parents:
7563
diff
changeset
|
43 Produces some named values for some given text if it matches a given |
c420a487b10f
changed convention for specifying constants versus named groups in a template for a value to extract from the output of a benchmark execution
Doug Simon <doug.simon@oracle.com>
parents:
7563
diff
changeset
|
44 regular expression. The named values are specified by a dictionary |
c420a487b10f
changed convention for specifying constants versus named groups in a template for a value to extract from the output of a benchmark execution
Doug Simon <doug.simon@oracle.com>
parents:
7563
diff
changeset
|
45 where any keys or value may be expressed as named group in the |
c420a487b10f
changed convention for specifying constants versus named groups in a template for a value to extract from the output of a benchmark execution
Doug Simon <doug.simon@oracle.com>
parents:
7563
diff
changeset
|
46 regular expression. A named group is enclosed in '<' and '>'. |
c420a487b10f
changed convention for specifying constants versus named groups in a template for a value to extract from the output of a benchmark execution
Doug Simon <doug.simon@oracle.com>
parents:
7563
diff
changeset
|
47 """ |
c420a487b10f
changed convention for specifying constants versus named groups in a template for a value to extract from the output of a benchmark execution
Doug Simon <doug.simon@oracle.com>
parents:
7563
diff
changeset
|
48 class ValuesMatcher: |
4151 | 49 |
7563
3aab15f42934
moved execution of a benchmark out of OutputParser
Doug Simon <doug.simon@oracle.com>
parents:
4282
diff
changeset
|
50 def __init__(self, regex, valuesTemplate): |
3aab15f42934
moved execution of a benchmark out of OutputParser
Doug Simon <doug.simon@oracle.com>
parents:
4282
diff
changeset
|
51 assert isinstance(valuesTemplate, dict) |
4151 | 52 self.regex = regex |
7563
3aab15f42934
moved execution of a benchmark out of OutputParser
Doug Simon <doug.simon@oracle.com>
parents:
4282
diff
changeset
|
53 self.valuesTemplate = valuesTemplate |
4151 | 54 |
7563
3aab15f42934
moved execution of a benchmark out of OutputParser
Doug Simon <doug.simon@oracle.com>
parents:
4282
diff
changeset
|
55 def parse(self, text): |
3aab15f42934
moved execution of a benchmark out of OutputParser
Doug Simon <doug.simon@oracle.com>
parents:
4282
diff
changeset
|
56 match = self.regex.search(text) |
4151 | 57 if not match: |
58 return False | |
7563
3aab15f42934
moved execution of a benchmark out of OutputParser
Doug Simon <doug.simon@oracle.com>
parents:
4282
diff
changeset
|
59 values = {} |
3aab15f42934
moved execution of a benchmark out of OutputParser
Doug Simon <doug.simon@oracle.com>
parents:
4282
diff
changeset
|
60 for key, value in self.valuesTemplate.items(): |
7564
c420a487b10f
changed convention for specifying constants versus named groups in a template for a value to extract from the output of a benchmark execution
Doug Simon <doug.simon@oracle.com>
parents:
7563
diff
changeset
|
61 values[self.get_template_value(match, key)] = self.get_template_value(match, value) |
7563
3aab15f42934
moved execution of a benchmark out of OutputParser
Doug Simon <doug.simon@oracle.com>
parents:
4282
diff
changeset
|
62 |
3aab15f42934
moved execution of a benchmark out of OutputParser
Doug Simon <doug.simon@oracle.com>
parents:
4282
diff
changeset
|
63 return values |
3aab15f42934
moved execution of a benchmark out of OutputParser
Doug Simon <doug.simon@oracle.com>
parents:
4282
diff
changeset
|
64 |
4151 | 65 |
7564
c420a487b10f
changed convention for specifying constants versus named groups in a template for a value to extract from the output of a benchmark execution
Doug Simon <doug.simon@oracle.com>
parents:
7563
diff
changeset
|
66 def get_template_value(self, match, template): |
c420a487b10f
changed convention for specifying constants versus named groups in a template for a value to extract from the output of a benchmark execution
Doug Simon <doug.simon@oracle.com>
parents:
7563
diff
changeset
|
67 if template.startswith('<'): |
c420a487b10f
changed convention for specifying constants versus named groups in a template for a value to extract from the output of a benchmark execution
Doug Simon <doug.simon@oracle.com>
parents:
7563
diff
changeset
|
68 assert template.endswith('>') |
c420a487b10f
changed convention for specifying constants versus named groups in a template for a value to extract from the output of a benchmark execution
Doug Simon <doug.simon@oracle.com>
parents:
7563
diff
changeset
|
69 groupName = template[1:-1] |
c420a487b10f
changed convention for specifying constants versus named groups in a template for a value to extract from the output of a benchmark execution
Doug Simon <doug.simon@oracle.com>
parents:
7563
diff
changeset
|
70 return match.group(groupName) |
4151 | 71 else: |
7564
c420a487b10f
changed convention for specifying constants versus named groups in a template for a value to extract from the output of a benchmark execution
Doug Simon <doug.simon@oracle.com>
parents:
7563
diff
changeset
|
72 return template |