stats.py 文件源码

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

项目:atsy 作者: EricRahm 项目源码 文件源码
def print_stats(self, verbose=False):
        """
        Prints out stats for each matched process and a sum of the RSS of the
        parent process and the USS of its children.

        :param verbose: Set true to see the full command-line. This is useful
         when deciding on a parent filter.
        """
        def wrapped_path_filter(x):
            try:
                return self.path_filter(x.exe())
            except (psutil.AccessDenied, psutil.ZombieProcess):
                return False

        parent_rss = 0
        children_uss = 0

        for p in filter(wrapped_path_filter, psutil.process_iter()):
            info = p.memory_full_info()
            rss = info.rss
            uss = info.uss
            cmdline = self.get_cmdline(p)
            exe = cmdline if verbose else p.exe()

            if self.parent_filter(cmdline):
                print "[%d] - %s\n  * RSS - %d\n    USS - %d" % (p.pid, exe, rss, uss)
                parent_rss += rss
            else:
                print "[%d] - %s\n    RSS - %d\n  * USS - %d" % (p.pid, exe, rss, uss)
                children_uss += uss

        if not parent_rss:
            if not children_uss:
                raise ProcessNotFoundException(
                    "No processes matched the path filter")
            else:
                raise ProcessNotFoundException(
                    "No process matched the parent filter")

        print "\nTotal: {:,} bytes\n".format(parent_rss + children_uss)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号