make_postexec_message.py 文件源码

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

项目:anglerfish 作者: juancarlospaco 项目源码 文件源码
def make_post_exec_msg(start_time: datetime=None, comment: str=None) -> str:
    """Build Post-Execution Message with information about RAM and Time."""
    use, al, msg = 0, 0, ""
    if sys.platform.startswith(("win", "darwin")):
        msg = "No information about RAM usage available on non-Linux systems."
    elif sys.platform.startswith("linux"):
        use = int(resource.getrusage(resource.RUSAGE_SELF).ru_maxrss *
                  resource.getpagesize() if resource else 0)
        al = int(os.sysconf('SC_PAGE_SIZE') * os.sysconf('SC_PHYS_PAGES')
                 if hasattr(os, "sysconf") else 0)
        msg += f"""Total Max Memory Used: ~{use / al:.2%} Percent.
            { bytes2human(use) } ({ use } bytes) of
            { bytes2human(al) } ({ al } bytes) of total RAM Memory.\n"""
        if start_time:
            _t = datetime.now() - start_time
            msg += f"Total Working Time: ~{ timedelta2human(_t) } ({ _t }).\n"
    if comment:
        msg += str(comment).strip()
    log.debug("Preparing Simple Post-Execution Messages.")
    atexit.register(log.info, msg)
    return msg
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号