Quentin Perret | baedd67 | 2017-07-04 17:57:16 +0100 | [diff] [blame] | 1 | # Copyright 2017 ARM Limited |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | |
| 15 | import re |
Quentin Perret | 34d73e6 | 2017-08-17 10:40:10 +0100 | [diff] [blame] | 16 | import logging |
| 17 | |
| 18 | from devlib.utils.types import numeric |
Quentin Perret | baedd67 | 2017-07-04 17:57:16 +0100 | [diff] [blame] | 19 | |
| 20 | |
| 21 | GEM5STATS_FIELD_REGEX = re.compile("^(?P<key>[^- ]\S*) +(?P<value>[^#]+).+$") |
| 22 | GEM5STATS_DUMP_HEAD = '---------- Begin Simulation Statistics ----------' |
| 23 | GEM5STATS_DUMP_TAIL = '---------- End Simulation Statistics ----------' |
| 24 | GEM5STATS_ROI_NUMBER = 8 |
| 25 | |
Quentin Perret | 34d73e6 | 2017-08-17 10:40:10 +0100 | [diff] [blame] | 26 | logger = logging.getLogger('gem5') |
| 27 | |
Quentin Perret | baedd67 | 2017-07-04 17:57:16 +0100 | [diff] [blame] | 28 | |
| 29 | def iter_statistics_dump(stats_file): |
| 30 | ''' |
| 31 | Yields statistics dumps as dicts. The parameter is assumed to be a stream |
| 32 | reading from the statistics log file. |
| 33 | ''' |
| 34 | cur_dump = {} |
| 35 | while True: |
| 36 | line = stats_file.readline() |
| 37 | if not line: |
| 38 | break |
| 39 | if GEM5STATS_DUMP_TAIL in line: |
| 40 | yield cur_dump |
| 41 | cur_dump = {} |
| 42 | else: |
| 43 | res = GEM5STATS_FIELD_REGEX.match(line) |
| 44 | if res: |
| 45 | k = res.group("key") |
Quentin Perret | 34d73e6 | 2017-08-17 10:40:10 +0100 | [diff] [blame] | 46 | vtext = res.group("value") |
| 47 | try: |
| 48 | v = map(numeric, vtext.split()) |
| 49 | cur_dump[k] = v[0] if len(v)==1 else set(v) |
| 50 | except ValueError: |
| 51 | msg = 'Found non-numeric entry in gem5 stats ({}: {})' |
| 52 | logger.warning(msg.format(k, vtext)) |
Quentin Perret | baedd67 | 2017-07-04 17:57:16 +0100 | [diff] [blame] | 53 | |