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 __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)