def __show_info(cls, occurrence, all_events_opt, all_metrics_opt, all_opt): """ Display information about an ocurrence (event or metric) Parameters: occurrence - the event or metric to be displayed. all_opt - if should display all ocurrences all_events_opt - if should display all events only all_metrics_opt - if should display all metrics only """ processor = core.get_processor() core.supported_feature(processor, "Info") inf_h = InfoHandler() inf_h.show_info(occurrence, all_events_opt, all_metrics_opt, all_opt) return 0
def __compare_from_lists(self, comparison_type): """ Compare form list of dictionaries """ if comparison_type == 'metric': metrics = {} # Calculate metrics values processor = core.get_processor() metrics_calc = metrics_calculator.MetricsCalculator(processor) for events in self.profile_list: metrics_values = metrics_calc.calculate_metrics(events) for values in metrics_values: metrics[str(values[0])] = values[1] self.profile_list.append(metrics) self.__create_dict(self.profile_list) return self.__compare_(self.dict_vals)
def load_profiling_list(self, file_names, comparison_type): """ Create a list with two dictionaries containing "event|metric:value" pairs """ dict_list = [] for file_name in file_names: events = core.get_events_from_file(file_name) if comparison_type == 'event': dict_list.append(events) elif comparison_type == 'metric': metrics = {} # Calculate metrics values processor = core.get_processor() metrics_calc = metrics_calculator.MetricsCalculator(processor) metrics_values = metrics_calc.calculate_metrics(events) for values in metrics_values: metrics[str(values[0])] = values[1] dict_list.append(metrics) self.profile_list = dict_list
def __display(cls, cpi_file, breakdown_format, top_events, top_metrics): """ Show the output of CPI recording Parameters: cpi_file - the file where the value of the recorded events is saved breakdown_format - the format the breakdown output will be printed top_events - show top 'n' events top_metrics - show top 'n' metrics """ events = core.get_events_from_file(cpi_file) # Calculate metrics values processor = core.get_processor() metrics_calc = metrics_calculator.MetricsCalculator(processor) metrics_value = metrics_calc.calculate_metrics(events) # Show events and metrics hot spots if top_metrics is not None or top_events is not None: hot_s = HotSpots() if top_metrics: hot_s.print_metrics_hotspots(top_metrics, metrics_value) if top_events: hot_s.print_events_hotspots(top_events, events.items()) # Show breakdown output else: if breakdown_format == 'table': sorted_metrics = sorted(metrics_value, key=lambda x: float(x[2]), reverse=True) table = MetricsTable(sorted_metrics) table.print_table() elif breakdown_format == 'tree': tree = BreakdownTree(metrics_calc.get_raw_metrics(), metrics_value) tree.print_tree()
* Rafael Peria de Sene <*****@*****.**> """ import unittest import os from cpi import core class DrilldownExecutionTest(unittest.TestCase): """ Class to test drilldown execution """ dir_path = os.path.dirname(os.path.realpath(__file__)) with open("./cpi/events/power8.yaml") as f: clean_output = [] events_list = f.read().replace(" ", "").splitlines() for event in events_list: if 'PM' in event: clean_output.append(event.split(':')[0]) def execution_test(self): self.assertTrue(len(self.clean_output) == 46) if core.cmdexists('cpi'): for event in self.clean_output: status = core.execute('cpi drilldown -e ' + event + " /bin/sleep 1") if __name__ == '__main__': if "POWER8" in core.get_processor(): unittest.main()
def test_get_processor(self): self.assertEqual("POWER8", core.get_processor())
def __init__(self): self.processor = core.get_processor() self.e_reader = events_reader.EventsReader(self.processor) self.events_list = self.__get_events_list(self.e_reader.get_events()) self.metrics_list = self.__get_metrics_list()
def __record(self, cpi_file_name, quiet=False): """ Record the events and their values in a .cpi file Parameters: cpi_file_name - the path where the cpi file will be generated quiet - if should suppress any message during the recording step """ ocount = "perf" core.supported_feature(core.get_processor(), "Breakdown") if not os.path.isfile(self.__binary_path): sys.stderr.write(self.__binary_path + ' binary file not found\n') sys.exit(1) timestamp = core.get_timestamp() binary_name = self.__binary_path.split("/").pop(-1) dir_current = os.getcwd() ocount_out = dir_current + "/output" if not core.cmdexists(ocount): sys.stderr.write(ocount + " is not installed in the system. " + "Install oprofile before continue." + "\n") sys.exit(2) reader = events_reader.EventsReader(core.get_processor()) if not cpi_file_name: fname = dir_current + "/" + binary_name + "_" + timestamp + ".cpi" cpi_file_name = fname else: dir_file = os.path.dirname(os.path.realpath(cpi_file_name)) if not os.path.exists(dir_file): sys.stderr.write(dir_file + " directory not found\n") return 1 elif os.path.isdir(cpi_file_name): sys.stderr.write(cpi_file_name + " is not a file\n") return 1 start_time = time.time() exec_counter = 0 events = {} # Run ocount for all events groups for event in reader.get_events(): exec_counter = exec_counter + 1 ocount_cmd = ocount + " stat -x, -o " + ocount_out for item in event: ocount_cmd += " -e " + item if not quiet: sys.stdout.write("\r Recording CPI Events: %d/%d " "iterations (elapsed time: %d seconds)" % (exec_counter, len(reader.get_events()), (time.time() - start_time))) sys.stdout.flush() status, output = core.execute_stdout(ocount_cmd + ' ' + self.__binary_path + ' ' + self.__binary_args) if status != 0: sys.stderr.write("\n\nFailed to run {0} command.". format(ocount) + "\n" + output.decode() + "\n") sys.exit(1) core.parse_file(ocount_out, events) core.execute("rm " + ocount_out) if not quiet: print() core.save_events(events, cpi_file_name) return events
def __run_drilldown(self, event, autodrilldown, autodrilldown_file, threshold): """ Run the drilldown feature Parameters: event - the event to be used in drilldown autodrilldown - run autodrilldown in top 'n' events autodrilldown_file - run the autodrilldown using values from a generated file threshold - the threshold value to show groups """ core.supported_feature(core.get_processor(), "Drilldown") if not os.path.isfile(self.__binary_path): sys.stderr.write(self.__binary_path + ' binary file not found\n') sys.exit(1) operf = drilldown_core.OPERF if not core.cmdexists(operf): sys.stderr.write(operf + " is not installed in the system. " + "Install oprofile before continue." + "\n") sys.exit(2) if autodrilldown: # Running autodrilldown generating a .cpi file if not autodrilldown_file: events = self.__record(None, False) # Running autodrilldown using an already created file elif autodrilldown_file: events = core.get_events_from_file(autodrilldown_file) else: events = {event: '0'} events = drilldown_core.sort_events(events) if autodrilldown: # Use the 'n' first elements events = events[:autodrilldown] reader = events_reader.EventsReader(core.get_processor()) # Run drilldown with chosen events for element in events: event = element[0] # Event is not supported with drilldown feature if not reader.valid_event(event): sys.stderr.write("Event {0} is not supported by drilldown " "feature.".format(event) + "\nChoose a supported event and try again\n") sys.exit(1) sys.stdout.write("\r Running drilldown with event: %s \n" % (event)) # Run operf min_count = str(reader.get_event_mincount(event)) drilldown_core.run_operf(self.__binary_path, self.__binary_args, event, min_count) # Run opreport report_file = "opreport.xml" drilldown_core.run_opreport(event, report_file) # Run drilldown drilldown_view = DrilldownView() drilldown_view.print_drilldown(event, report_file, threshold)