Lines Matching +full:event +full:- +full:name

2 # SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
16 # List of regular event tables.
18 # List of event tables generated from "/sys" directories.
24 # Mapping between sys event table names and sys metric table names.
26 # Map from an event name to an architecture standard
32 # Name of events table to be written out
36 # Name of metrics table to be written out
40 # Map from the name of a metric group to a description of the group.
45 'name', 'topic', 'desc',
47 'event',
63 def removesuffix(s: str, suffix: str) -> str:
69 return s[0:-len(suffix)] if s.endswith(suffix) else s
73 dirname: str) -> str:
74 """Generate a C table name from directory names."""
79 return tblname.replace('-', '_')
82 def c_len(s: str) -> int:
94 utf = s.encode(encoding='utf-8',errors='strict')
98 return len(utf) - utf.count(b'\\') + utf.count(b'\\\\') - (utf.count(b'\\000') * 2)
103 Generating a large number of stand-alone C strings creates a large
110 strings are merged. If a longer string ends-with the same value as a
126 def add(self, s: str, metric: bool) -> None:
135 def compute(self) -> None:
141 sorted_reversed_strings = sorted([x[::-1] for x in self.strings])
157 folded_strings[s[::-1]] = sorted_reversed_strings[best_pos][::-1]
166 # being appended to - comments, etc. don't count. big_string is
174 def string_cmp_key(s: str) -> Tuple[bool, int, str]:
194 self.offsets[s] = self.offsets[folded_s] + c_len(folded_s) - c_len(s)
199 """Representation of an event loaded from a json file dictionary."""
204 def llx(x: int) -> str:
208 def fixdesc(s: str) -> str:
216 def convert_aggr_mode(aggr_mode: str) -> Optional[str]:
226 def convert_metric_constraint(metric_constraint: str) -> Optional[str]:
238 def lookup_msr(num: str) -> Optional[str]:
239 """Converts the msr number, or first in a list to the appropriate event field."""
250 def real_event(name: str, event: str) -> Optional[str]:
251 """Convert well known event names to an event string otherwise use the event argument."""
253 'inst_retired.any': 'event=0xc0,period=2000003',
254 'inst_retired.any_p': 'event=0xc0,period=2000003',
255 'cpu_clk_unhalted.ref': 'event=0x0,umask=0x03,period=2000003',
256 'cpu_clk_unhalted.thread': 'event=0x3c,period=2000003',
257 'cpu_clk_unhalted.core': 'event=0x3c,period=2000003',
258 'cpu_clk_unhalted.thread_any': 'event=0x3c,any=1,period=2000003',
260 if not name:
262 if name.lower() in fixed:
263 return fixed[name.lower()]
264 return event
266 def unit_to_pmu(unit: str) -> Optional[str]:
267 """Convert a JSON Unit to Linux PMU name."""
276 'iMPH-U': 'uncore_arb',
277 'CPU-M-CF': 'cpum_cf',
278 'CPU-M-SF': 'cpum_sf',
279 'PAI-CRYPTO' : 'pai_crypto',
280 'PAI-EXT' : 'pai_ext',
299 def is_zero(val: str) -> bool:
308 def canonicalize_value(val: str) -> str:
323 self.name = jd['EventName'].lower() if 'EventName' in jd else None
357 if precise and self.desc and '(Precise Event)' not in self.desc:
359 'event)')
360 event = None
362 event = f'config={llx(configcode)}'
364 event = f'eventid={llx(eventidcode)}'
366 event = f'event={llx(eventcode)}'
385 event += f',{value}{canonicalize_value(jd[key])}'
387 event += f',{filter}'
389 event += f',{msr}{msrval}'
396 event = _arch_std_events[arch_std.lower()].event
397 # Copy from the architecture standard event to self for undefined fields.
402 raise argparse.ArgumentTypeError('Cannot find arch std event:', arch_std)
404 self.event = real_event(self.name, event)
406 def __repr__(self) -> str:
414 def build_c_string(self, metric: bool) -> str:
430 def to_c_string(self, metric: bool) -> str:
431 """Representation of the event as a C struct initializer."""
433 def fix_comment(s: str) -> str:
441 def read_json_events(path: str, topic: str) -> Sequence[JsonEvent]:
449 for event in events:
450 event.topic = topic
451 if event.metric_name and '-' not in event.metric_name:
452 metrics.append((event.pmu, event.metric_name, event.metric_expr))
455 for event in events:
456 if event.metric_name in updates:
457 # print(f'Updated {event.metric_name} from\n"{event.metric_expr}"\n'
458 # f'to\n"{updates[event.metric_name]}"')
459 event.metric_expr = updates[event.metric_name]
463 def preprocess_arch_std_files(archpath: str) -> None:
467 if not item.is_file() or not item.name.endswith('.json'):
470 for event in read_json_events(item.path, topic=''):
471 if event.name:
472 _arch_std_events[event.name.lower()] = event
473 if event.metric_name:
474 _arch_std_events[event.metric_name.lower()] = event
476 raise RuntimeError(f'Failure processing \'{item.name}\' in \'{archpath}\'') from e
479 def add_events_table_entries(item: os.DirEntry, topic: str) -> None:
482 if e.name:
488 def print_pending_events() -> None:
491 def event_cmp_key(j: JsonEvent) -> Tuple[str, str, bool, str, str]:
492 def fix_none(s: Optional[str]) -> str:
497 … return (fix_none(j.pmu).replace(',','_'), fix_none(j.name), j.desc is not None, fix_none(j.topic),
516 for event in sorted(_pending_events, key=event_cmp_key):
517 if last_pmu and last_pmu == event.pmu:
518 …assert event.name != last_name, f"Duplicate event: {last_pmu}/{last_name}/ in {_pending_events_tbl…
519 if event.pmu != last_pmu:
522 pmu_name = event.pmu.replace(',', '_')
526 last_pmu = event.pmu
527 pmus.add((event.pmu, pmu_name))
529 _args.output_file.write(event.to_c_string(metric=False))
530 last_name = event.name
548 def print_pending_metrics() -> None:
551 def metric_cmp_key(j: JsonEvent) -> Tuple[bool, str, str]:
552 def fix_none(s: Optional[str]) -> str:
603 def get_topic(topic: str) -> str:
606 return removesuffix(topic, '.json').replace('-', ' ')
608 def preprocess_one_file(parents: Sequence[str], item: os.DirEntry) -> None:
618 # Ignore other directories. If the file name does not have a .json
620 if not item.is_file() or not item.name.endswith('.json'):
623 if item.name == 'metricgroups.json':
634 topic = get_topic(item.name)
635 for event in read_json_events(item.path, topic):
636 pmu_name = f"{event.pmu}\\000"
637 if event.name:
639 _bcs.add(event.build_c_string(metric=False), metric=False)
640 if event.metric_name:
642 _bcs.add(event.build_c_string(metric=True), metric=True)
644 def process_one_file(parents: Sequence[str], item: os.DirEntry) -> None:
646 def is_leaf_dir_ignoring_sys(path: str) -> bool:
648 if item.is_dir() and item.name != 'sys':
661 _pending_events_tblname = file_name_to_table_name('pmu_events_', parents, item.name)
663 _pending_metrics_tblname = file_name_to_table_name('pmu_metrics_', parents, item.name)
665 if item.name == 'sys':
674 # Ignore other directories. If the file name does not have a .json
676 if not item.is_file() or not item.name.endswith('.json') or item.name == 'metricgroups.json':
679 add_events_table_entries(item, get_topic(item.name))
682 def print_mapping_table(archs: Sequence[str]) -> None:
683 """Read the mapfile and generate the struct from cpuid string to event table."""
685 /* Struct used to make the PMU event table implementation opaque to callers. */
699 * cpuid field, which is an arch-specific identifier for the CPU.
700 * The identifier specified in tools/perf/pmu-events/arch/xxx/mapfile
791 def print_system_mapping_table() -> None:
795 \tconst char *name;
818 \t\t.name = \"{tblname}\",
829 \t\t.name = \"{tblname}\",
843 _args.output_file.write(f'\n\tpe->{attr} = ')
845 _args.output_file.write("*p - '0';\n")
848 if attr == _json_event_attributes[-1]:
861 _args.output_file.write(f'\n\tpm->{attr} = ')
863 _args.output_file.write("*p - '0';\n")
866 if attr == _json_metric_attributes[-1]:
881 .pmu = &big_c_string[pmu->pmu_name.offset],
884 for (uint32_t i = 0; i < pmu->num_entries; i++) {
885 decompress_event(pmu->entries[i].offset, &pe);
886 if (!pe.name)
897 const char *name,
902 .pmu = &big_c_string[pmu->pmu_name.offset],
904 int low = 0, high = pmu->num_entries - 1;
909 decompress_event(pmu->entries[mid].offset, &pe);
911 if (!pe.name && !name)
914 if (!pe.name && name) {
918 if (pe.name && !name) {
919 high = mid - 1;
923 cmp = strcasecmp(pe.name, name);
929 high = mid - 1;
943 for (size_t i = 0; i < table->num_pmus; i++) {
944 const struct pmu_table_entry *table_pmu = &table->pmus[i];
945 const char *pmu_name = &big_c_string[table_pmu->pmu_name.offset];
960 const char *name,
964 for (size_t i = 0; i < table->num_pmus; i++) {
965 const struct pmu_table_entry *table_pmu = &table->pmus[i];
966 const char *pmu_name = &big_c_string[table_pmu->pmu_name.offset];
972 ret = pmu_events_table__find_event_pmu(table, table_pmu, name, fn, data);
984 for (size_t i = 0; i < table->num_pmus; i++) {
985 const struct pmu_table_entry *table_pmu = &table->pmus[i];
986 const char *pmu_name = &big_c_string[table_pmu->pmu_name.offset];
989 count += table_pmu->num_entries;
1001 .pmu = &big_c_string[pmu->pmu_name.offset],
1004 for (uint32_t i = 0; i < pmu->num_entries; i++) {
1005 decompress_metric(pmu->entries[i].offset, &pm);
1019 for (size_t i = 0; i < table->num_pmus; i++) {
1020 int ret = pmu_metrics_table__for_each_metric_pmu(table, &table->pmus[i],
1064 if (!map->arch) {
1069 if (!strcmp_cpuid_str(map->cpuid, cpuid))
1086 struct perf_cpu cpu = {-1};
1089 cpu = perf_cpu_map__min(pmu->cpus);
1101 return &map->event_table;
1103 for (size_t i = 0; i < map->event_table.num_pmus; i++) {
1104 const struct pmu_table_entry *table_pmu = &map->event_table.pmus[i];
1105 const char *pmu_name = &big_c_string[table_pmu->pmu_name.offset];
1108 return &map->event_table;
1115 struct perf_cpu cpu = {-1};
1118 return map ? &map->metric_table : NULL;
1124 tables->arch;
1126 if (!strcmp(tables->arch, arch) && !strcmp_cpuid_str(tables->cpuid, cpuid))
1127 return &tables->event_table;
1135 tables->arch;
1137 if (!strcmp(tables->arch, arch) && !strcmp_cpuid_str(tables->cpuid, cpuid))
1138 return &tables->metric_table;
1146 tables->arch;
1148 int ret = pmu_events_table__for_each_event(&tables->event_table,
1160 tables->arch;
1162 int ret = pmu_metrics_table__for_each_metric(&tables->metric_table, fn, data);
1170 const struct pmu_events_table *find_sys_events_table(const char *name)
1173 tables->name;
1175 if (!strcmp(tables->name, name))
1176 return &tables->event_table;
1184 tables->name;
1186 int ret = pmu_events_table__for_each_event(&tables->event_table,
1198 tables->name;
1200 int ret = pmu_metrics_table__for_each_metric(&tables->metric_table, fn, data);
1209 def print_metricgroups() -> None:
1223 int low = 0, high = (int)ARRAY_SIZE(metricgroups) - 1;
1235 high = mid - 1;
1242 def main() -> None:
1245 def dir_path(path: str) -> str:
1252 action: Callable[[Sequence[str], os.DirEntry], None]) -> None:
1254 for item in sorted(os.scandir(path), key=lambda e: e.name):
1259 item_path = '/'.join(parents) + ('/' if len(parents) > 0 else '') + item.name
1265 raise RuntimeError(f'Action failure for \'{item.name}\' in {parents}') from e
1267 ftw(item.path, parents + [item.name], action)
1270 ap.add_argument('arch', help='Architecture name like x86')
1274 such as "arm/cortex-a34".''',
1282 'output_file', type=argparse.FileType('w', encoding='utf-8'), nargs='?', default=sys.stdout)
1286 /* SPDX-License-Identifier: GPL-2.0 */
1290 #include <pmu-events/pmu-events.h>
1311 … if item.name == _args.arch or _args.arch == 'all' or item.name == 'test' or item.name == 'common':
1312 archs.append(item.name)