Exemple #1
0
    def _goto_dump(self, stats_file, target_dump):
        if target_dump < 0:
            raise HostError('Cannot go to dump {}'.format(target_dump))

        # Go to required dump quickly if it was visited before
        if target_dump in self._dump_pos_cache:
            stats_file.seek(self._dump_pos_cache[target_dump])
            return target_dump
        # Or start from the closest dump already visited before the required one
        prev_dumps = filter(lambda x: x < target_dump, self._dump_pos_cache.keys())
        curr_dump = max(prev_dumps)
        curr_pos = self._dump_pos_cache[curr_dump]
        stats_file.seek(curr_pos)

        # And iterate until target_dump
        dump_iterator = iter_statistics_dump(stats_file)
        while curr_dump < target_dump:
            try:
                next(dump_iterator)
            except StopIteration:
                break
            # End of passed dump is beginning og next one
            curr_pos = stats_file.tell()
            curr_dump += 1
        self._dump_pos_cache[curr_dump] = curr_pos
        return curr_dump
Exemple #2
0
    def match_iter(self, keys, rois_labels):
        '''
        Yields for each dump since origin a pair containing:
        1. a dict storing the values corresponding to each of the specified keys
        2. the list of currently active ROIs among those passed as parameters.

        Keys must match fields in gem5's statistics log file. Key example:
            system.cluster0.cores0.power_model.static_power
        '''
        for label in rois_labels:
            if label not in self.rois:
                raise KeyError(
                    'Impossible to match ROI label {}'.format(label))
            if self.rois[label].running:
                self.logger.warning(
                    'Trying to match records in statistics file'
                    ' while ROI {} is running'.format(label))

        def roi_active(roi_label, dump):
            roi = self.rois[roi_label]
            return (roi.field in dump) and (int(dump[roi.field]) == 1)

        with open(self._stats_file_path, 'r') as stats_file:
            stats_file.seek(self._current_origin)
            for dump in iter_statistics_dump(stats_file):
                active_rois = [l for l in rois_labels if roi_active(l, dump)]
                if active_rois:
                    record = {k: dump[k] for k in keys}
                    yield (record, active_rois)
Exemple #3
0
    def _goto_dump(self, stats_file, target_dump):
        if target_dump < 0:
            raise HostError('Cannot go to dump {}'.format(target_dump))

        # Go to required dump quickly if it was visited before
        if target_dump in self._dump_pos_cache:
            stats_file.seek(self._dump_pos_cache[target_dump])
            return target_dump
        # Or start from the closest dump already visited before the required one
        prev_dumps = filter(lambda x: x < target_dump, self._dump_pos_cache.keys())
        curr_dump = max(prev_dumps)
        curr_pos = self._dump_pos_cache[curr_dump]
        stats_file.seek(curr_pos)
        
        # And iterate until target_dump
        dump_iterator = iter_statistics_dump(stats_file)
        while curr_dump < target_dump:
            try:
                dump = dump_iterator.next()
            except StopIteration:
                break
            # End of passed dump is beginning og next one
            curr_pos = stats_file.tell()
            curr_dump += 1
        self._dump_pos_cache[curr_dump] = curr_pos
        return curr_dump
Exemple #4
0
    def match_iter(self, keys, rois_labels, base_dump=0):
        '''
        Yield specific values dump-by-dump from the statistics log file of gem5

        :param keys: same as ``match()``
        :param rois_labels: same as ``match()``
        :param base_dump: same as ``match()``
        :returns: a pair containing:
            1. a dict storing the values corresponding to each of the found keys
            2. the list of currently active ROIs among those passed as parameters

        Example of return value:
         * Result of match_iter(['sim_'],['roi_1', 'roi_2']).next()
            ( 
                { 
                    'sim_inst': 265300176,
                    'sim_ops': 324395787,
                    'sim_seconds': 0.199960, 
                    'sim_freq': 1000000000000,
                    'sim_ticks': 199960234227,
                },
                [ 'roi_1 ' ] 
            )
        '''
        for label in rois_labels:
            if label not in self.rois:
                raise KeyError(
                    'Impossible to match ROI label {}'.format(label))
            if self.rois[label].running:
                self.logger.warning(
                    'Trying to match records in statistics file'
                    ' while ROI {} is running'.format(label))

        # Construct one large regex that concatenates all keys because
        # matching one large expression is more efficient than several smaller
        all_keys_re = re.compile('|'.join(keys))

        def roi_active(roi_label, dump):
            roi = self.rois[roi_label]
            return (roi.field in dump) and (int(dump[roi.field]) == 1)

        with open(self._stats_file_path, 'r') as stats_file:
            self._goto_dump(stats_file, base_dump)
            for dump in iter_statistics_dump(stats_file):
                active_rois = [l for l in rois_labels if roi_active(l, dump)]
                if active_rois:
                    rec = {k: dump[k] for k in dump if all_keys_re.search(k)}
                    yield (rec, active_rois)
Exemple #5
0
    def match_iter(self, keys, rois_labels, base_dump=0):
        '''
        Yield specific values dump-by-dump from the statistics log file of gem5

        :param keys: same as ``match()``
        :param rois_labels: same as ``match()``
        :param base_dump: same as ``match()``
        :returns: a pair containing:
            1. a dict storing the values corresponding to each of the found keys
            2. the list of currently active ROIs among those passed as parameters

        Example of return value:
         * Result of match_iter(['sim_'],['roi_1', 'roi_2']).next()
            ( 
                { 
                    'sim_inst': 265300176,
                    'sim_ops': 324395787,
                    'sim_seconds': 0.199960, 
                    'sim_freq': 1000000000000,
                    'sim_ticks': 199960234227,
                },
                [ 'roi_1 ' ] 
            )
        '''
        for label in rois_labels:
            if label not in self.rois:
                raise KeyError('Impossible to match ROI label {}'.format(label))
            if self.rois[label].running:
                self.logger.warning('Trying to match records in statistics file'
                        ' while ROI {} is running'.format(label))
        
        # Construct one large regex that concatenates all keys because
        # matching one large expression is more efficient than several smaller
        all_keys_re = re.compile('|'.join(keys))
        
        def roi_active(roi_label, dump):
            roi = self.rois[roi_label]
            return (roi.field in dump) and (int(dump[roi.field]) == 1)

        with open(self._stats_file_path, 'r') as stats_file:
            self._goto_dump(stats_file, base_dump)
            for dump in iter_statistics_dump(stats_file):
                active_rois = [l for l in rois_labels if roi_active(l, dump)]
                if active_rois:
                    rec = {k: dump[k] for k in dump if all_keys_re.search(k)}
                    yield (rec, active_rois)