Exemple #1
0
 def test_execute(self):
     self.assertEqual(0, core.execute("cd"))
     self.assertNotEqual(0, core.execute("foo_bar"))
Exemple #2
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")
Exemple #3
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