Skip to content

Commit 7ebcc06

Browse files
committed
Fix for hybrid device prefixes
1 parent 61052f1 commit 7ebcc06

File tree

2 files changed

+141
-93
lines changed

2 files changed

+141
-93
lines changed

scripts/config/replacements_config.json

Lines changed: 13 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -48,39 +48,6 @@
4848
"CHAS_PER_SOCKET":"UNC_CHA([^\\s]*)",
4949
"CORES_PER_SOCKET":"UNC_C_([^\\s]*)"
5050
},
51-
"association_option_replacements": [
52-
{
53-
"events": ["ICACHE_", "INT_MISC", "UOPS_", "IDQ", "OFFCORE_",
54-
"L1D_", "DTLB_", "AMX_", "ITLB_", "EXE_", "INST_", "ASSISTS",
55-
"SW_", "RS", "DSB2MITE_", "ARB_", "LSD"],
56-
"unit":"cpu",
57-
"translations":{
58-
"c":"cmask",
59-
"u":"umask",
60-
"i":"inv",
61-
"e":"edge"
62-
},
63-
"scale":1
64-
},
65-
{
66-
"events": ["UNC_CHA_"],
67-
"unit":"cha",
68-
"translations":{
69-
"filter1":"config1",
70-
"c":"thresh"
71-
},
72-
"scale":100000000
73-
},
74-
{
75-
"events":["UNC_C_"],
76-
"unit":"cbox",
77-
"translations":{
78-
"opc":"filter_opc",
79-
"tid":"filter_tid"
80-
},
81-
"scale":1
82-
}
83-
],
8451
"scale_unit_replacements": {
8552
"per instruction":"per_instr",
8653
"per second":"per_sec",
@@ -90,5 +57,18 @@
9057
"MB/sec":"MB/s",
9158
"GT/sec":"GT/s",
9259
"Watts":"Watts"
60+
},
61+
"core_option_translations": {
62+
"c":"cmask",
63+
"u":"umask",
64+
"i":"inv",
65+
"e":"edge",
66+
"eq": null
67+
},
68+
"uncore_option_translations": {
69+
"filter1":"config1",
70+
"c":"thresh",
71+
"opc":"filter_opc",
72+
"tid":"filter_tid"
9373
}
9474
}

scripts/perf_format_converter.py

Lines changed: 128 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,8 @@ def __init__(self, input_fp):
162162
self.metric_assoc_replacement_dict = None
163163
self.metric_source_event_dict = None
164164
self.scale_unit_replacement_dict = None
165-
self.association_option_replacement_dict = None
165+
self.core_option_translation_dict = None
166+
self.uncore_option_translation_dict = None
166167
self.platforms = None
167168
self.init_dictionaries()
168169

@@ -190,9 +191,10 @@ def init_dictionaries(self):
190191
try:
191192
self.metric_name_replacement_dict = config_dict["metric_name_replacements"]
192193
self.metric_assoc_replacement_dict = config_dict["metric_association_replacements"]
194+
self.core_option_translation_dict = config_dict["core_option_translations"]
195+
self.uncore_option_translation_dict = config_dict["uncore_option_translations"]
193196
self.metric_source_event_dict = config_dict["metric_source_events"]
194197
self.scale_unit_replacement_dict = config_dict["scale_unit_replacements"]
195-
self.association_option_replacement_dict = config_dict["association_option_replacements"]
196198
except KeyError as e:
197199
sys.exit(f"[ERROR] - Error in config JSON format {str(e)}. Exiting")
198200

@@ -281,7 +283,7 @@ def get_expression(self, metric, platform):
281283
# Term is not an operator or a numeric value
282284
if "tma_" not in term:
283285
# Translate any event names
284-
expression_list[i] = self.translate_metric_event(term.upper(), platform)
286+
expression_list[i] = self.translate_metric_event(term, platform)
285287

286288
# Combine into formula
287289
expression = " ".join(expression_list).strip()
@@ -420,70 +422,136 @@ def translate_metric_event(self, event_name, platform):
420422
@param event_name: string containing event name
421423
@returns: string containing un-aliased expression
422424
"""
425+
translated_event = None
426+
427+
# Get prefix
428+
prefix = None
429+
if platform["IsHybrid"]: # Hybrid
430+
if platform["CoreType"] == "P-core":
431+
prefix = "cpu_core"
432+
elif platform["CoreType"] == "E-core":
433+
prefix = "cpu_atom"
434+
else:
435+
if self.is_core_event(event_name):
436+
prefix = "cpu"
437+
else:
438+
if "unc_cha_" in event_name.lower():
439+
prefix = "cha"
440+
elif "unc_c_" in event_name.lower():
441+
prefix = "cbox"
442+
423443
# Check if association has 1:1 replacement
424444
for replacement in self.metric_assoc_replacement_dict:
425-
if re.match(replacement, event_name):
426-
return self.metric_assoc_replacement_dict[replacement]
445+
if re.match(replacement, event_name.upper()):
446+
print(f"\tTRANSLATED EVENT: {self.metric_assoc_replacement_dict[replacement.upper()]}")
447+
return self.metric_assoc_replacement_dict[replacement.upper()]
427448

428-
# Check for retire latency option
429-
if ":retire_latency" in event_name.lower():
430-
split = event_name.split(":")
431-
if platform["IsHybrid"]:
432-
if platform["CoreType"] == "P-core":
433-
return f"cpu_core@{split[0]}@R"
434-
elif platform["CoreType"] == "E-core":
435-
return f"cpu_atom@{split[0]}@R"
436-
else:
437-
return split[0] + ":R"
438-
439-
# Check for other event option
440-
if ":" in event_name and "TOPDOWN" not in event_name:
441-
for row in self.association_option_replacement_dict:
442-
for event in row["events"]:
443-
if event in event_name:
444-
split = event_name.split(":")
445-
return self.translate_event_options(split, row)
446-
print("[ERROR] - Event with no option translations: " + event_name)
447-
448-
return event_name.replace("RXL", "RxL")
449-
449+
# Translate other events
450+
if ":" in event_name.lower():
451+
if ":retire_latency" in event_name.lower(): # Check for retire latency option
452+
split = event_name.split(":")
453+
if platform["IsHybrid"]:
454+
translated_event = f"{prefix}@{split[0]}@R"
455+
else:
456+
translated_event = split[0] + ":R"
457+
else: # Check for other event option
458+
split = event_name.split(":")
459+
base_event = split[0] # Base event
460+
event_options = split[1:] # Event options
461+
print(f"\t EVENT: {base_event} \t OPTIONS: {event_options}")
450462

451-
def translate_event_options(self, split, event_info):
452-
"""
453-
Takes info about an event with options and translates the options
454-
into a perf compatible format
463+
464+
translated_options = []
465+
for option in event_options:
466+
if self.translate_event_option(option, self.is_core_event(base_event)):
467+
translated_options.append(self.translate_event_option(option, self.is_core_event(base_event)))
455468

456-
@param split: list of options as strings
457-
@param event_info: info on how to translate options
458-
@returns: string containing translated event
459-
"""
460-
translation = event_info["unit"] + "@" + split[0]
461-
for option in split[1:]:
462-
if "=" in option:
463-
split = [s.lower() for s in option.split("=")]
464-
if split[0] in event_info["translations"]:
465-
if "x" in split[1] or "X" in split[1]:
466-
translation += "\\," + event_info["translations"][split[0]] + "\\=" + split[1]
467-
else:
468-
translation += "\\," + event_info["translations"][split[0]] + "\\=" + (int(split[1]) * event_info["scale"])
469-
elif "0x" in option:
470-
split = option.split("0x")
471-
if split[0] in event_info["translations"]:
472-
translation += "\\," + event_info["translations"][split[0]] + "\\=" + "0x" + split[1]
473-
else:
474-
print(f"ERROR - {split[0]} not in event translations...")
475-
elif "0X" in option:
476-
split = option.split("0X")
477-
if split[0].lower() in event_info["translations"]:
478-
translation += "\\," + event_info["translations"][split[0].lower()] + "\\=" + "0x" + split[1]
469+
if prefix:
470+
translated_event = f"{prefix}@{base_event.upper()}\\,{"\\\\,".join(translated_options)}@"
479471
else:
480-
print(f"ERROR - {split[0]} not in event translations...")
472+
translated_event = f"{base_event.upper()}@{"\\\\,".join(translated_options)}@"
473+
print("!!!!!!!!!NO PREFIX. SOMETHING IS WRONG!!!!!!!!!!!!!")
474+
else: # No event options
475+
if prefix and self.is_core_event(event_name) and platform["IsHybrid"]:
476+
translated_event = f"{prefix}@{event_name.upper()}@"
481477
else:
482-
match = re.match(r"([a-zA-Z]+)([\d]+)", option.lower())
483-
if match:
484-
if match[1] in event_info["translations"]:
485-
translation += "\\,"+ event_info["translations"][match[1]] + "\\=" + "0x" + match[2]
486-
return translation + "@"
478+
translated_event = event_name.upper()
479+
480+
print(f"\tTRANSLATED EVENT: {translated_event.replace("TXL", "TxL")}")
481+
return translated_event.replace("RXL", "RxL")
482+
483+
def is_core_event(self, event):
484+
if "unc_" in event.lower():
485+
return False
486+
return True
487+
488+
def translate_event_option(self, full_option, is_core_event):
489+
if "=" in full_option:
490+
split = full_option.split("=")
491+
option = split[0]
492+
value = split[1]
493+
print(f"\t\t\tOPTION: {option}\tVALUE: {value}")
494+
elif "0x" in full_option.lower():
495+
split = full_option.lower().split("0x")
496+
option = split[0]
497+
value = split[1]
498+
print(f"\t\t\tOPTION: {option}\tVALUE: {value}")
499+
else:
500+
match = re.match(r"([a-zA-Z]+)([\d]+)", full_option.lower())
501+
if match:
502+
option = match[1]
503+
value = match[2]
504+
print(f"\t\t\tOPTION: {option}\tVALUE: {value}")
505+
else:
506+
print("ERROR COULD NOT FIND OPTION")
507+
508+
if not option:
509+
return None
510+
511+
try:
512+
if is_core_event:
513+
return f"{self.core_option_translation_dict[option.lower()]}\\=0x{value}"
514+
else:
515+
return f"{self.uncore_option_translation_dict[option.lower()]}\\=0x{value}"
516+
except KeyError:
517+
return None
518+
519+
# def translate_event_options(self, split, event_info):
520+
# """
521+
# Takes info about an event with options and translates the options
522+
# into a perf compatible format
523+
524+
# @param split: list of options as strings
525+
# @param event_info: info on how to translate options
526+
# @returns: string containing translated event
527+
# """
528+
# translation = event_info["unit"] + "@" + split[0]
529+
# for option in split[1:]:
530+
# if "=" in option:
531+
# split = [s.lower() for s in option.split("=")]
532+
# if split[0] in event_info["translations"]:
533+
# if "x" in split[1] or "X" in split[1]:
534+
# translation += "\\," + event_info["translations"][split[0]] + "\\=" + split[1]
535+
# else:
536+
# translation += "\\," + event_info["translations"][split[0]] + "\\=" + (int(split[1]) * event_info["scale"])
537+
# elif "0x" in option:
538+
# split = option.split("0x")
539+
# if split[0] in event_info["translations"]:
540+
# translation += "\\," + event_info["translations"][split[0]] + "\\=" + "0x" + split[1]
541+
# else:
542+
# print(f"ERROR - {split[0]} not in event translations...")
543+
# elif "0X" in option:
544+
# split = option.split("0X")
545+
# if split[0].lower() in event_info["translations"]:
546+
# translation += "\\," + event_info["translations"][split[0].lower()] + "\\=" + "0x" + split[1]
547+
# else:
548+
# print(f"ERROR - {split[0]} not in event translations...")
549+
# else:
550+
# match = re.match(r"([a-zA-Z]+)([\d]+)", option.lower())
551+
# if match:
552+
# if match[1] in event_info["translations"]:
553+
# translation += "\\,"+ event_info["translations"][match[1]] + "\\=" + "0x" + match[2]
554+
# return translation + "@"
487555

488556

489557
def translate_metric_constant(self, constant_name, metric):

0 commit comments

Comments
 (0)