blob: 0ca42ec12ff226a10ab5fec737eeb5a5588a386b [file] [log] [blame]
Quentin Perretbaedd672017-07-04 17:57:16 +01001# 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
15import re
Quentin Perret34d73e62017-08-17 10:40:10 +010016import logging
17
18from devlib.utils.types import numeric
Quentin Perretbaedd672017-07-04 17:57:16 +010019
20
21GEM5STATS_FIELD_REGEX = re.compile("^(?P<key>[^- ]\S*) +(?P<value>[^#]+).+$")
22GEM5STATS_DUMP_HEAD = '---------- Begin Simulation Statistics ----------'
23GEM5STATS_DUMP_TAIL = '---------- End Simulation Statistics ----------'
24GEM5STATS_ROI_NUMBER = 8
25
Quentin Perret34d73e62017-08-17 10:40:10 +010026logger = logging.getLogger('gem5')
27
Quentin Perretbaedd672017-07-04 17:57:16 +010028
29def 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 Perret34d73e62017-08-17 10:40:10 +010046 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 Perretbaedd672017-07-04 17:57:16 +010053