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',
372 def __repr__(self) -> str:
380 def build_c_string(self, metric: bool) -> str:
396 def to_c_string(self, metric: bool) -> str:
404 def read_json_events(path: str, topic: str) -> Sequence[JsonEvent]:
414 if event.metric_name and '-' not in event.metric_name:
426 def preprocess_arch_std_files(archpath: str) -> None:
438 def add_events_table_entries(item: os.DirEntry, topic: str) -> None:
447 def print_pending_events() -> None:
450 def event_cmp_key(j: JsonEvent) -> Tuple[str, str, bool, str, str]:
451 def fix_none(s: Optional[str]) -> str:
503 def print_pending_metrics() -> None:
506 def metric_cmp_key(j: JsonEvent) -> Tuple[bool, str, str]:
507 def fix_none(s: Optional[str]) -> str:
558 def get_topic(topic: str) -> str:
561 return removesuffix(topic, '.json').replace('-', ' ')
563 def preprocess_one_file(parents: Sequence[str], item: os.DirEntry) -> None:
599 def process_one_file(parents: Sequence[str], item: os.DirEntry) -> None:
601 def is_leaf_dir(path: str) -> bool:
634 def print_mapping_table(archs: Sequence[str]) -> None:
651 * cpuid field, which is an arch-specific identifier for the CPU.
652 * The identifier specified in tools/perf/pmu-events/arch/xxx/mapfile
732 def print_system_mapping_table() -> None:
784 _args.output_file.write(f'\n\tpe->{attr} = ')
786 _args.output_file.write("*p - '0';\n")
789 if attr == _json_event_attributes[-1]:
802 _args.output_file.write(f'\n\tpm->{attr} = ')
804 _args.output_file.write("*p - '0';\n")
807 if attr == _json_metric_attributes[-1]:
822 .pmu = &big_c_string[pmu->pmu_name.offset],
825 for (uint32_t i = 0; i < pmu->num_entries; i++) {
826 decompress_event(pmu->entries[i].offset, &pe);
843 .pmu = &big_c_string[pmu->pmu_name.offset],
845 int low = 0, high = pmu->num_entries - 1;
850 decompress_event(pmu->entries[mid].offset, &pe);
860 high = mid - 1;
870 high = mid - 1;
876 return -1000;
884 for (size_t i = 0; i < table->num_pmus; i++) {
885 const struct pmu_table_entry *table_pmu = &table->pmus[i];
886 const char *pmu_name = &big_c_string[table_pmu->pmu_name.offset];
905 for (size_t i = 0; i < table->num_pmus; i++) {
906 const struct pmu_table_entry *table_pmu = &table->pmus[i];
907 const char *pmu_name = &big_c_string[table_pmu->pmu_name.offset];
914 if (ret != -1000)
917 return -1000;
925 for (size_t i = 0; i < table->num_pmus; i++) {
926 const struct pmu_table_entry *table_pmu = &table->pmus[i];
927 const char *pmu_name = &big_c_string[table_pmu->pmu_name.offset];
930 count += table_pmu->num_entries;
942 .pmu = &big_c_string[pmu->pmu_name.offset],
945 for (uint32_t i = 0; i < pmu->num_entries; i++) {
946 decompress_metric(pmu->entries[i].offset, &pm);
960 for (size_t i = 0; i < table->num_pmus; i++) {
961 int ret = pmu_metrics_table__for_each_metric_pmu(table, &table->pmus[i],
985 if (!map->arch)
988 if (!strcmp_cpuid_str(map->cpuid, cpuid)) {
989 table = &map->event_table;
997 for (i = 0; i < table->num_pmus; i++) {
998 const struct pmu_table_entry *table_pmu = &table->pmus[i];
999 const char *pmu_name = &big_c_string[table_pmu->pmu_name.offset];
1022 if (!map->arch)
1025 if (!strcmp_cpuid_str(map->cpuid, cpuid)) {
1026 table = &map->metric_table;
1037 tables->arch;
1039 if (!strcmp(tables->arch, arch) && !strcmp_cpuid_str(tables->cpuid, cpuid))
1040 return &tables->event_table;
1048 tables->arch;
1050 if (!strcmp(tables->arch, arch) && !strcmp_cpuid_str(tables->cpuid, cpuid))
1051 return &tables->metric_table;
1059 tables->arch;
1061 int ret = pmu_events_table__for_each_event(&tables->event_table,
1073 tables->arch;
1075 int ret = pmu_metrics_table__for_each_metric(&tables->metric_table, fn, data);
1086 tables->name;
1088 if (!strcmp(tables->name, name))
1089 return &tables->event_table;
1097 tables->name;
1099 int ret = pmu_events_table__for_each_event(&tables->event_table,
1111 tables->name;
1113 int ret = pmu_metrics_table__for_each_metric(&tables->metric_table, fn, data);
1122 def print_metricgroups() -> None:
1136 int low = 0, high = (int)ARRAY_SIZE(metricgroups) - 1;
1148 high = mid - 1;
1155 def main() -> None:
1158 def dir_path(path: str) -> str:
1165 action: Callable[[Sequence[str], os.DirEntry], None]) -> None:
1184 such as "arm/cortex-a34".''',
1192 'output_file', type=argparse.FileType('w', encoding='utf-8'), nargs='?', default=sys.stdout)
1196 #include <pmu-events/pmu-events.h>