示例#1
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)
示例#2
0
    def write_header_to_log(self, version, memlimit, timelimit, corelimit,
                            sysinfo):
        """
        This method writes information about benchmark and system into txt_file.
        """

        columnWidth = 20
        simpleLine = "-" * (60) + "\n\n"

        header = "   BENCHMARK INFORMATION\n"\
                + "benchmark:".ljust(columnWidth) + self.benchmark.name + "\n"\
                + "date:".ljust(columnWidth) +  time.strftime("%a, %Y-%m-%d %H:%M:%S %Z", self.benchmark.start_time) + "\n"\
                + "tool:".ljust(columnWidth) + self.benchmark.tool_name\
                + " " + version + "\n"

        if memlimit:
            header += "memlimit:".ljust(columnWidth) + str(
                memlimit / _BYTE_FACTOR / _BYTE_FACTOR) + " MB\n"
        if timelimit:
            header += "timelimit:".ljust(columnWidth) + timelimit + "\n"
        if corelimit:
            header += "CPU cores used:".ljust(columnWidth) + corelimit + "\n"
        header += simpleLine

        if sysinfo:
            header += "   SYSTEM INFORMATION\n"\
                    + "host:".ljust(columnWidth) + sysinfo.hostname + "\n"\
                    + "os:".ljust(columnWidth) + sysinfo.os + "\n"\
                    + "cpu:".ljust(columnWidth) + sysinfo.cpu_model + "\n"\
                    + "- cores:".ljust(columnWidth) + sysinfo.cpu_number_of_cores + "\n"\
                    + "- max frequency:".ljust(columnWidth) + str(sysinfo.cpu_max_frequency/1000/1000) + " MHz\n"\
                    + "ram:".ljust(columnWidth) + str(sysinfo.memory/_BYTE_FACTOR/_BYTE_FACTOR) + " MB\n"\
                    + simpleLine

        self.description = header

        runSetName = None
        run_sets = [
            runSet for runSet in self.benchmark.run_sets
            if runSet.should_be_executed()
        ]
        if len(run_sets) == 1:
            # in case there is only a single run set to to execute, we can use its name
            runSetName = run_sets[0].name

        # write to file
        txt_file_name = self.get_filename(runSetName, "txt")
        self.txt_file = filewriter.FileWriter(txt_file_name, self.description)
        self.all_created_files.add(txt_file_name)
示例#3
0
    def write_header_to_log(self, sysinfo):
        """
        This method writes information about benchmark and system into txt_file.
        """
        runSetName = None
        run_sets = [
            runSet for runSet in self.benchmark.run_sets
            if runSet.should_be_executed()
        ]
        if len(run_sets) == 1:
            # in case there is only a single run set to to execute, we can use its name
            runSetName = run_sets[0].name

        columnWidth = 25
        simpleLine = "-" * 60 + "\n\n"

        def format_line(key, value):
            if value is None:
                return ""
            return ((key + ":").ljust(columnWidth) + str(value)).strip() + "\n"

        def format_byte(key, value):
            if value is None:
                return ""
            return format_line(
                key,
                str(value / _BYTE_FACTOR / _BYTE_FACTOR) + " MB")

        def format_time(key, value):
            if value is None:
                return ""
            return format_line(key, str(value) + " s")

        header = (
            "   BENCHMARK INFORMATION\n" +
            ((self.benchmark.display_name +
              "\n") if self.benchmark.display_name else "") + format_line(
                  "benchmark definition", self.benchmark.benchmark_file) +
            format_line("name", self.benchmark.name) +
            format_line("run sets", ", ".join(run_set.name
                                              for run_set in run_sets)) +
            format_line(
                "date",
                self.benchmark.start_time.strftime("%a, %Y-%m-%d %H:%M:%S %Z"))
            + format_line(
                "tool",
                self.benchmark.tool_name + " " + self.benchmark.tool_version) +
            format_line("tool executable", self.benchmark.executable) +
            format_line(
                "options",
                " ".join(map(util.escape_string_shell,
                             self.benchmark.options)),
            ) + format_line("property file",
                            util.text_or_none(self.benchmark.propertytag)))
        if self.benchmark.num_of_threads > 1:
            header += format_line("parallel runs",
                                  self.benchmark.num_of_threads)

        header += (
            "resource limits:\n" +
            format_byte("- memory", self.benchmark.rlimits.memory) +
            format_time("- time", self.benchmark.rlimits.cputime) +
            format_line("- cpu cores", self.benchmark.rlimits.cpu_cores))

        header += (
            "hardware requirements:\n" +
            format_line("- cpu model", self.benchmark.requirements.cpu_model) +
            format_line("- cpu cores", self.benchmark.requirements.cpu_cores) +
            format_byte("- memory", self.benchmark.requirements.memory) +
            simpleLine)

        if sysinfo:
            header += (
                "   SYSTEM INFORMATION\n" +
                format_line("host", sysinfo.hostname) +
                format_line("os", sysinfo.os) +
                format_line("cpu", sysinfo.cpu_model) +
                format_line("- cores", sysinfo.cpu_number_of_cores) +
                format_line(
                    "- max frequency",
                    str(sysinfo.cpu_max_frequency / 1000 / 1000) + " MHz",
                ) +
                format_line("- turbo boost enabled", sysinfo.cpu_turboboost) +
                format_byte("ram", sysinfo.memory) + simpleLine)

        self.description = header

        # write to file
        txt_file_name = self.get_filename(runSetName, "txt")
        self.txt_file = filewriter.FileWriter(txt_file_name, self.description)
        self.all_created_files.add(txt_file_name)