本文整理汇总了Python中psutil.Process.cpu_times方法的典型用法代码示例。如果您正苦于以下问题:Python Process.cpu_times方法的具体用法?Python Process.cpu_times怎么用?Python Process.cpu_times使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类psutil.Process
的用法示例。
在下文中一共展示了Process.cpu_times方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __enter__
# 需要导入模块: from psutil import Process [as 别名]
# 或者: from psutil.Process import cpu_times [as 别名]
def __enter__(self):
cput = P.cpu_times()
memi = P.memory_info_ex()
self.start_sys = cput.system
self.start_user = cput.user
self.start_rss = memi.rss
self.start_disk = get_wdb() + get_ldb()
示例2: __exit__
# 需要导入模块: from psutil import Process [as 别名]
# 或者: from psutil.Process import cpu_times [as 别名]
def __exit__(self, *args):
cput = P.cpu_times()
memi = P.memory_info_ex()
self.stop_sys = cput.system
self.stop_user = cput.user
self.stop_rss = memi.rss
self.stop_disk = get_wdb() + get_ldb()
t_elapsed_sys = self.stop_sys - self.start_sys
t_elapsed_user = self.stop_user - self.start_user
t_elapsed = t_elapsed_sys + t_elapsed_user
print >>sys.stderr, blessings.Terminal().yellow('timer: {} took {} (user: {}, sys: {}) seconds.'.format(self.name, t_elapsed, t_elapsed_user, t_elapsed_sys))
print >>sys.stderr, blessings.Terminal().yellow('timer: rss = {} MiB. (change: {} MiB).'.format(self.stop_rss/1048576.0, (self.stop_rss-self.start_rss)/1048576.0))
print >>sys.stderr, blessings.Terminal().yellow('timer: disk = {} MiB. (change: {} MiB).'.format(self.stop_disk/1048576.0, (self.stop_disk-self.start_disk)/1048576.0))
print >>sys.stderr
stats[self.name+'.Memory'] = self.stop_rss + self.stop_disk
stats[self.name+'.Runtime'] = t_elapsed