Esempio n. 1
0
    def output_before_run(self, run):
        """
        The method output_before_run() prints the name of a file to terminal.
        It returns the name of the logfile.
        @param run: a Run object
        """
        # output in terminal
        runSet = run.runSet
        try:
            OutputHandler.print_lock.acquire()

            try:
                runSet.started_runs += 1
            except AttributeError:
                runSet.started_runs = 1

            timeStr = time.strftime("%H:%M:%S", time.localtime()) + "   "
            progressIndicator = " ({0}/{1})".format(runSet.started_runs, len(runSet.runs))
            terminalTitle = TERMINAL_TITLE.format(runSet.full_name + progressIndicator) if USE_COLORS and sys.stdout.isatty() else ""
            if self.benchmark.num_of_threads == 1:
                util.printOut(terminalTitle + timeStr + self.format_sourcefile_name(run.identifier, runSet), '')
            else:
                util.printOut(terminalTitle + timeStr + "starting   " + self.format_sourcefile_name(run.identifier, runSet))
        finally:
            OutputHandler.print_lock.release()
Esempio n. 2
0
    def output_after_benchmark(self, isStoppedByInterrupt):
        self.statistics.print_to_terminal()

        if self.xml_file_names:

            def _find_file_relative(name):
                """
                Find a file with the given name in the same directory as this script.
                Returns a path relative to the current directory, or None.
                """
                path = os.path.join(os.path.dirname(sys.argv[0]), name)
                if not os.path.isfile(path):
                    path = os.path.join(os.path.dirname(__file__), os.path.pardir, name)
                    if not os.path.isfile(path):
                        return None

                if os.path.dirname(path) in os.environ['PATH'].split(os.pathsep):
                    # in PATH, just use command name
                    return os.path.basename(path)

                path = os.path.relpath(path)
                if path == name:
                    path = './' + path # for easier copy and paste into a shell
                return path

            tableGeneratorPath = _find_file_relative('table-generator.py') \
                              or _find_file_relative('table-generator')
            if tableGeneratorPath:
                xml_file_names = [file+".bz2" for file in self.xml_file_names] if self.compress_results else self.xml_file_names
                util.printOut("In order to get HTML and CSV tables, run\n{0} '{1}'"
                              .format(tableGeneratorPath, "' '".join(xml_file_names)))

        if isStoppedByInterrupt:
            util.printOut("\nScript was interrupted by user, some runs may not be done.\n")
Esempio n. 3
0
    def output_before_run(self, run):
        """
        The method output_before_run() prints the name of a file to terminal.
        It returns the name of the logfile.
        @param run: a Run object
        """
        # output in terminal
        runSet = run.runSet
        try:
            OutputHandler.print_lock.acquire()

            try:
                runSet.started_runs += 1
            except AttributeError:
                runSet.started_runs = 1

            timeStr = time.strftime("%H:%M:%S", time.localtime()) + "   "
            progressIndicator = f" ({runSet.started_runs}/{len(runSet.runs)})"
            terminalTitle = TERMINAL_TITLE.format(runSet.full_name +
                                                  progressIndicator)
            if self.benchmark.num_of_threads == 1:
                util.printOut(
                    terminalTitle + timeStr +
                    self.format_sourcefile_name(run.identifier, runSet),
                    "",
                )
            else:
                util.printOut(
                    terminalTitle + timeStr + "starting   " +
                    self.format_sourcefile_name(run.identifier, runSet))
        finally:
            OutputHandler.print_lock.release()
Esempio n. 4
0
    def print_to_terminal(self):
        correct = self.dic[result.CATEGORY_CORRECT]
        correct_true = self.dic[(result.CATEGORY_CORRECT,
                                 result.RESULT_CLASS_TRUE)]
        correct_false = correct - correct_true
        incorrect = self.dic[result.CATEGORY_WRONG]
        incorrect_true = self.dic[(result.CATEGORY_WRONG,
                                   result.RESULT_CLASS_TRUE)]
        incorrect_false = incorrect - incorrect_true

        width = 6
        output = [
            '',
            'Statistics:' + str(self.counter).rjust(width + 9) + ' Files',
            '  correct:          ' + str(correct).rjust(width),
            '    correct true:   ' + str(correct_true).rjust(width),
            '    correct false:  ' + str(correct_false).rjust(width),
            '  incorrect:        ' + str(incorrect).rjust(width),
            '    incorrect true: ' + str(incorrect_true).rjust(width),
            '    incorrect false:' + str(incorrect_false).rjust(width),
            '  unknown:          ' +
            str(self.dic[result.CATEGORY_UNKNOWN] +
                self.dic[result.CATEGORY_ERROR]).rjust(width),
        ]
        if self.max_score:
            output.append('  Score:            ' +
                          str(self.score).rjust(width) + ' (max: ' +
                          str(self.max_score) + ')')
        util.printOut('\n'.join(output) + '\n')
Esempio n. 5
0
    def output_before_run(self, run):
        """
        The method output_before_run() prints the name of a file to terminal.
        It returns the name of the logfile.
        @param run: a Run object
        """
        # output in terminal
        runSet = run.runSet
        try:
            OutputHandler.print_lock.acquire()

            try:
                runSet.started_runs += 1
            except AttributeError:
                runSet.started_runs = 1

            timeStr = time.strftime("%H:%M:%S", time.localtime()) + "   "
            progressIndicator = " ({0}/{1})".format(runSet.started_runs,
                                                    len(runSet.runs))
            terminalTitle = TERMINAL_TITLE.format(
                runSet.full_name + progressIndicator
            ) if USE_COLORS and sys.stdout.isatty() else ""
            if self.benchmark.num_of_threads == 1:
                util.printOut(
                    terminalTitle + timeStr +
                    self.format_sourcefile_name(run.identifier, runSet), '')
            else:
                util.printOut(
                    terminalTitle + timeStr + "starting   " +
                    self.format_sourcefile_name(run.identifier, runSet))
        finally:
            OutputHandler.print_lock.release()

        # get name of file-specific log-file
        self.all_created_files.append(run.log_file)
Esempio n. 6
0
    def output_after_run(self, run):
        """
        The method output_after_run() prints filename, result, time and status
        of a run to terminal and stores all data in XML
        """

        # format times, type is changed from float to string!
        cputime_str = util.format_number(run.cputime, TIME_PRECISION)
        walltime_str = util.format_number(run.walltime, TIME_PRECISION)

        # format numbers, number_of_digits is optional, so it can be None
        for column in run.columns:
            if column.number_of_digits is not None:

                # if the number ends with "s" or another letter, remove it
                if (not column.value.isdigit()) and column.value[-2:-1].isdigit():
                    column.value = column.value[:-1]

                try:
                    floatValue = float(column.value)
                    column.value = util.format_number(floatValue, column.number_of_digits)
                except ValueError: # if value is no float, don't format it
                    pass

        # store information in run
        run.resultline = self.create_output_line(run.runSet, run.identifier, run.status,
                cputime_str, walltime_str, run.values.get('host'),
                run.columns)
        self.add_values_to_run_xml(run)

        # output in terminal/console
        if USE_COLORS and sys.stdout.isatty(): # is terminal, not file
            statusStr = COLOR_DIC[run.category].format(run.status.ljust(LEN_OF_STATUS))
        else:
            statusStr = run.status.ljust(LEN_OF_STATUS)

        try:
            OutputHandler.print_lock.acquire()

            valueStr = statusStr + cputime_str.rjust(8) + walltime_str.rjust(8)
            if self.benchmark.num_of_threads == 1:
                util.printOut(valueStr)
            else:
                timeStr = time.strftime("%H:%M:%S", time.localtime()) + " "*14
                util.printOut(timeStr + self.format_sourcefile_name(run.identifier, run.runSet) + valueStr)

            # write result in txt_file and XML
            self.txt_file.append(self.run_set_to_text(run.runSet), False)
            self.statistics.add_result(run)

            # we don't want to write this file to often, it can slow down the whole script,
            # so we wait at least 10 seconds between two write-actions
            currentTime = util.read_monotonic_time()
            if currentTime - run.runSet.xml_file.lastModifiedTime > 60:
                run.runSet.xml_file.replace(self._result_xml_to_string(run.runSet.xml))
                run.runSet.xml_file.lastModifiedTime = util.read_monotonic_time()

        finally:
            OutputHandler.print_lock.release()
Esempio n. 7
0
def stop():
    global STOPPED_BY_INTERRUPT
    STOPPED_BY_INTERRUPT = True

    # kill running jobs
    util.printOut("killing subprocesses...")
    for worker in WORKER_THREADS:
        worker.stop()
Esempio n. 8
0
    def output_before_run_set(self, runSet):
        """
        The method output_before_run_set() calculates the length of the
        first column for the output in terminal and stores information
        about the runSet in XML.
        @param runSet: current run set
        """
        sourcefiles = [run.identifier for run in runSet.runs]

        # common prefix of file names
        runSet.common_prefix = util.common_base_dir(sourcefiles) + os.path.sep

        # length of the first column in terminal
        runSet.max_length_of_filename = max(
            len(file) for file in sourcefiles) if sourcefiles else 20
        runSet.max_length_of_filename = max(
            20, runSet.max_length_of_filename - len(runSet.common_prefix))

        # write run set name to terminal
        numberOfFiles = len(runSet.runs)
        numberOfFilesStr = ("     (1 file)" if numberOfFiles == 1 else
                            "     ({0} files)".format(numberOfFiles))
        util.printOut("\nexecuting run set" +
                      (" '" + runSet.name + "'" if runSet.name else "") +
                      numberOfFilesStr +
                      (TERMINAL_TITLE.format(runSet.full_name)
                       if USE_COLORS and sys.stdout.isatty() else ""))

        # write information about the run set into txt_file
        self.writeRunSetInfoToLog(runSet)

        # prepare information for text output
        for run in runSet.runs:
            run.resultline = self.format_sourcefile_name(
                run.identifier, runSet)

            # prepare XML structure for each run and runSet
            run.xml = ET.Element(
                "run", {
                    "name": run.identifier,
                    "files": "[" + ", ".join(run.sourcefiles) + "]"
                })
            if run.specific_options:
                run.xml.set("options", " ".join(run.specific_options))
            if run.properties:
                run.xml.set("properties", " ".join(sorted(run.properties)))
            run.xml.extend(self.xml_dummy_elements)

        runSet.xml = self.runs_to_xml(runSet, runSet.runs)

        # write (empty) results to txt_file and XML
        self.txt_file.append(self.run_set_to_text(runSet), False)
        xml_file_name = self.get_filename(runSet.name, "xml")
        runSet.xml_file = filewriter.FileWriter(
            xml_file_name, self._result_xml_to_string(runSet.xml))
        runSet.xml_file.lastModifiedTime = util.read_monotonic_time()
        self.all_created_files.append(xml_file_name)
        self.xml_file_names.append(xml_file_name)
Esempio n. 9
0
def stop():
    global STOPPED_BY_INTERRUPT
    STOPPED_BY_INTERRUPT = True

    util.printOut("Killing subprocesses. May take some seconds...")
    if not APPENGINE_POLLER_THREAD == None:
        APPENGINE_POLLER_THREAD.join()
    if not APPENGINE_SUBMITTER_THREAD == None:
        APPENGINE_SUBMITTER_THREAD.join()
Esempio n. 10
0
def stop():
    global STOPPED_BY_INTERRUPT
    STOPPED_BY_INTERRUPT = True

    util.printOut("Killing subprocesses. May take some seconds...")
    if not APPENGINE_POLLER_THREAD == None:
        APPENGINE_POLLER_THREAD.join()
    if not APPENGINE_SUBMITTER_THREAD == None:
        APPENGINE_SUBMITTER_THREAD.join()
Esempio n. 11
0
def stop():
    global STOPPED_BY_INTERRUPT
    STOPPED_BY_INTERRUPT = True

    # kill running jobs
    util.printOut("killing subprocesses...")
    for worker in WORKER_THREADS:
        worker.stop()

    # wait until all threads are stopped
    for worker in WORKER_THREADS:
        worker.join()
Esempio n. 12
0
    def output_before_run_set(self, runSet):
        """
        The method output_before_run_set() calculates the length of the
        first column for the output in terminal and stores information
        about the runSet in XML.
        @param runSet: current run set
        """
        sourcefiles = [run.identifier for run in runSet.runs]

        # common prefix of file names
        runSet.common_prefix = util.common_base_dir(sourcefiles) + os.path.sep

        # length of the first column in terminal
        runSet.max_length_of_filename = max(len(file) for file in sourcefiles) if sourcefiles else 20
        runSet.max_length_of_filename = max(20, runSet.max_length_of_filename - len(runSet.common_prefix))

        # write run set name to terminal
        numberOfFiles = len(runSet.runs)
        numberOfFilesStr = ("     (1 file)" if numberOfFiles == 1
                        else "     ({0} files)".format(numberOfFiles))
        util.printOut("\nexecuting run set"
            + (" '" + runSet.name + "'" if runSet.name else "")
            + numberOfFilesStr
            + (TERMINAL_TITLE.format(runSet.full_name) if USE_COLORS and sys.stdout.isatty() else ""))

        # write information about the run set into txt_file
        self.writeRunSetInfoToLog(runSet)

        # prepare information for text output
        for run in runSet.runs:
            run.resultline = self.format_sourcefile_name(run.identifier, runSet)

        # prepare XML structure for each run and runSet
            run.xml = ET.Element("run",
                                 {"name": run.identifier, "files": "[" + ", ".join(run.sourcefiles) + "]"})
            if run.specific_options:
                run.xml.set("options", " ".join(run.specific_options))
            if run.properties:
                run.xml.set("properties", " ".join(sorted(run.properties)))
            run.xml.extend(self.xml_dummy_elements)

        runSet.xml = self.runs_to_xml(runSet, runSet.runs)

        # write (empty) results to txt_file and XML
        self.txt_file.append(self.run_set_to_text(runSet), False)
        xml_file_name = self.get_filename(runSet.name, "xml")
        runSet.xml_file = filewriter.FileWriter(xml_file_name,
                       self._result_xml_to_string(runSet.xml))
        runSet.xml_file.lastModifiedTime = util.read_monotonic_time()
        self.all_created_files.append(xml_file_name)
        self.xml_file_names.append(xml_file_name)
Esempio n. 13
0
    def output_for_skipping_run_set(self, runSet, reason=None):
        '''
        This function writes a simple message to terminal and logfile,
        when a run set is skipped.
        There is no message about skipping a run set in the xml-file.
        '''

        # print to terminal
        util.printOut("\nSkipping run set" +
                      (" '" + runSet.name + "'" if runSet.name else "") +
                      (" " + reason if reason else ""))

        # write into txt_file
        runSetInfo = "\n\n"
        if runSet.name:
            runSetInfo += runSet.name + "\n"
        runSetInfo += "Run set {0} of {1}: skipped {2}\n".format(
            runSet.index, len(self.benchmark.run_sets), reason or "")
        self.txt_file.append(runSetInfo)
Esempio n. 14
0
def main(benchexec=None, argv=None):
    """
    The main method of BenchExec for use in a command-line script.
    In addition to calling benchexec.start(argv),
    it also handles signals and keyboard interrupts.
    It does not return but calls sys.exit().
    @param benchexec: An instance of BenchExec for executing benchmarks.
    @param argv: optionally the list of command-line options to use
    """
    if sys.version_info < (3,):
        sys.exit('benchexec needs Python 3 to run.')
    # ignore SIGTERM
    signal.signal(signal.SIGTERM, signal_handler_ignore)
    try:
        if not benchexec:
            benchexec = BenchExec()
        sys.exit(benchexec.start(argv or sys.argv))
    except KeyboardInterrupt: # this block is reached, when interrupt is thrown before or after a run set execution
        benchexec.stop()
        util.printOut("\n\nScript was interrupted by user, some runs may not be done.")
Esempio n. 15
0
    def output_for_skipping_run_set(self, runSet, reason=None):
        '''
        This function writes a simple message to terminal and logfile,
        when a run set is skipped.
        There is no message about skipping a run set in the xml-file.
        '''

        # print to terminal
        util.printOut("\nSkipping run set" +
               (" '" + runSet.name + "'" if runSet.name else "") +
               (" " + reason if reason else "")
              )

        # write into txt_file
        runSetInfo = "\n\n"
        if runSet.name:
            runSetInfo += runSet.name + "\n"
        runSetInfo += "Run set {0} of {1}: skipped {2}\n".format(
                runSet.index, len(self.benchmark.run_sets), reason or "")
        self.txt_file.append(runSetInfo)
Esempio n. 16
0
def main(benchexec=None, argv=None):
    """
    The main method of BenchExec for use in a command-line script.
    In addition to calling benchexec.start(argv),
    it also handles signals and keyboard interrupts.
    It does not return but calls sys.exit().
    @param benchexec: An instance of BenchExec for executing benchmarks.
    @param argv: optionally the list of command-line options to use
    """
    if sys.version_info < (3,):
        sys.exit('benchexec needs Python 3 to run.')
    # ignore SIGTERM
    signal.signal(signal.SIGTERM, signal_handler_ignore)
    try:
        if not benchexec:
            benchexec = BenchExec()
        sys.exit(benchexec.start(argv or sys.argv))
    except KeyboardInterrupt: # this block is reached, when interrupt is thrown before or after a run set execution
        benchexec.stop()
        util.printOut("\n\nScript was interrupted by user, some runs may not be done.")
Esempio n. 17
0
    def output_after_benchmark(self, isStoppedByInterrupt):
        self.statistics.print_to_terminal()

        if self.xml_file_names:

            def _find_file_relative(name):
                """
                Find a file with the given name in the same directory as this script.
                Returns a path relative to the current directory, or None.
                """
                path = os.path.join(os.path.dirname(sys.argv[0]), name)
                if not os.path.isfile(path):
                    path = os.path.join(os.path.dirname(__file__),
                                        os.path.pardir, name)
                    if not os.path.isfile(path):
                        return None

                if os.path.dirname(path) in os.environ['PATH'].split(
                        os.pathsep):
                    # in PATH, just use command name
                    return os.path.basename(path)

                path = os.path.relpath(path)
                if path == name:
                    path = './' + path  # for easier copy and paste into a shell
                return path

            tableGeneratorPath = _find_file_relative('table-generator.py') \
                              or _find_file_relative('table-generator')
            if tableGeneratorPath:
                xml_file_names = [
                    file + ".bz2" for file in self.xml_file_names
                ] if self.compress_results else self.xml_file_names
                util.printOut(
                    "In order to get HTML and CSV tables, run\n{0} '{1}'".
                    format(tableGeneratorPath, "' '".join(xml_file_names)))

        if isStoppedByInterrupt:
            util.printOut(
                "\nScript was interrupted by user, some runs may not be done.\n"
            )
Esempio n. 18
0
    def output_for_skipping_run_set(self, runSet, reason=None):
        """
        This function writes a simple message to terminal and logfile,
        when a run set is skipped.
        There is no message about skipping a run set in the xml-file.
        """

        # print to terminal
        util.printOut("\nSkipping run set" +
                      (" '" + runSet.name + "'" if runSet.name else "") +
                      (" " + reason if reason else ""))

        # write into txt_file
        runSetInfo = "\n\n"
        if runSet.name:
            runSetInfo += runSet.name + "\n"
        runSetInfo += (
            f"Run set {runSet.index} of {len(self.benchmark.run_sets)}: "
            f"skipped {reason or ''}".rstrip())
        runSetInfo += "\n"
        self.txt_file.append(runSetInfo)
Esempio n. 19
0
    def print_to_terminal(self):
        correct = self.dic[result.CATEGORY_CORRECT]
        correct_true = self.dic[(result.CATEGORY_CORRECT, result.RESULT_CLASS_TRUE)]
        correct_false = correct - correct_true
        incorrect = self.dic[result.CATEGORY_WRONG]
        incorrect_true = self.dic[(result.CATEGORY_WRONG, result.RESULT_CLASS_TRUE)]
        incorrect_false = incorrect - incorrect_true

        width = 6
        output = ['',
                 'Statistics:' + str(self.counter).rjust(width + 9) + ' Files',
                 '  correct:          ' + str(correct).rjust(width),
                 '    correct true:   ' + str(correct_true).rjust(width),
                 '    correct false:  ' + str(correct_false).rjust(width),
                 '  incorrect:        ' + str(incorrect).rjust(width),
                 '    incorrect true: ' + str(incorrect_true).rjust(width),
                 '    incorrect false:' + str(incorrect_false).rjust(width),
                 '  unknown:          ' + str(self.dic[result.CATEGORY_UNKNOWN] + self.dic[result.CATEGORY_ERROR]).rjust(width),
                 ]
        if self.max_score:
            output.append(
                 '  Score:            ' + str(self.score).rjust(width) + ' (max: ' + str(self.max_score) + ')'
                 )
        util.printOut('\n'.join(output)+'\n')
Esempio n. 20
0
    def output_after_benchmark(self, isStoppedByInterrupt):
        stats = str(self.statistics)
        util.printOut(stats)
        self.txt_file.append(stats)

        if self.xml_file_names:

            def _find_file_relative(name):
                """
                Find a file with the given name in the same directory as this script.
                Returns a path relative to the current directory, or None.
                """
                main_dir = os.path.dirname(sys.argv[0])
                search_dirs = [
                    main_dir,
                    os.path.join(main_dir, os.path.pardir, "bin"),
                    os.path.join(os.path.dirname(__file__), os.path.pardir),
                ]
                path = util.find_executable2(name, search_dirs)

                if not path:
                    return None

                if os.path.dirname(path) in util.get_path():
                    # in PATH, just use command name
                    return os.path.basename(path)

                path = os.path.relpath(path)
                if path == name:
                    path = "./" + path  # for easier copy and paste into a shell
                return path

            tableGeneratorPath = _find_file_relative(
                "table-generator.py") or _find_file_relative("table-generator")
            if tableGeneratorPath:
                xml_file_names = ([
                    file + ".bz2" for file in self.xml_file_names
                ] if self.compress_results else self.xml_file_names)
                cmdline = [tableGeneratorPath] + xml_file_names
                util.printOut(
                    "In order to get HTML and CSV tables, run\n" +
                    " ".join(map(util.escape_string_shell, cmdline)), )

        if isStoppedByInterrupt:
            util.printOut(
                "\nScript was interrupted by user, some runs may not be done.\n"
            )
Esempio n. 21
0
    def output_after_run(self, run):
        """
        The method output_after_run() prints filename, result, time and status
        of a run to terminal and stores all data in XML
        """

        # format times, type is changed from float to string!
        cputime_str = util.format_number(run.values.get("cputime"),
                                         TIME_PRECISION)
        walltime_str = util.format_number(run.values.get("walltime"),
                                          TIME_PRECISION)

        # format numbers, number_of_digits is optional, so it can be None
        for column in run.columns:
            if column.number_of_digits is not None:

                # if the number ends with "s" or another letter, remove it
                if (not column.value.isdigit()
                    ) and column.value[-2:-1].isdigit():
                    column.value = column.value[:-1]

                try:
                    floatValue = float(column.value)
                    column.value = util.format_number(floatValue,
                                                      column.number_of_digits)
                except ValueError:  # if value is no float, don't format it
                    pass

        # store information in run
        run.resultline = self.create_output_line(
            run.runSet,
            run.identifier,
            run.status,
            cputime_str,
            walltime_str,
            run.values.get("host"),
            run.columns,
        )
        self.add_values_to_run_xml(run)

        # output in terminal/console
        statusStr = COLOR_DIC[run.category].format(
            run.status.ljust(LEN_OF_STATUS))

        try:
            OutputHandler.print_lock.acquire()

            valueStr = statusStr + cputime_str.rjust(8) + walltime_str.rjust(8)
            if self.benchmark.num_of_threads == 1:
                util.printOut(valueStr)
            else:
                timeStr = time.strftime("%H:%M:%S",
                                        time.localtime()) + " " * 14
                util.printOut(
                    timeStr +
                    self.format_sourcefile_name(run.identifier, run.runSet) +
                    valueStr)

            # write result in txt_file and XML
            self.txt_file.append(run.resultline + "\n", keep=False)
            self.statistics.add_result(run)

            # we don't want to write this file to often, it can slow down the whole script,
            # so we wait at least 10 seconds between two write-actions
            currentTime = time.monotonic()
            if currentTime - run.runSet.xml_file_last_modified_time > 60:
                self._write_rough_result_xml_to_file(run.runSet.xml,
                                                     run.runSet.xml_file_name)
                run.runSet.xml_file_last_modified_time = time.monotonic()

        finally:
            OutputHandler.print_lock.release()

        if self.compress_results:
            log_file_path = os.path.relpath(
                run.log_file, os.path.join(self.benchmark.log_folder,
                                           os.pardir))
            with self.log_zip_lock:
                self.log_zip.write(run.log_file, log_file_path)
            os.remove(run.log_file)
        else:
            self.all_created_files.add(run.log_file)

        if os.path.isdir(run.result_files_folder):
            self.all_created_files.add(run.result_files_folder)
Esempio n. 22
0
    def output_after_run(self, run):
        """
        The method output_after_run() prints filename, result, time and status
        of a run to terminal and stores all data in XML
        """

        # format times, type is changed from float to string!
        cputime_str = util.format_number(run.cputime, TIME_PRECISION)
        walltime_str = util.format_number(run.walltime, TIME_PRECISION)

        # format numbers, number_of_digits is optional, so it can be None
        for column in run.columns:
            if column.number_of_digits is not None:

                # if the number ends with "s" or another letter, remove it
                if (not column.value.isdigit()
                    ) and column.value[-2:-1].isdigit():
                    column.value = column.value[:-1]

                try:
                    floatValue = float(column.value)
                    column.value = util.format_number(floatValue,
                                                      column.number_of_digits)
                except ValueError:  # if value is no float, don't format it
                    pass

        # store information in run
        run.resultline = self.create_output_line(run.runSet, run.identifier,
                                                 run.status, cputime_str,
                                                 walltime_str,
                                                 run.values.get('host'),
                                                 run.columns)
        self.add_values_to_run_xml(run)

        # output in terminal/console
        if USE_COLORS and sys.stdout.isatty():  # is terminal, not file
            statusStr = COLOR_DIC[run.category].format(
                run.status.ljust(LEN_OF_STATUS))
        else:
            statusStr = run.status.ljust(LEN_OF_STATUS)

        try:
            OutputHandler.print_lock.acquire()

            valueStr = statusStr + cputime_str.rjust(8) + walltime_str.rjust(8)
            if self.benchmark.num_of_threads == 1:
                util.printOut(valueStr)
            else:
                timeStr = time.strftime("%H:%M:%S",
                                        time.localtime()) + " " * 14
                util.printOut(
                    timeStr +
                    self.format_sourcefile_name(run.identifier, run.runSet) +
                    valueStr)

            # write result in txt_file and XML
            self.txt_file.append(self.run_set_to_text(run.runSet), False)
            self.statistics.add_result(run)

            # we don't want to write this file to often, it can slow down the whole script,
            # so we wait at least 10 seconds between two write-actions
            currentTime = util.read_monotonic_time()
            if currentTime - run.runSet.xml_file.lastModifiedTime > 60:
                run.runSet.xml_file.replace(
                    self._result_xml_to_string(run.runSet.xml))
                run.runSet.xml_file.lastModifiedTime = util.read_monotonic_time(
                )

        finally:
            OutputHandler.print_lock.release()
Esempio n. 23
0
    def output_before_run_set(self, runSet, start_time=None):
        """
        The method output_before_run_set() calculates the length of the
        first column for the output in terminal and stores information
        about the runSet in XML.
        @param runSet: current run set
        """
        xml_file_name = self.get_filename(runSet.name, "xml")

        identifier_names = [run.identifier for run in runSet.runs]

        # common prefix of file names
        runSet.common_prefix = util.common_base_dir(identifier_names)
        if runSet.common_prefix:
            runSet.common_prefix += os.path.sep

        # length of the first column in terminal
        runSet.max_length_of_filename = (max(
            len(file)
            for file in identifier_names) if identifier_names else 20)
        runSet.max_length_of_filename = max(
            20, runSet.max_length_of_filename - len(runSet.common_prefix))

        # write run set name to terminal
        numberOfFiles = len(runSet.runs)
        numberOfFilesStr = ("     (1 file)" if numberOfFiles == 1 else
                            f"     ({numberOfFiles} files)")
        util.printOut("\nexecuting run set" +
                      (" '" + runSet.name + "'" if runSet.name else "") +
                      numberOfFilesStr +
                      TERMINAL_TITLE.format(runSet.full_name))

        # write information about the run set into txt_file
        self.writeRunSetInfoToLog(runSet)

        # prepare information for text output
        for run in runSet.runs:
            run.resultline = self.format_sourcefile_name(
                run.identifier, runSet)

            if run.sourcefiles:
                adjusted_identifier = util.relative_path(
                    run.identifier, xml_file_name)
            else:
                # If no source files exist the task doesn't point to any file that could be downloaded.
                # In this case, the name doesn't have to be adjusted because it's no path.
                adjusted_identifier = run.identifier

            # prepare XML structure for each run and runSet
            run.xml = ElementTree.Element("run", name=adjusted_identifier)
            if run.sourcefiles:
                adjusted_sourcefiles = (util.relative_path(s, xml_file_name)
                                        for s in run.sourcefiles)
                run.xml.set("files",
                            "[" + ", ".join(adjusted_sourcefiles) + "]")
            if run.specific_options:
                run.xml.set("options", " ".join(run.specific_options))
            if run.properties:
                all_properties = (prop.name for prop in run.properties)
                run.xml.set("properties", " ".join(sorted(all_properties)))
            if len(run.properties) == 1:
                prop = run.properties[0]
                run.xml.set("propertyFile",
                            util.relative_path(prop.filename, xml_file_name))
                expected_result = str(
                    run.expected_results.get(prop.filename, ""))
                if expected_result:
                    run.xml.set("expectedVerdict", expected_result)

        block_name = runSet.blocks[0].name if len(runSet.blocks) == 1 else None
        runSet.xml = self.runs_to_xml(runSet, runSet.runs, block_name)
        if start_time:
            runSet.xml.set("starttime", start_time.isoformat())
        elif not self.benchmark.config.start_time:
            runSet.xml.set("starttime", util.read_local_time().isoformat())

        # write (empty) results to XML
        runSet.xml_file_name = xml_file_name
        self._write_rough_result_xml_to_file(runSet.xml, runSet.xml_file_name)
        runSet.xml_file_last_modified_time = time.monotonic()
        self.all_created_files.add(runSet.xml_file_name)
        self.xml_file_names.append(runSet.xml_file_name)
Esempio n. 24
0
    def output_before_run_set(self, runSet):
        """
        The method output_before_run_set() calculates the length of the
        first column for the output in terminal and stores information
        about the runSet in XML.
        @param runSet: current run set
        """
        xml_file_name = self.get_filename(runSet.name, "xml")

        identifier_names = [run.identifier for run in runSet.runs]

        # common prefix of file names
        runSet.common_prefix = util.common_base_dir(identifier_names)
        if runSet.common_prefix:
            runSet.common_prefix += os.path.sep

        # length of the first column in terminal
        runSet.max_length_of_filename = max(len(file) for file in identifier_names) if identifier_names else 20
        runSet.max_length_of_filename = max(20, runSet.max_length_of_filename - len(runSet.common_prefix))

        # write run set name to terminal
        numberOfFiles = len(runSet.runs)
        numberOfFilesStr = ("     (1 file)" if numberOfFiles == 1
                        else "     ({0} files)".format(numberOfFiles))
        util.printOut("\nexecuting run set"
            + (" '" + runSet.name + "'" if runSet.name else "")
            + numberOfFilesStr
            + TERMINAL_TITLE.format(runSet.full_name))

        # write information about the run set into txt_file
        self.writeRunSetInfoToLog(runSet)

        # prepare information for text output
        for run in runSet.runs:
            run.resultline = self.format_sourcefile_name(run.identifier, runSet)

            if run.sourcefiles:
                adjusted_identifier = util.relative_path(run.identifier, xml_file_name)
            else:
                # If no source files exist the task doesn't point to any file that could be downloaded.
                # In this case, the name doesn't have to be adjusted because it's no path.
                adjusted_identifier = run.identifier

        # prepare XML structure for each run and runSet
            run_attributes = {'name': adjusted_identifier}
            if run.sourcefiles:
                adjusted_sourcefiles = [util.relative_path(s, xml_file_name) for s in run.sourcefiles]
                run_attributes['files'] = '[' + ', '.join(adjusted_sourcefiles) + ']'
            run.xml = ET.Element("run", run_attributes)
            if run.specific_options:
                run.xml.set("options", " ".join(run.specific_options))
            if run.properties:
                all_properties = [prop_name for prop in run.properties for prop_name in prop.names]
                run.xml.set("properties", " ".join(sorted(all_properties)))
            run.xml.extend(self.xml_dummy_elements)

        block_name = runSet.blocks[0].name if len(runSet.blocks) == 1 else None
        runSet.xml = self.runs_to_xml(runSet, runSet.runs, block_name)

        # write (empty) results to txt_file and XML
        self.txt_file.append(self.run_set_to_text(runSet), False)
        runSet.xml_file_name = xml_file_name
        self._write_rough_result_xml_to_file(runSet.xml, runSet.xml_file_name)
        runSet.xml_file_last_modified_time = util.read_monotonic_time()
        self.all_created_files.add(runSet.xml_file_name)
        self.xml_file_names.append(runSet.xml_file_name)