Mercurial > hg > graal-jvmci-8
comparison 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 |
comparison
equal
deleted
inserted
replaced
7563:3aab15f42934 | 7564:c420a487b10f |
---|---|
37 record = matcher.parse(output) | 37 record = matcher.parse(output) |
38 if record: | 38 if record: |
39 records.append(record) | 39 records.append(record) |
40 return records | 40 return records |
41 | 41 |
42 class Matcher: | 42 """ |
43 Produces some named values for some given text if it matches a given | |
44 regular expression. The named values are specified by a dictionary | |
45 where any keys or value may be expressed as named group in the | |
46 regular expression. A named group is enclosed in '<' and '>'. | |
47 """ | |
48 class ValuesMatcher: | |
43 | 49 |
44 def __init__(self, regex, valuesTemplate): | 50 def __init__(self, regex, valuesTemplate): |
45 assert isinstance(valuesTemplate, dict) | 51 assert isinstance(valuesTemplate, dict) |
46 self.regex = regex | 52 self.regex = regex |
47 self.valuesTemplate = valuesTemplate | 53 self.valuesTemplate = valuesTemplate |
50 match = self.regex.search(text) | 56 match = self.regex.search(text) |
51 if not match: | 57 if not match: |
52 return False | 58 return False |
53 values = {} | 59 values = {} |
54 for key, value in self.valuesTemplate.items(): | 60 for key, value in self.valuesTemplate.items(): |
55 values[self.get_value_or_const(match, key)] = self.get_value_or_const(match, value) | 61 values[self.get_template_value(match, key)] = self.get_template_value(match, value) |
56 | 62 |
57 return values | 63 return values |
58 | 64 |
59 | 65 |
60 def get_value_or_const(self, match, name): | 66 def get_template_value(self, match, template): |
61 if name.startswith('const:'): | 67 if template.startswith('<'): |
62 return name.split(':')[1] | 68 assert template.endswith('>') |
69 groupName = template[1:-1] | |
70 return match.group(groupName) | |
63 else: | 71 else: |
64 return match.group(name) | 72 return template |