def _create_event_attributes(event_name, disabled): """Creates perf_event_attr structure for perf_event_open syscall""" attr = pc.PerfEventAttr() attr.size = pc.PERF_ATTR_SIZE_VER5 if event_name == MetricName.MEMSTALL: attr.type = pc.PerfType.PERF_TYPE_RAW attr.config = _get_memstall_config() elif event_name in pc.HardwareEventNameMap: attr.type = pc.PerfType.PERF_TYPE_HARDWARE attr.config = pc.HardwareEventNameMap[event_name] elif '__r' in event_name: attr.type = pc.PerfType.PERF_TYPE_RAW attr.config = _parse_raw_event_name(event_name) else: raise Exception('unknown event name %r' % event_name) log.log(logger.TRACE, 'perf: event_attribute: name=%r type=%r config=%r', event_name, attr.type, attr.config) attr.sample_type = pc.PERF_SAMPLE_IDENTIFIER attr.read_format = (pc.PERF_FORMAT_GROUP | pc.PERF_FORMAT_TOTAL_TIME_ENABLED | pc.PERF_FORMAT_TOTAL_TIME_RUNNING | pc.PERF_FORMAT_ID) attr.flags = pc.AttrFlags.exclude_guest if disabled: attr.flags |= pc.AttrFlags.disabled return attr
def _create_event_attributes(pmu_type, disabled, event: Event): """Creates perf_event_attr structure for perf_event_open syscall""" attr = pc.PerfEventAttr() attr.size = pc.PERF_ATTR_SIZE_VER5 attr.type = pmu_type attr.config = event.config attr.config1 = event.config1 attr.sample_type = pc.PERF_SAMPLE_IDENTIFIER attr.read_format = (pc.PERF_FORMAT_GROUP | pc.PERF_FORMAT_TOTAL_TIME_ENABLED | pc.PERF_FORMAT_TOTAL_TIME_RUNNING | pc.PERF_FORMAT_ID) attr.flags = pc.AttrFlags.inherit if disabled: attr.flags |= pc.AttrFlags.disabled return attr