Lines Matching +full:os +full:- +full:data +full:- +full:offset
2 # SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
9 import os
66 def removesuffix(s: str, suffix: str) -> str:
72 return s[0:-len(suffix)] if s.endswith(suffix) else s
76 dirname: str) -> str:
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])
149 # an offset of 1. We record which string can be folded into which
150 # in folded_strings, we don't need to record the offset as it is
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]:
184 self.big_string.append(f'/* offset={big_string_offset} */ "')
197 self.offsets[s] = self.offsets[folded_s] + c_len(folded_s) - c_len(s)
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]:
254 def real_event(name: str, event: str) -> Optional[str]:
270 def unit_to_pmu(unit: str) -> Optional[str]:
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:
417 def __repr__(self) -> str:
425 def build_c_string(self, metric: bool) -> str:
441 def to_c_string(self, metric: bool) -> str:
444 def fix_comment(s: str) -> str:
452 def read_json_events(path: str, topic: str) -> Sequence[JsonEvent]:
462 if event.metric_name and '-' not in event.metric_name:
474 def preprocess_arch_std_files(archpath: str) -> None:
477 for item in os.scandir(archpath):
490 def add_events_table_entries(item: os.DirEntry, topic: str) -> None:
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:
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:
655 def process_one_file(parents: Sequence[str], item: os.DirEntry) -> None:
657 def is_leaf_dir_ignoring_sys(path: str) -> bool:
658 for item in os.scandir(path):
693 def print_mapping_table(archs: Sequence[str]) -> None:
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:
849 static void decompress_event(int offset, struct pmu_event *pe)
851 \tconst char *p = &big_c_string[offset];
854 _args.output_file.write(f'\n\tpe->{attr} = ')
856 _args.output_file.write("*p - '0';\n")
859 if attr == _json_event_attributes[-1]:
867 static void decompress_metric(int offset, struct pmu_metric *pm)
869 \tconst char *p = &big_c_string[offset];
872 _args.output_file.write(f'\n\tpm->{attr} = ')
874 _args.output_file.write("*p - '0';\n")
877 if attr == _json_metric_attributes[-1]:
888 void *data)
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);
899 ret = fn(&pe, table, data);
910 void *data)
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);
930 high = mid - 1;
940 high = mid - 1;
944 return fn ? fn(&pe, table, data) : 0;
952 void *data)
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];
962 ret = pmu_events_table__for_each_event_pmu(table, table_pmu, fn, data);
973 void *data)
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;
1008 void *data)
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);
1019 ret = fn(&pm, table, data);
1030 void *data)
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;
1064 return fn ? fn(&pm, table, data) : 0;
1071 void *data)
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],
1075 fn, data);
1087 void *data)
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];
1097 ret = pmu_metrics_table__find_metric_pmu(table, table_pmu, metric, fn, data);
1139 if (!map->arch) {
1144 if (!strcmp_cpuid_str(map->cpuid, cpuid))
1161 struct perf_cpu cpu = {-1};
1165 const char *pmu_name = &big_c_string[pmu_events__common[i].pmu_name.offset];
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;
1230 int pmu_for_each_core_event(pmu_event_iter_fn fn, void *data)
1233 tables->arch;
1235 int ret = pmu_events_table__for_each_event(&tables->event_table,
1236 /*pmu=*/ NULL, fn, data);
1244 int pmu_for_each_core_metric(pmu_metric_iter_fn fn, void *data)
1247 tables->arch;
1249 int ret = pmu_metrics_table__for_each_metric(&tables->metric_table, fn, data);
1260 tables->name;
1262 if (!strcmp(tables->name, name))
1263 return &tables->event_table;
1268 int pmu_for_each_sys_event(pmu_event_iter_fn fn, void *data)
1271 tables->name;
1273 int ret = pmu_events_table__for_each_event(&tables->event_table,
1274 /*pmu=*/ NULL, fn, data);
1282 int pmu_for_each_sys_metric(pmu_metric_iter_fn fn, void *data)
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:
1334 if os.path.isdir(path):
1339 action: Callable[[Sequence[str], os.DirEntry], None]) -> None:
1341 for item in sorted(os.scandir(path), key=lambda e: e.name):
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>
1384 int offset;
1395 for item in os.scandir(_args.starting_dir):