Пример #1
0
    def test_execute_stdout(self):
        status, output = core.execute_stdout("cd")
        self.assertEqual(0, status)
        self.assertEqual("", output)

        status, output = core.execute_stdout("ls /bla/foo")
        self.assertNotEqual(0, status)
        self.assertIn("No such file or directory", output)
Пример #2
0
def run_operf(binary_path, binary_args, event, min_count):
    """ Run operf and exit if an error happens """
    operf_cmd = OPERF + " -e {0}:{1} {2} {3}".format(event, min_count,
                                                     binary_path, binary_args)
    status, output = core.execute_stdout(operf_cmd)
    if status != 0:
        sys.stderr.write("Failed to run {0} command.\n".format(OPERF) + "\n" +
                         output)
        sys.exit(1)
def run_opreport(event, report_file):
    """ Run opreport and exit if an error happens """
    opreport_cmd = OPREPORT + " --debug-info --symbols --details "
    opreport_cmd += "--xml event:{0} -o {1}".format(event, report_file)
    status, output = core.execute_stdout(opreport_cmd)
    if status != 0:
        sys.stderr.write("Failed to run {0} command.\n".format(OPREPORT) +
                         "\n" + output.decode())
        sys.exit(1)
Пример #4
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