Lines Matching +full:early +full:- +full:to +full:- +full:mid
2 # SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
3 """Convert directories of JSON events to C code."""
26 # Map from an event name to an architecture standard
30 # Events to write out when the table is closed
32 # Name of events table to be written out
34 # Metrics to write out when the table is closed
36 # Name of metrics table to be written out
40 # Map from the name of a metric group to a description of the group.
46 # Seems useful, put it early.
63 def removesuffix(s: str, suffix: str) -> str:
66 The removesuffix function is added to str in Python 3.9. We aim for 3.6
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
108 string are recorded and when stored to disk these don't need
109 relocation. To reduce the size of the string further, identical
110 strings are merged. If a longer string ends-with the same value as a
126 def add(self, s: str, metric: bool) -> None:
127 """Called to add to the big string."""
135 def compute(self) -> None:
136 """Called once all strings are added to compute the string and offsets."""
141 sorted_reversed_strings = sorted([x[::-1] for x in self.strings])
144 # for each string to see if there is a better candidate to fold it
147 # in folded_strings, we don't need to record the offset as it is
157 folded_strings[s[::-1]] = sorted_reversed_strings[best_pos][::-1]
166 # being appended to - comments, etc. don't count. big_string is
168 # in Python and so appending to one causes memory issues, while
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)
204 def llx(x: int) -> str:
205 """Convert an int to a string similar to a printf modifier of %#llx."""
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."""
266 def unit_to_pmu(unit: str) -> Optional[str]:
267 """Convert a JSON Unit to Linux PMU name."""
271 # it's not realistic to keep adding these, we need something more scalable ...
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:
397 # Copy from the architecture standard event to self for undefined fields.
406 def __repr__(self) -> str:
414 def build_c_string(self, metric: bool) -> str:
430 def to_c_string(self, metric: bool) -> str:
433 def fix_comment(s: str) -> str:
441 def read_json_events(path: str, topic: str) -> Sequence[JsonEvent]:
451 if event.metric_name and '-' not in event.metric_name:
458 # f'to\n"{updates[event.metric_name]}"')
463 def preprocess_arch_std_files(archpath: str) -> None:
479 def add_events_table_entries(item: os.DirEntry, topic: str) -> None:
480 """Add contents of file to _pending_events table."""
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:
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:
644 def process_one_file(parents: Sequence[str], item: os.DirEntry) -> None:
646 def is_leaf_dir_ignoring_sys(path: str) -> bool:
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. */
691 /* Struct used to make the PMU metric table implementation opaque to callers. */
698 * Map a CPU to its table of PMU events. The CPU is identified by the
699 * cpuid field, which is an arch-specific identifier for the CPU.
700 * The identifier specified in tools/perf/pmu-events/arch/xxx/mapfile
713 * Global table mapping each known CPU for the architecture to its
791 def print_system_mapping_table() -> None:
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);
902 .pmu = &big_c_string[pmu->pmu_name.offset],
904 int low = 0, high = pmu->num_entries - 1;
907 int cmp, mid = (low + high) / 2;
909 decompress_event(pmu->entries[mid].offset, &pe);
915 low = mid + 1;
919 high = mid - 1;
925 low = mid + 1;
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];
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];
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);
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;
1226 int mid = (low + high) / 2;
1227 const char *mgroup = &big_c_string[metricgroups[mid][0]];
1231 return &big_c_string[metricgroups[mid][1]];
1233 low = mid + 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:
1271 ap.add_argument('model', help='''Select a model such as skylake to
1272 reduce the code size. Normally set to "all". For architectures like
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>