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)
评论列表
文章目录