init.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:temci 作者: parttimenerd 项目源码 文件源码
def prompt_perf_stat_exec_dict(run_dict: dict) -> dict:
    """
    Prompt for the config of the perf stat exec runner.

    :param run_dict: run config dict (without the runner part)
    :return: runner config
    """
    runner_dict = {}
    default_repeat = PerfStatExecRunner.misc_options["repeat"].get_default()
    runner_dict["repeat"] = int(default_prompt("How many times should perf stat itself repeat the measurement? ",
                                               default=default_repeat, validator=TypeValidator(PositiveInt())))
    default_props = ", ".join(PerfStatExecRunner.misc_options["properties"].get_default())

    class PerfStatPropertiesValidator(Validator):

        def validate(self, document: Document):
            vals = [elem.strip() for elem in document.text.split(",")]
            cmd = "perf stat -x ';' -e {props} -- /bin/echo".format(props=",".join(vals))
            proc = subprocess.Popen(["/bin/sh", "-c", cmd], stdout=subprocess.DEVNULL,
                                    stderr=subprocess.PIPE, universal_newlines=True)
            out, err = proc.communicate()
            if proc.poll() > 0:
                msg = str(err).split("\n")[0].strip()
                raise ValidationError(message=msg, cursor_position=len(document.text))

    props = prompt("Which properties should perf stat measure? ",
                   validator=PerfStatPropertiesValidator(), default=default_props,
                   completer=WordCompleter(sorted(list(set(get_av_perf_stat_properties()))), ignore_case=False, WORD=True))
    runner_dict["properties"] = [prop.strip() for prop in props.split(",")]
    return runner_dict
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号