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',
66 def removesuffix(s: str, suffix: str) -> str:
72 return s[0:-len(suffix)] if s.endswith(suffix) else s
76 dirname: str) -> str:
77 """Generate a C table name from directory names."""
82 return tblname.replace('-', '_')
85 def c_len(s: str) -> int:
97 utf = s.encode(encoding='utf-8',errors='strict')
101 return len(utf) - utf.count(b'\\') + utf.count(b'\\\\') - (utf.count(b'\\000') * 2)
106 Generating a large number of stand-alone C strings creates a large
113 strings are merged. If a longer string ends-with the same value as a
129 def add(self, s: str, metric: bool) -> None:
138 def compute(self) -> None:
144 sorted_reversed_strings = sorted([x[::-1] for x in self.strings])
160 folded_strings[s[::-1]] = sorted_reversed_strings[best_pos][::-1]
169 # being appended to - comments, etc. don't count. big_string is
177 def string_cmp_key(s: str) -> Tuple[bool, int, str]:
197 self.offsets[s] = self.offsets[folded_s] + c_len(folded_s) - c_len(s)
202 """Representation of an event loaded from a json file dictionary."""
207 def llx(x: int) -> str:
211 def fixdesc(s: str) -> str:
219 def convert_aggr_mode(aggr_mode: str) -> Optional[str]:
229 def convert_metric_constraint(metric_constraint: str) -> Optional[str]:
242 def lookup_msr(num: str) -> Optional[str]:
243 """Converts the msr number, or first in a list to the appropriate event field."""
254 def real_event(name: str, event: str) -> Optional[str]:
255 """Convert well known event names to an event string otherwise use the event argument."""
257 'inst_retired.any': 'event=0xc0,period=2000003',
258 'inst_retired.any_p': 'event=0xc0,period=2000003',
259 'cpu_clk_unhalted.ref': 'event=0x0,umask=0x03,period=2000003',
260 'cpu_clk_unhalted.thread': 'event=0x3c,period=2000003',
261 'cpu_clk_unhalted.core': 'event=0x3c,period=2000003',
262 'cpu_clk_unhalted.thread_any': 'event=0x3c,any=1,period=2000003',
264 if not name:
266 if name.lower() in fixed:
267 return fixed[name.lower()]
268 return event
270 def unit_to_pmu(unit: str) -> Optional[str]:
271 """Convert a JSON Unit to Linux PMU name."""
280 'iMPH-U': 'uncore_arb',
281 'CPU-M-CF': 'cpum_cf',
282 'CPU-M-SF': 'cpum_sf',
283 'PAI-CRYPTO' : 'pai_crypto',
284 'PAI-EXT' : 'pai_ext',
304 def is_zero(val: str) -> bool:
313 def canonicalize_value(val: str) -> str:
328 self.name = jd['EventName'].lower() if 'EventName' in jd else None
365 if precise and self.desc and '(Precise Event)' not in self.desc:
367 'event)')
368 event = None
370 event = f'config={llx(configcode)}'
372 event = f'eventid={llx(eventidcode)}'
374 event = f'event={llx(eventcode)}'
393 event += f',{value}{canonicalize_value(jd[key])}'
395 event += f',{filter}'
397 event += f',{msr}{msrval}'
407 event = _arch_std_events[arch_std.lower()].event
408 # Copy from the architecture standard event to self for undefined fields.
413 raise argparse.ArgumentTypeError('Cannot find arch std event:', arch_std)
415 self.event = real_event(self.name, event)
417 def __repr__(self) -> str:
425 def build_c_string(self, metric: bool) -> str:
441 def to_c_string(self, metric: bool) -> str:
442 """Representation of the event as a C struct initializer."""
444 def fix_comment(s: str) -> str:
452 def read_json_events(path: str, topic: str) -> Sequence[JsonEvent]:
460 for event in events:
461 event.topic = topic
462 if event.metric_name and '-' not in event.metric_name:
463 metrics.append((event.pmu, event.metric_name, event.metric_expr))
466 for event in events:
467 if event.metric_name in updates:
468 # print(f'Updated {event.metric_name} from\n"{event.metric_expr}"\n'
469 # f'to\n"{updates[event.metric_name]}"')
470 event.metric_expr = updates[event.metric_name]
474 def preprocess_arch_std_files(archpath: str) -> None:
478 if not item.is_file() or not item.name.endswith('.json'):
481 for event in read_json_events(item.path, topic=''):
482 if event.name:
483 _arch_std_events[event.name.lower()] = event
484 if event.metric_name:
485 _arch_std_events[event.metric_name.lower()] = event
487 raise RuntimeError(f'Failure processing \'{item.name}\' in \'{archpath}\'') from e
490 def add_events_table_entries(item: os.DirEntry, topic: str) -> None:
493 if e.name:
499 def print_pending_events() -> None:
502 def event_cmp_key(j: JsonEvent) -> Tuple[str, str, bool, str, str]:
503 def fix_none(s: Optional[str]) -> str:
508 … return (fix_none(j.pmu).replace(',','_'), fix_none(j.name), j.desc is not None, fix_none(j.topic),
527 for event in sorted(_pending_events, key=event_cmp_key):
528 if last_pmu and last_pmu == event.pmu:
529 …assert event.name != last_name, f"Duplicate event: {last_pmu}/{last_name}/ in {_pending_events_tbl…
530 if event.pmu != last_pmu:
533 pmu_name = event.pmu.replace(',', '_')
537 last_pmu = event.pmu
538 pmus.add((event.pmu, pmu_name))
540 _args.output_file.write(event.to_c_string(metric=False))
541 last_name = event.name
559 def print_pending_metrics() -> None:
562 def metric_cmp_key(j: JsonEvent) -> Tuple[bool, str, str]:
563 def fix_none(s: Optional[str]) -> str:
614 def get_topic(topic: str) -> str:
617 return removesuffix(topic, '.json').replace('-', ' ')
619 def preprocess_one_file(parents: Sequence[str], item: os.DirEntry) -> None:
629 # Ignore other directories. If the file name does not have a .json
631 if not item.is_file() or not item.name.endswith('.json'):
634 if item.name == 'metricgroups.json':
645 topic = get_topic(item.name)
646 for event in read_json_events(item.path, topic):
647 pmu_name = f"{event.pmu}\\000"
648 if event.name:
650 _bcs.add(event.build_c_string(metric=False), metric=False)
651 if event.metric_name:
653 _bcs.add(event.build_c_string(metric=True), metric=True)
655 def process_one_file(parents: Sequence[str], item: os.DirEntry) -> None:
657 def is_leaf_dir_ignoring_sys(path: str) -> bool:
659 if item.is_dir() and item.name != 'sys':
672 _pending_events_tblname = file_name_to_table_name('pmu_events_', parents, item.name)
674 _pending_metrics_tblname = file_name_to_table_name('pmu_metrics_', parents, item.name)
676 if item.name == 'sys':
685 # Ignore other directories. If the file name does not have a .json
687 if not item.is_file() or not item.name.endswith('.json') or item.name == 'metricgroups.json':
690 add_events_table_entries(item, get_topic(item.name))
693 def print_mapping_table(archs: Sequence[str]) -> None:
694 """Read the mapfile and generate the struct from cpuid string to event table."""
696 /* Struct used to make the PMU event table implementation opaque to callers. */
710 * cpuid field, which is an arch-specific identifier for the CPU.
711 * The identifier specified in tools/perf/pmu-events/arch/xxx/mapfile
802 def print_system_mapping_table() -> None:
806 \tconst char *name;
829 \t\t.name = \"{tblname}\",
840 \t\t.name = \"{tblname}\",
854 _args.output_file.write(f'\n\tpe->{attr} = ')
856 _args.output_file.write("*p - '0';\n")
859 if attr == _json_event_attributes[-1]:
872 _args.output_file.write(f'\n\tpm->{attr} = ')
874 _args.output_file.write("*p - '0';\n")
877 if attr == _json_metric_attributes[-1]:
892 .pmu = &big_c_string[pmu->pmu_name.offset],
895 for (uint32_t i = 0; i < pmu->num_entries; i++) {
896 decompress_event(pmu->entries[i].offset, &pe);
897 if (!pe.name)
908 const char *name,
913 .pmu = &big_c_string[pmu->pmu_name.offset],
915 int low = 0, high = pmu->num_entries - 1;
920 decompress_event(pmu->entries[mid].offset, &pe);
922 if (!pe.name && !name)
925 if (!pe.name && name) {
929 if (pe.name && !name) {
930 high = mid - 1;
934 cmp = strcasecmp(pe.name, name);
940 high = mid - 1;
954 for (size_t i = 0; i < table->num_pmus; i++) {
955 const struct pmu_table_entry *table_pmu = &table->pmus[i];
956 const char *pmu_name = &big_c_string[table_pmu->pmu_name.offset];
971 const char *name,
975 for (size_t i = 0; i < table->num_pmus; i++) {
976 const struct pmu_table_entry *table_pmu = &table->pmus[i];
977 const char *pmu_name = &big_c_string[table_pmu->pmu_name.offset];
983 ret = pmu_events_table__find_event_pmu(table, table_pmu, name, fn, data);
995 for (size_t i = 0; i < table->num_pmus; i++) {
996 const struct pmu_table_entry *table_pmu = &table->pmus[i];
997 const char *pmu_name = &big_c_string[table_pmu->pmu_name.offset];
1000 count += table_pmu->num_entries;
1012 .pmu = &big_c_string[pmu->pmu_name.offset],
1015 for (uint32_t i = 0; i < pmu->num_entries; i++) {
1016 decompress_metric(pmu->entries[i].offset, &pm);
1033 .pmu = &big_c_string[pmu->pmu_name.offset],
1035 int low = 0, high = pmu->num_entries - 1;
1040 decompress_metric(pmu->entries[mid].offset, &pm);
1050 high = mid - 1;
1060 high = mid - 1;
1073 for (size_t i = 0; i < table->num_pmus; i++) {
1074 int ret = pmu_metrics_table__for_each_metric_pmu(table, &table->pmus[i],
1089 for (size_t i = 0; i < table->num_pmus; i++) {
1090 const struct pmu_table_entry *table_pmu = &table->pmus[i];
1091 const char *pmu_name = &big_c_string[table_pmu->pmu_name.offset];
1139 if (!map->arch) {
1144 if (!strcmp_cpuid_str(map->cpuid, cpuid))
1161 struct perf_cpu cpu = {-1};
1167 if (!strcmp(pmu_name, pmu->name)) {
1170 while (strcmp("common", map->arch))
1175 cpu = perf_cpu_map__min(pmu->cpus);
1188 return &map->event_table;
1190 for (size_t i = 0; i < map->event_table.num_pmus; i++) {
1191 const struct pmu_table_entry *table_pmu = &map->event_table.pmus[i];
1192 const char *pmu_name = &big_c_string[table_pmu->pmu_name.offset];
1195 return &map->event_table;
1202 struct perf_cpu cpu = {-1};
1205 return map ? &map->metric_table : NULL;
1211 tables->arch;
1213 if (!strcmp(tables->arch, arch) && !strcmp_cpuid_str(tables->cpuid, cpuid))
1214 return &tables->event_table;
1222 tables->arch;
1224 if (!strcmp(tables->arch, arch) && !strcmp_cpuid_str(tables->cpuid, cpuid))
1225 return &tables->metric_table;
1233 tables->arch;
1235 int ret = pmu_events_table__for_each_event(&tables->event_table,
1247 tables->arch;
1249 int ret = pmu_metrics_table__for_each_metric(&tables->metric_table, fn, data);
1257 const struct pmu_events_table *find_sys_events_table(const char *name)
1260 tables->name;
1262 if (!strcmp(tables->name, name))
1263 return &tables->event_table;
1271 tables->name;
1273 int ret = pmu_events_table__for_each_event(&tables->event_table,
1285 tables->name;
1287 int ret = pmu_metrics_table__for_each_metric(&tables->metric_table, fn, data);
1296 def print_metricgroups() -> None:
1310 int low = 0, high = (int)ARRAY_SIZE(metricgroups) - 1;
1322 high = mid - 1;
1329 def main() -> None:
1332 def dir_path(path: str) -> str:
1339 action: Callable[[Sequence[str], os.DirEntry], None]) -> None:
1341 for item in sorted(os.scandir(path), key=lambda e: e.name):
1346 item_path = '/'.join(parents) + ('/' if len(parents) > 0 else '') + item.name
1352 raise RuntimeError(f'Action failure for \'{item.name}\' in {parents}') from e
1354 ftw(item.path, parents + [item.name], action)
1357 ap.add_argument('arch', help='Architecture name like x86')
1361 such as "arm/cortex-a34".''',
1369 'output_file', type=argparse.FileType('w', encoding='utf-8'), nargs='?', default=sys.stdout)
1373 /* SPDX-License-Identifier: GPL-2.0 */
1377 #include <pmu-events/pmu-events.h>
1398 … if item.name == _args.arch or _args.arch == 'all' or item.name == 'test' or item.name == 'common':
1399 archs.append(item.name)