Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
蜕变的菜鸟
glances
提交
76184da1
G
glances
项目概览
蜕变的菜鸟
/
glances
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
glances
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
76184da1
编写于
12月 05, 2012
作者:
N
Nicolas Hennion
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactor CPU and LOAD stats graber
上级
da2d2b45
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
38 addition
and
66 deletion
+38
-66
glances/glances.py
glances/glances.py
+38
-66
未找到文件。
glances/glances.py
浏览文件 @
76184da1
...
...
@@ -625,36 +625,23 @@ class GlancesStats:
"""
# CPU
cputime
=
psutil
.
cpu_times
()
cputime_total
=
(
cputime
.
user
+
cputime
.
system
+
cputime
.
idle
)
# Only available on some OS
if
hasattr
(
cputime
,
'nice'
):
cputime_total
+=
cputime
.
nice
if
hasattr
(
cputime
,
'iowait'
):
cputime_total
+=
cputime
.
iowait
if
hasattr
(
cputime
,
'irq'
):
cputime_total
+=
cputime
.
irq
if
hasattr
(
cputime
,
'softirq'
):
cputime_total
+=
cputime
.
softirq
if
not
hasattr
(
self
,
'cputime_old'
):
self
.
cputime_old
=
psutil
.
cpu_times
()
self
.
cputime_total_old
=
(
self
.
cputime_old
.
user
+
self
.
cputime_old
.
system
+
self
.
cputime_old
.
idle
)
# Only available on some OS
if
hasattr
(
self
.
cputime_old
,
'nice'
):
self
.
cputime_total_old
+=
self
.
cputime_old
.
nice
if
hasattr
(
self
.
cputime_old
,
'iowait'
):
self
.
cputime_total_old
+=
self
.
cputime_old
.
iowait
if
hasattr
(
self
.
cputime_old
,
'irq'
):
self
.
cputime_total_old
+=
self
.
cputime_old
.
irq
if
hasattr
(
self
.
cputime_old
,
'softirq'
):
self
.
cputime_total_old
+=
self
.
cputime_old
.
softirq
self
.
cputime_old
=
cputime
self
.
cputime_total_old
=
cputime_total
self
.
cpu
=
{}
else
:
self
.
cputime_new
=
cputime
self
.
cputime_total_new
=
cputime_total
try
:
self
.
cputime_new
=
psutil
.
cpu_times
()
self
.
cputime_total_new
=
(
self
.
cputime_new
.
user
+
self
.
cputime_new
.
system
+
self
.
cputime_new
.
idle
)
# Only available on some OS
if
hasattr
(
self
.
cputime_new
,
'nice'
):
self
.
cputime_total_new
+=
self
.
cputime_new
.
nice
if
hasattr
(
self
.
cputime_new
,
'iowait'
):
self
.
cputime_total_new
+=
self
.
cputime_new
.
iowait
if
hasattr
(
self
.
cputime_new
,
'irq'
):
self
.
cputime_total_new
+=
self
.
cputime_new
.
irq
if
hasattr
(
self
.
cputime_new
,
'softirq'
):
self
.
cputime_total_new
+=
self
.
cputime_new
.
softirq
percent
=
100
/
(
self
.
cputime_total_new
-
self
.
cputime_total_old
)
self
.
cpu
=
{
'user'
:
(
self
.
cputime_new
.
user
-
...
...
@@ -678,50 +665,35 @@ class GlancesStats:
self
.
cpu
=
{}
# Per-CPU
percputime
=
psutil
.
cpu_times
(
percpu
=
True
)
percputime_total
=
[]
for
i
in
range
(
len
(
percputime
)):
percputime_total
.
append
(
percputime
[
i
].
user
+
percputime
[
i
].
system
+
percputime
[
i
].
idle
)
# Only available on some OS
for
i
in
range
(
len
(
percputime
)):
if
hasattr
(
percputime
[
i
],
'nice'
):
percputime_total
[
i
]
+=
percputime
[
i
].
nice
for
i
in
range
(
len
(
percputime
)):
if
hasattr
(
percputime
[
i
],
'iowait'
):
percputime_total
[
i
]
+=
percputime
[
i
].
iowait
for
i
in
range
(
len
(
percputime
)):
if
hasattr
(
percputime
[
i
],
'irq'
):
percputime_total
[
i
]
+=
percputime
[
i
].
irq
for
i
in
range
(
len
(
percputime
)):
if
hasattr
(
percputime
[
i
],
'softirq'
):
percputime_total
[
i
]
+=
percputime
[
i
].
softirq
if
not
hasattr
(
self
,
'percputime_old'
):
self
.
percputime_old
=
psutil
.
cpu_times
(
percpu
=
True
)
self
.
percputime_total_old
=
[]
for
i
in
range
(
len
(
self
.
percputime_old
)):
self
.
percputime_total_old
.
append
(
self
.
percputime_old
[
i
].
user
+
self
.
percputime_old
[
i
].
system
+
self
.
percputime_old
[
i
].
idle
)
# Only available on some OS
for
i
in
range
(
len
(
self
.
percputime_old
)):
if
hasattr
(
self
.
percputime_old
[
i
],
'nice'
):
self
.
percputime_total_old
[
i
]
+=
self
.
percputime_old
[
i
].
nice
for
i
in
range
(
len
(
self
.
percputime_old
)):
if
hasattr
(
self
.
percputime_old
[
i
],
'iowait'
):
self
.
percputime_total_old
[
i
]
+=
self
.
percputime_old
[
i
].
iowait
for
i
in
range
(
len
(
self
.
percputime_old
)):
if
hasattr
(
self
.
percputime_old
[
i
],
'irq'
):
self
.
percputime_total_old
[
i
]
+=
self
.
percputime_old
[
i
].
irq
for
i
in
range
(
len
(
self
.
percputime_old
)):
if
hasattr
(
self
.
percputime_old
[
i
],
'softirq'
):
self
.
percputime_total_old
[
i
]
+=
self
.
percputime_old
[
i
].
softirq
self
.
percputime_old
=
percputime
self
.
percputime_total_old
=
percputime_total
self
.
percpu
=
[]
else
:
self
.
percputime_new
=
percputime
self
.
percputime_total_new
=
percputime_total
perpercent
=
[]
self
.
percpu
=
[]
try
:
self
.
percputime_new
=
psutil
.
cpu_times
(
percpu
=
True
)
self
.
percputime_total_new
=
[]
for
i
in
range
(
len
(
self
.
percputime_new
)):
self
.
percputime_total_new
.
append
(
self
.
percputime_new
[
i
].
user
+
self
.
percputime_new
[
i
].
system
+
self
.
percputime_new
[
i
].
idle
)
# Only available on some OS
for
i
in
range
(
len
(
self
.
percputime_new
)):
if
hasattr
(
self
.
percputime_new
[
i
],
'nice'
):
self
.
percputime_total_new
[
i
]
+=
self
.
percputime_new
[
i
].
nice
for
i
in
range
(
len
(
self
.
percputime_new
)):
if
hasattr
(
self
.
percputime_new
[
i
],
'iowait'
):
self
.
percputime_total_new
[
i
]
+=
self
.
percputime_new
[
i
].
iowait
for
i
in
range
(
len
(
self
.
percputime_new
)):
if
hasattr
(
self
.
percputime_new
[
i
],
'irq'
):
self
.
percputime_total_new
[
i
]
+=
self
.
percputime_new
[
i
].
irq
for
i
in
range
(
len
(
self
.
percputime_new
)):
if
hasattr
(
self
.
percputime_new
[
i
],
'softirq'
):
self
.
percputime_total_new
[
i
]
+=
self
.
percputime_new
[
i
].
softirq
perpercent
=
[]
self
.
percpu
=
[]
for
i
in
range
(
len
(
self
.
percputime_new
)):
perpercent
.
append
(
100
/
(
self
.
percputime_total_new
[
i
]
-
self
.
percputime_total_old
[
i
]))
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录