How to use temci - 10 common examples

To help you get started, we’ve selected a few temci examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github parttimenerd / temci / temci / report / report.py View on Github external
print_func("""\t{d}:\n\t\t{m}""".format(d=run.description(), m="\n\t\t".join(str(run.recorded_error).split("\n"))))


@register(ReporterRegistry, "html", Dict(unknown_keys=True) // Default({}) // Description("Deprecated setting"),
          deprecated=True)
class HTMLReporter(AbstractReporter):
    """
    Deprecated reporter that just lives as a hull.
    It might be useful to revive it as a basic reporter without JavaScript.
    """

    def report(self):
        raise NotImplementedError("The html reporter is broken. Consider using the html2 reporter.")


@register(ReporterRegistry, "html2", Dict({
    "out": Str() // Default("report") // Description("Output directory"),
    "html_filename": Str() // Default("report.html") // Description("Name of the HTML file"),
    "fig_width_small": Float() // Default(15.0) // Description("Width of all small plotted figures"),
    "fig_width_big": Float() // Default(25.0) // Description("Width of all big plotted figures"),
    "boxplot_height": Float() // Default(2.0) // Description("Height per run block for the big comparison box plots"),
    "alpha": Float() // Default(0.05) // Description("Alpha value for confidence intervals"),
    "gen_tex": Bool() // Default(True) // Description("Generate simple latex versions of the plotted figures?"),
    "gen_pdf": Bool() // Default(False) // Description("Generate pdf versions of the plotted figures?"),
    "gen_xls": Bool() // Default(False) // Description("Generate excel files for all tables"),
    "show_zoomed_out": Bool() // Default(False)
                       // Description("Show zoomed out (x min = 0) figures in the extended summaries?"),
    "percent_format": Str() // Default("{:5.2%}") // Description("Format string used to format floats as percentages"),
    "float_format": Str() // Default("{:5.2e}") // Description("Format string used to format floats"),
    "min_in_comparison_tables": Bool() // Default(False)
                                // Description("Show the mininmum related values in the big comparison table"),
    "mean_in_comparison_tables": Bool() // Default(True)
github parttimenerd / temci / temci / run / run_driver_plugin.py View on Github external
"m = np.random.randint(0, 100, (500, 500)); " \
              "print(list(map(lambda x: len(np.linalg.eig(m)), range(10000))))' > /dev/null".format(heat_time)
        cmds = []
        for i in range(1, multiprocessing.cpu_count()):
            cmds.append(cmd + "& > /dev/null")
        cmds.append(cmd)
        return ";".join(cmds)


@register(ExecRunDriver, "other_nice", Dict({
    "nice": Int(range=range(-20, 20)) // Description("Niceness values for other processes.")
                                      // Default(19),
    "min_nice": Int(range=range(-15, 20)) // Default(-10)
                // Description("Processes with lower nice values are ignored.")
}))
class OtherNicePlugin(AbstractRunDriverPlugin):
    """
    Allows the setting of the nice value of most other processes (as far as possible).
    """

    def __init__(self, misc_settings):
        super().__init__(misc_settings)
        self._old_nices = {}

    def setup(self):
        for line in self._exec_command("/bin/ps --noheaders -e -o pid,nice").split("\n"):
            line = line.strip()
            arr = list(filter(lambda x: len(x) > 0, line.split(" ")))
            if len(arr) == 0:
                continue
            pid = int(arr[0].strip())
            nice = arr[1].strip()
github parttimenerd / temci / temci / run / run_driver_plugin.py View on Github external
"min_nice": Int(range=range(-15, 20)) // Default(-10)
                // Description("Processes with lower nice values are ignored."),
    "min_id": PositiveInt() // Default(1500)
                // Description("Processes with lower id are ignored."),
    "comm_prefixes": ListOrTuple(Str()) // Default(["ssh", "xorg", "bluetoothd"])
                // Description("Each process which name (lower cased) starts with one of the prefixes is not ignored. "
                               "Overrides the decision based on the min_id."),
    "comm_prefixes_ignored": ListOrTuple(Str()) // Default(["dbus", "kworker"])
                // Description("Each process which name (lower cased) starts with one of the prefixes is ignored. "
                               "It overrides the decisions based on comm_prefixes and min_id."),
    "subtree_suffixes": ListOrTuple(Str()) // Default(["dm", "apache"])
                        // Description("Suffixes of processes names which are stopped."),
    "dry_run": Bool() // Default(False)
               // Description("Just output the to be stopped processes but don't actually stop them?")
}))
class StopStartPlugin(AbstractRunDriverPlugin):
    """
    Stop almost all other processes (as far as possible).
    """

    def __init__(self, misc_settings):
        super().__init__(misc_settings)
        self._processes = {}  # type: t.Dict[str, t.Union[str, int]]
        self._pids = []  # type: t.List[int]

    def parse_processes(self):
        self._processes = {}
        for line in self._exec_command("/bin/ps --noheaders -e -o pid,nice,comm,cmd,ppid").split("\n"):
            line = line.strip()
            arr = list(map(lambda x: x.strip(), filter(lambda x: len(x) > 0, line.split(" "))))
            if len(arr) == 0:
                continue
github parttimenerd / temci / temci / run / run_driver_plugin.py View on Github external
def setup(self):
        self._set_nice(self.misc_settings["nice"])
        self._set_io_nice(self.misc_settings["io_nice"])

    def _set_nice(self, nice: int):
        self._exec_command("renice -n {} -p {}".format(nice, os.getpid()))

    def _set_io_nice(self, nice: int):
        self._exec_command("ionice -n {} -p {}".format(nice, os.getpid()))

    def teardown(self):
        self._set_nice(self._old_nice)
        self._set_io_nice(self._old_io_nice)


@register(ExecRunDriver, "env_randomize", Dict({
    "min": NaturalNumber() // Default(4) // Description("Minimum number of added random environment variables"),
    "max": PositiveInt() // Default(4) // Description("Maximum number of added random environment variables"),
    "var_max": PositiveInt() // Default(get_memory_page_size()) // Description("Maximum length of each random value"),
    "key_max": PositiveInt() // Default(get_memory_page_size()) // Description("Maximum length of each random key")
}))
class EnvRandomizePlugin(AbstractRunDriverPlugin):
    """
    Adds random environment variables.
    """

    def setup_block_run(self, block: RunProgramBlock, runs: int = 1):
        env = {}
        for i in range(random.randint(self.misc_settings["min"], self.misc_settings["max"] + 1)):
            env["a" * random.randint(0, self.misc_settings["key_max"])] \
                = "a" * random.randint(0, self.misc_settings["var_max"])
        block["env"] = env
github parttimenerd / temci / temci / run / run_driver_plugin.py View on Github external
"""
        pass

    def _exec_command(self, cmd: str) -> str:
        proc = subprocess.Popen(["/bin/sh", "-c", cmd], stdout=subprocess.PIPE,
                                stderr=subprocess.PIPE,
                                universal_newlines=True)
        out, err = proc.communicate()
        if proc.poll() > 0:
            msg = "Error executing '" + cmd + "' in {}: ".format(type(self)) + str(err) + " " + str(out)
            #logging.error(msg)
            raise EnvironmentError(msg)
        return str(out)


@register(ExecRunDriver, "nice", Dict({
    "nice": Int(range=range(-20, 20)) // Description("Niceness values range from -20 (most favorable "
                                                     "to the process) to 19 (least favorable to the process).")
                                      // Default(-15),
    "io_nice": Int(range=range(0, 4)) // Description("Specify the name or number of the scheduling class to use;"
                                                     "0 for none, 1 for realtime, 2 for best-effort, 3 for idle.")
                                      // Default(1)
}))
class NicePlugin(AbstractRunDriverPlugin):
    """
    Allows the setting of the nice and ionice values of the benchmarking process.
    """

    needs_root_privileges = True

    def __init__(self, misc_settings):
        super().__init__(misc_settings)
github parttimenerd / temci / temci / report / report.py View on Github external
"max": lambda single: single.max(),
            "stddev per mean": lambda single: single.std_dev_per_mean()
        }
        num = mod[modifier](single)
        if baseline:
            num = num / baseline.mean()
        return FNumber(num,
                       abs_deviation=single.std_dev(),
                       is_percent=("%" in opts),
                       scientific_notation=("s" in opts),
                       parentheses=("o" in opts or "p" in opts),
                       parentheses_mode=ParenthesesMode.DIGIT_CHANGE if "p" in opts else \
                                        (ParenthesesMode.ORDER_OF_MAGNITUDE if "o" in opts else None)).format()


@register(ReporterRegistry, "codespeed", Dict({
    "project": Str() // Default("") // Description("Project name reported to codespeed."),
    "executable": Str() // Default("") // Description("Executable name reported to codespeed. Defaults to the project name."),
    "environment": Str() // Default("") // Description("Environment name reported to codespeed. Defaults to current host name."),
    "branch": Str() // Default("") // Description("Branch name reported to codespeed. Defaults to current branch or else 'master'."),
    "commit_id": Str() // Default("") // Description("Commit ID reported to codespeed. Defaults to current commit."),
}))
class CodespeedReporter(AbstractReporter):
    """
    Reporter that outputs JSON as expected by `codespeed <https://github.com/tobami/codespeed>`_.
    Branch name and commit ID are taken from the current directory.
    Use it like this:

    .. code:: sh

        temci report --reporter codespeed ... | curl --data-urlencode json@- http://localhost:8000/result/add/json/
github parttimenerd / temci / temci / run / run_driver_plugin.py View on Github external
#logging.info(err)
                    pass

    def _set_nice(self, pid: int, nice: int):
        self._exec_command("renice -n {} -p {}".format(nice, pid))

    def teardown(self):
        for pid in self._old_nices:
            try:
                self._set_nice(pid, self._old_nices[pid])
            except EnvironmentError as err:
                #logging.info(err)
                pass


@register(ExecRunDriver, "stop_start", Dict({
    "min_nice": Int(range=range(-15, 20)) // Default(-10)
                // Description("Processes with lower nice values are ignored."),
    "min_id": PositiveInt() // Default(1500)
                // Description("Processes with lower id are ignored."),
    "comm_prefixes": ListOrTuple(Str()) // Default(["ssh", "xorg", "bluetoothd"])
                // Description("Each process which name (lower cased) starts with one of the prefixes is not ignored. "
                               "Overrides the decision based on the min_id."),
    "comm_prefixes_ignored": ListOrTuple(Str()) // Default(["dbus", "kworker"])
                // Description("Each process which name (lower cased) starts with one of the prefixes is ignored. "
                               "It overrides the decisions based on comm_prefixes and min_id."),
    "subtree_suffixes": ListOrTuple(Str()) // Default(["dm", "apache"])
                        // Description("Suffixes of processes names which are stopped."),
    "dry_run": Bool() // Default(False)
               // Description("Just output the to be stopped processes but don't actually stop them?")
}))
class StopStartPlugin(AbstractRunDriverPlugin):
github parttimenerd / temci / temci / report / report.py View on Github external
def _is_valid_csv_reporter_spec_list(specs: t.List[str]) -> bool:
    try:
        _parse_csv_reporter_specs(specs)
    except SyntaxError as err:
        return False
    return True

@register(ReporterRegistry, "csv", Dict({
    "out": FileNameOrStdOut() // Default("-") // Description("Output file name or standard out (-)"),
    "columns": ListOrTuple(Str()) // (lambda x: _is_valid_csv_reporter_spec_list(x))
               // Description("List of valid column specs, format is a comma separated list of 'PROPERTY\\[mod\\]' or 'ATTRIBUTE' "
                              "mod is one of: {}, optionally a formatting option can be given via"
                              "PROPERTY\\[mod|OPT1OPT2…\\], where the OPTs are one of the following: {}. "
                              "PROPERTY can be either the description or the short version of the property. "
                              "Configure the number formatting further via the number settings in the settings file"
                              .format(join_strs(valid_csv_reporter_modifiers),
                                      join_strs("{} ({})".format(k, v) for k, v in FORMAT_OPTIONS.items())))
    // Default(["description"])
}))
class CSVReporter(AbstractReporter):
    """
    Simple reporter that outputs just a configurable csv table with rows for each run block
    """

    def report(self) -> t.Optional[str]:
        """
        Create an report and output it as configured.

        :return: the report string if ``to_string == True``
        """
        if not self.misc["out"] == "-" and not os.path.exists(os.path.dirname(self.misc["out"])):
            logging.error("Folder for report ({}) doesn't exist".format(os.path.dirname(self.misc["out"])))
github parttimenerd / temci / temci / run / run_driver_plugin.py View on Github external
self._send_signal(signal.SIGSTOP)

    def _send_signal(self, signal: int):
        for pid in self._pids:
            try:
                os.kill(pid, signal)
            except BaseException as ex:
                #logging.info(ex)
                pass

    def teardown(self):
        self._send_signal(signal.SIGCONT)


@register(ExecRunDriver, "sync", Dict({}))
class SyncPlugin(AbstractRunDriverPlugin):
    """
    Calls ``sync`` before each program execution.
    """

    def setup_block_run(self, block: RunProgramBlock, runs: int = 1):
        block["cmd_prefix"].append("sync")


@register(ExecRunDriver, "sleep", Dict({
    "seconds": PositiveInt() // Default(10) // Description("Seconds to sleep")
}))
class SleepPlugin(AbstractRunDriverPlugin):
    """
    Sleep a given amount of time before the benchmarking begins.

    See Gernot Heisers Systems Benchmarking Crimes:
github parttimenerd / temci / temci / run / run_driver_plugin.py View on Github external
"free_dentries_inodes": Bool() // Default(True) // Description("Free dentries and inodes")
}))
class DropFSCaches(AbstractRunDriverPlugin):
    """
    Drop page cache, directoy entries and inodes before every benchmarking run.
    """

    needs_root_privileges = True

    def setup_block(self, block: RunProgramBlock, runs: int = 1):
        num = self.misc_settings["free_pagecache"] + 2 * self.misc_settings["free_dentries_inodes"]
        block["cmd_prefix"].append("sync; echo {} > /proc/sys/vm/drop_caches".format(num))


@register(ExecRunDriver, "disable_swap", Dict({}))
class DisableSwap(AbstractRunDriverPlugin):
    """
    Disables swapping on the system before the benchmarking and enables it after.
    """

    needs_root_privileges = True

    def setup(self):
        self._exec_command("swapoff -a")

    def teardown(self):
        self._exec_command("swapon -a")


@register(ExecRunDriver, "disable_cpu_caches", Dict({}))
class DisableCPUCaches(AbstractRunDriverPlugin):
    """