Lines Matching +full:num +full:- +full:strings

2 # SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
63 def removesuffix(s: str, suffix: str) -> str:
69 return s[0:-len(suffix)] if s.endswith(suffix) else s
73 dirname: str) -> str:
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)
101 """A class to hold many strings concatenated together.
103 Generating a large number of stand-alone C strings creates a large
106 are all the other C strings (to avoid memory issues the string
107 itself is held as a list of strings). The offsets within the big
110 strings are merged. If a longer string ends-with the same value as a
113 strings: Set[str]
121 self.strings = set()
126 def add(self, s: str, metric: bool) -> None:
128 if s not in self.strings:
129 self.strings.add(s)
135 def compute(self) -> None:
136 """Called once all strings are added to compute the string and offsets."""
139 # Determine if two strings can be folded, ie. let 1 string use the
140 # end of another. First reverse all strings and sort them.
141 sorted_reversed_strings = sorted([x[::-1] for x in self.strings])
143 # Strings 'xyz' and 'yz' will now be [ 'zy', 'zyx' ]. Scan forward
157 folded_strings[s[::-1]] = sorted_reversed_strings[best_pos][::-1]
166 # being appended to - comments, etc. don't count. big_string is
167 # the string contents represented as a list. Strings are immutable
174 def string_cmp_key(s: str) -> Tuple[bool, int, str]:
177 # Emit all strings that aren't folded in a sorted manner.
178 for s in sorted(self.strings, key=string_cmp_key):
190 # Compute the offsets of the folded strings.
194 self.offsets[s] = self.offsets[folded_s] + c_len(folded_s) - c_len(s)
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]:
240 if not num:
248 return msrmap[int(num.split(',', 1)[0], 0)]
250 def real_event(name: str, event: str) -> Optional[str]:
266 def unit_to_pmu(unit: str) -> Optional[str]:
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',
383 def __repr__(self) -> str:
391 def build_c_string(self, metric: bool) -> str:
407 def to_c_string(self, metric: bool) -> str:
415 def read_json_events(path: str, topic: str) -> Sequence[JsonEvent]:
425 if event.metric_name and '-' not in event.metric_name:
437 def preprocess_arch_std_files(archpath: str) -> None:
449 def add_events_table_entries(item: os.DirEntry, topic: str) -> None:
458 def print_pending_events() -> None:
461 def event_cmp_key(j: JsonEvent) -> Tuple[str, str, bool, str, str]:
462 def fix_none(s: Optional[str]) -> str:
514 def print_pending_metrics() -> None:
517 def metric_cmp_key(j: JsonEvent) -> Tuple[bool, str, str]:
518 def fix_none(s: Optional[str]) -> str:
569 def get_topic(topic: str) -> str:
572 return removesuffix(topic, '.json').replace('-', ' ')
574 def preprocess_one_file(parents: Sequence[str], item: os.DirEntry) -> None:
610 def process_one_file(parents: Sequence[str], item: os.DirEntry) -> None:
612 def is_leaf_dir(path: str) -> bool:
645 def print_mapping_table(archs: Sequence[str]) -> None:
662 * cpuid field, which is an arch-specific identifier for the CPU.
663 * The identifier specified in tools/perf/pmu-events/arch/xxx/mapfile
743 def print_system_mapping_table() -> None:
795 _args.output_file.write(f'\n\tpe->{attr} = ')
797 _args.output_file.write("*p - '0';\n")
800 if attr == _json_event_attributes[-1]:
813 _args.output_file.write(f'\n\tpm->{attr} = ')
815 _args.output_file.write("*p - '0';\n")
818 if attr == _json_metric_attributes[-1]:
833 .pmu = &big_c_string[pmu->pmu_name.offset],
836 for (uint32_t i = 0; i < pmu->num_entries; i++) {
837 decompress_event(pmu->entries[i].offset, &pe);
854 .pmu = &big_c_string[pmu->pmu_name.offset],
856 int low = 0, high = pmu->num_entries - 1;
861 decompress_event(pmu->entries[mid].offset, &pe);
871 high = mid - 1;
881 high = mid - 1;
887 return -1000;
895 for (size_t i = 0; i < table->num_pmus; i++) {
896 const struct pmu_table_entry *table_pmu = &table->pmus[i];
897 const char *pmu_name = &big_c_string[table_pmu->pmu_name.offset];
916 for (size_t i = 0; i < table->num_pmus; i++) {
917 const struct pmu_table_entry *table_pmu = &table->pmus[i];
918 const char *pmu_name = &big_c_string[table_pmu->pmu_name.offset];
925 if (ret != -1000)
928 return -1000;
936 for (size_t i = 0; i < table->num_pmus; i++) {
937 const struct pmu_table_entry *table_pmu = &table->pmus[i];
938 const char *pmu_name = &big_c_string[table_pmu->pmu_name.offset];
941 count += table_pmu->num_entries;
953 .pmu = &big_c_string[pmu->pmu_name.offset],
956 for (uint32_t i = 0; i < pmu->num_entries; i++) {
957 decompress_metric(pmu->entries[i].offset, &pm);
971 for (size_t i = 0; i < table->num_pmus; i++) {
972 int ret = pmu_metrics_table__for_each_metric_pmu(table, &table->pmus[i],
1016 if (!map->arch) {
1021 if (!strcmp_cpuid_str(map->cpuid, cpuid))
1044 return &map->event_table;
1046 for (size_t i = 0; i < map->event_table.num_pmus; i++) {
1047 const struct pmu_table_entry *table_pmu = &map->event_table.pmus[i];
1048 const char *pmu_name = &big_c_string[table_pmu->pmu_name.offset];
1051 return &map->event_table;
1064 return &map->metric_table;
1066 for (size_t i = 0; i < map->metric_table.num_pmus; i++) {
1067 const struct pmu_table_entry *table_pmu = &map->metric_table.pmus[i];
1068 const char *pmu_name = &big_c_string[table_pmu->pmu_name.offset];
1071 return &map->metric_table;
1079 tables->arch;
1081 if (!strcmp(tables->arch, arch) && !strcmp_cpuid_str(tables->cpuid, cpuid))
1082 return &tables->event_table;
1090 tables->arch;
1092 if (!strcmp(tables->arch, arch) && !strcmp_cpuid_str(tables->cpuid, cpuid))
1093 return &tables->metric_table;
1101 tables->arch;
1103 int ret = pmu_events_table__for_each_event(&tables->event_table,
1115 tables->arch;
1117 int ret = pmu_metrics_table__for_each_metric(&tables->metric_table, fn, data);
1128 tables->name;
1130 if (!strcmp(tables->name, name))
1131 return &tables->event_table;
1139 tables->name;
1141 int ret = pmu_events_table__for_each_event(&tables->event_table,
1153 tables->name;
1155 int ret = pmu_metrics_table__for_each_metric(&tables->metric_table, fn, data);
1164 def print_metricgroups() -> None:
1178 int low = 0, high = (int)ARRAY_SIZE(metricgroups) - 1;
1190 high = mid - 1;
1197 def main() -> None:
1200 def dir_path(path: str) -> str:
1207 action: Callable[[Sequence[str], os.DirEntry], None]) -> None:
1226 such as "arm/cortex-a34".''',
1234 'output_file', type=argparse.FileType('w', encoding='utf-8'), nargs='?', default=sys.stdout)
1238 #include <pmu-events/pmu-events.h>