@@ -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"\t TRANSLATED 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"\t TRANSLATED 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 \t OPTION: { option } \t VALUE: { 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 \t OPTION: { option } \t VALUE: { 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 \t OPTION: { option } \t VALUE: { 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