用法:
resource.getrusage(who)此函数返回一个对象,该对象说明当前进程或其子进程消耗的资源,由
who参数指定。who参数应该使用下面说明的RUSAGE_*常量之一来指定。一个简单的例子:
from resource import * import time # a non CPU-bound task time.sleep(3) print(getrusage(RUSAGE_SELF)) # a CPU-bound task for i in range(10 ** 8): _ = 1 + 1 print(getrusage(RUSAGE_SELF))返回值的每个字段都说明了特定系统资源的使用方式,例如运行所花费的时间是用户模式或进程从主内存换出的次数。一些值取决于内部时钟滴答,例如进程正在使用的内存量。
为了向后兼容,返回值也可以作为 16 个元素的元组访问。
返回值的字段
ru_utime和ru_stime是浮点值,分别表示在用户模式下执行的时间和在系统模式下执行的时间。其余值是整数。有关这些值的详细信息,请参阅getrusage(2)手册页。这里提供一个简短的摘要:index
场地
资源
0ru_utime用户模式下的时间(浮点秒)
1ru_stime系统模式下的时间(浮点数)
2ru_maxrss最大驻留集大小
3ru_ixrss共享内存大小
4ru_idrss非共享内存大小
5ru_isrss非共享堆栈大小
6ru_minflt不需要 I/O 的页面错误
7ru_majflt需要 I/O 的页面错误
8ru_nswap换出次数
9ru_inblock块输入操作
10ru_oublock块输出操作
11ru_msgsnd发送的消息
12ru_msgrcv收到的消息
13ru_nsignals接收到的信号
14ru_nvcsw自愿上下文切换
15ru_nivcsw无意识的上下文切换
如果指定了无效的
who参数,此函数将引发ValueError。它还可能在异常情况下引发error异常。
相关用法
- Python response.status_code用法及代码示例
- Python response.elapsed用法及代码示例
- Python response.cookies用法及代码示例
- Python response.ok用法及代码示例
- Python response.text用法及代码示例
- Python response.request用法及代码示例
- Python response.history用法及代码示例
- Python response.links用法及代码示例
- Python response.reason用法及代码示例
- Python response.headers用法及代码示例
- Python response.close()用法及代码示例
- Python response.is_permanent_redirect用法及代码示例
- Python Tkinter resizable()用法及代码示例
- Python response.raise_for_status()用法及代码示例
- Python OpenCV resizeWindow()用法及代码示例
- Python response.content用法及代码示例
- Python response.encoding用法及代码示例
- Python response.url用法及代码示例
- Python response.json()用法及代码示例
- Python response.is_redirect用法及代码示例
注:本文由纯净天空筛选整理自python.org大神的英文原创作品 resource.getrusage。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
