Beispiel #1
0
 def __enter__(self):
     MetricName.TEST_METRIC = 'test_metric'
     METRICS_METADATA['test_metric'] = MetricMetadata('Non existing metric for unit test.',
                                                      MetricType.COUNTER,
                                                      MetricUnit.NUMERIC,
                                                      MetricSource.CGROUP,
                                                      MetricGranularity.PLATFORM,
                                                      levels=['numa_node', 'container'],
                                                      enabled='no'
                                                      )
Beispiel #2
0
 def _get_unknown_event(event_name, event_value, umask, config, config1):
     event = Event(name=event_name, event=event_value, umask=umask,
                   config=config, config1=config1)
     metric_metadata = MetricMetadata('Uncore metric provided by user',
                                      MetricType.GAUGE,
                                      MetricUnit.NUMERIC,
                                      MetricSource.PERF_SUBSYSTEM_UNCORE,
                                      MetricGranularity.PLATFORM,
                                      ['socket', 'pmu_type'],
                                      'yes')
     add_metric(event_name, metric_metadata)
     return event
    def __init__(
            self,
            node: Node,
            metrics_storage: Storage = DEFAULT_STORAGE,
            interval: Numeric(0, 60) = 1.,
            rdt_enabled: Optional[bool] = None,
            gather_hw_mm_topology: bool = False,
            extra_labels: Optional[Dict[Str, Str]] = None,
            event_names: List[str] = [],
            perf_aggregate_cpus: bool = True,
            enable_derived_metrics: bool = False,
            enable_perf_uncore: Optional[bool] = None,
            task_label_generators: Optional[Dict[str, TaskLabelGenerator]] = None,
            allocation_configuration: Optional[AllocationConfiguration] = None,
            wss_reset_interval: int = 0,
            include_optional_labels: bool = False
    ):

        self._node = node
        self._metrics_storage = metrics_storage
        self._interval = interval
        self._rdt_enabled = rdt_enabled
        self._gather_hw_mm_topology = gather_hw_mm_topology
        self._include_optional_labels = include_optional_labels

        self._extra_labels = {k: str(v) for k, v in
                              extra_labels.items()} if extra_labels else dict()
        log.debug('Extra labels: %r', self._extra_labels)
        self._finish = False  # Guard to stop iterations.
        self._last_iteration = time.time()  # Used internally by wait function.
        self._allocation_configuration = allocation_configuration
        self._event_names = event_names
        log.info('Enabling %i perf events: %s', len(self._event_names),
                 ', '.join(self._event_names))
        self._perf_aggregate_cpus = perf_aggregate_cpus

        # TODO: fix those workarounds for dynamic levels and dynamic perf event metrics.
        # First add dynamic metrics
        for event_name in event_names:
            # is dynamic raw event
            if '__r' in event_name:
                log.debug('Creating metadata for dynamic metric: %r', event_name)
                METRICS_METADATA[event_name] = MetricMetadata(
                    'Hardware PMU counter (raw event)',
                    MetricType.COUNTER,
                    MetricUnit.NUMERIC,
                    MetricSource.PERF_SUBSYSTEM_WITH_CGROUPS,
                    MetricGranularity.TASK,
                    [],
                    'no (event_names)',
                )
        # We had the modify levels for all metrics
        # The set proper levels based on perf_aggregate_cpus value
        if not perf_aggregate_cpus:
            log.debug('Enabling "cpu" level for PERF_SUBSYSTEM_WITH_CGROUPS metrics.')
            for metric_metadata in METRICS_METADATA.values():
                if metric_metadata.source == MetricSource.PERF_SUBSYSTEM_WITH_CGROUPS:
                    metric_metadata.levels = ['cpu']

        self._enable_derived_metrics = enable_derived_metrics
        self._enable_perf_uncore = enable_perf_uncore

        # Default value for task_labels_generator.
        if task_label_generators is None:
            self._task_label_generators = {
                'application':
                    TaskLabelRegexGenerator('$', '', 'task_name'),
                'application_version_name':
                    TaskLabelRegexGenerator('.*$', '', 'task_name'),
            }
        else:
            self._task_label_generators = task_label_generators

        self._wss_reset_interval = wss_reset_interval

        self._uncore_pmu = None

        self._initialize_rdt_callback = None
        self._iterate_body_callback = None
Beispiel #4
0
    def __init__(
            self,
            node: Node,
            metrics_storage: Storage = DEFAULT_STORAGE,
            interval: Numeric(0, 60) = 1.,
            rdt_enabled: Optional[bool] = None,
            gather_hw_mm_topology: Optional[bool] = None,
            extra_labels: Optional[Dict[Str, Str]] = None,
            event_names: List[str] = [],
            perf_aggregate_cpus: bool = True,
            enable_derived_metrics: bool = False,
            uncore_event_names: List[Union[List[str], str]] = [],
            task_label_generators: Optional[Dict[str, TaskLabelGenerator]] = None,
            allocation_configuration: Optional[AllocationConfiguration] = None,
            wss_reset_cycles: Optional[int] = None,
            wss_stable_cycles: int = 0,
            wss_membw_threshold: Optional[float] = None,
            include_optional_labels: bool = False,
            zoneinfo: Union[Str, bool] = True,
            vmstat: Union[Str, bool] = True,
            sched: Union[Str, bool] = False,
    ):

        self._node = node
        self._metrics_storage = metrics_storage
        self._interval = interval
        self._rdt_enabled = rdt_enabled
        self._gather_hw_mm_topology = gather_hw_mm_topology
        self._include_optional_labels = include_optional_labels

        self._extra_labels = {k: str(v) for k, v in
                              extra_labels.items()} if extra_labels else dict()
        log.debug('Extra labels: %r', self._extra_labels)
        self._finish = False  # Guard to stop iterations.
        self._last_iteration = time.time()  # Used internally by wait function.
        self._allocation_configuration = allocation_configuration
        self._event_names = event_names
        self._perf_aggregate_cpus = perf_aggregate_cpus

        # TODO: fix those workarounds for dynamic levels and dynamic perf event metrics.
        # First add dynamic metrics
        for event_name in event_names:
            # is dynamic raw event
            if '__r' in event_name:
                log.debug('Creating metadata for dynamic metric: %r', event_name)
                METRICS_METADATA[event_name] = MetricMetadata(
                    'Hardware PMU counter (raw event)',
                    MetricType.COUNTER,
                    MetricUnit.NUMERIC,
                    MetricSource.PERF_SUBSYSTEM_WITH_CGROUPS,
                    MetricGranularity.TASK,
                    [],
                    'no (event_names)',
                )
        # We had the modify levels for all metrics
        # The set proper levels based on perf_aggregate_cpus value
        if not perf_aggregate_cpus:
            log.debug('Enabling "cpu" level for PERF_SUBSYSTEM_WITH_CGROUPS and derived metrics.')
            for metric_metadata in METRICS_METADATA.values():
                if metric_metadata.source == MetricSource.PERF_SUBSYSTEM_WITH_CGROUPS:
                    metric_metadata.levels = ['cpu']
                if metric_metadata.source == MetricSource.DERIVED_PERF_WITH_CGROUPS:
                    metric_metadata.levels = ['cpu']

        self._enable_derived_metrics = enable_derived_metrics
        self._uncore_events = uncore_event_names

        self._task_label_generators = task_label_generators or {}

        self._wss_reset_cycles = wss_reset_cycles
        self._wss_stable_cycles = wss_stable_cycles
        self._wss_membw_threshold = wss_membw_threshold

        self._uncore_pmu = None

        self._initialize_rdt_callback = None
        self._iterate_body_callback = None
        self._cached_bandwidth = None

        if zoneinfo is True:
            self._zoneinfo = zoneinfo
            zoneinfo_regexp = zoneinfo_module.DEFAULT_REGEXP
            log.debug('Enabled zoneinfo collection')
        elif zoneinfo is False:
            self._zoneinfo = zoneinfo
            log.debug('Disabled zoneinfo collection')
            zoneinfo_regexp = None
        else:
            zoneinfo_regexp = zoneinfo
            self._zoneinfo = True

        # Validate zoneinfo regexp.
        log.debug('zoneinfo=%r regexp=%r', self._zoneinfo, zoneinfo_regexp)
        self._zoneinfo_regexp_compiled = None
        if self._zoneinfo:
            try:
                self._zoneinfo_regexp_compiled = re.compile(zoneinfo_regexp)
            except re.error as e:
                raise ValidationError('zoneinfo_regexp_compile improper regexp: %s' % e)

            if not self._zoneinfo_regexp_compiled.groups == 2:
                raise ValidationError(
                    'zoneinfo_regexp_compile improper number of groups: should be 2')

        # Validate config and vmstat regexp.
        if vmstat in (True, False):
            self._vmstat = vmstat
        else:
            # Got regexp - compile and check...
            try:
                self._vmstat = re.compile(vmstat)
            except re.error as e:
                raise ValidationError('vmstat_regexp_compile improper regexp: %s' % e)

        # Validate config and sched regexp.
        if sched in (True, False):
            self._sched = sched
        else:
            # Got regexp - compile and check...
            try:
                self._sched = re.compile(sched)
            except re.error as e:
                raise ValidationError('sched regex compile improper regexp: %s' % e)