Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
蜕变的菜鸟
glances
提交
77b3a888
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,发现更多精彩内容 >>
提交
77b3a888
编写于
8月 05, 2014
作者:
N
Nicolargo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactor sorting code
上级
a8092685
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
41 addition
and
24 deletion
+41
-24
glances/core/glances_logs.py
glances/core/glances_logs.py
+3
-4
glances/core/glances_processes.py
glances/core/glances_processes.py
+27
-6
glances/outputs/glances_curses.py
glances/outputs/glances_curses.py
+5
-0
glances/plugins/glances_processcount.py
glances/plugins/glances_processcount.py
+3
-7
glances/plugins/glances_processlist.py
glances/plugins/glances_processlist.py
+3
-7
未找到文件。
glances/core/glances_logs.py
浏览文件 @
77b3a888
...
...
@@ -87,8 +87,7 @@ class GlancesLogs(object):
else
:
# Default sort is...
process_auto_by
=
'cpu_percent'
glances_processes
.
setsortkey
(
process_auto_by
)
glances_processes
.
setautosortkey
(
process_auto_by
)
return
process_auto_by
...
...
@@ -96,8 +95,8 @@ class GlancesLogs(object):
"""Reset the process_auto_by variable."""
# Default sort is...
process_auto_by
=
'cpu_percent'
glances_processes
.
set
sortkey
(
process_auto_by
)
glances_processes
.
setautosortkey
(
process_auto_by
)
glances_processes
.
set
manualsortkey
(
None
)
return
process_auto_by
...
...
glances/core/glances_processes.py
浏览文件 @
77b3a888
...
...
@@ -44,7 +44,7 @@ class GlancesProcesses(object):
self
.
io_old
=
{}
# Init stats
self
.
processsort
=
'cpu_percent'
self
.
resetsort
()
self
.
processlist
=
[]
self
.
processcount
=
{
'total'
:
0
,
'running'
:
0
,
'sleeping'
:
0
,
'thread'
:
0
}
...
...
@@ -219,7 +219,7 @@ class GlancesProcesses(object):
if
self
.
get_max_processes
()
is
not
None
:
# Sort the internal dict and cut the top N (Return a list of tuple)
# tuple=key (proc), dict (returned by __get_process_stats)
processiter
=
sorted
(
processdict
.
items
(),
key
=
lambda
x
:
x
[
1
][
'cpu_percent'
],
reverse
=
True
)
processiter
=
sorted
(
processdict
.
items
(),
key
=
lambda
x
:
x
[
1
][
self
.
getsortkey
()
],
reverse
=
True
)
for
i
in
processiter
[
0
:
self
.
get_max_processes
()]:
# Already existing mandatory stats
procstat
=
i
[
1
]
...
...
@@ -257,13 +257,34 @@ class GlancesProcesses(object):
return
self
.
processlist
def
getsortkey
(
self
):
"""Get the current sort key"""
if
self
.
getmanualsortkey
()
is
not
None
:
return
self
.
getmanualsortkey
()
else
:
return
self
.
getautosortkey
()
def
getmanualsortkey
(
self
):
"""Get the current sort key for manual sort."""
return
self
.
processmanualsort
def
getautosortkey
(
self
):
"""Get the current sort key for automatic sort."""
return
self
.
processsort
return
self
.
process
auto
sort
def
setsortkey
(
self
,
sortedby
):
def
setmanualsortkey
(
self
,
sortedby
):
"""Set the current sort key for manual sort."""
self
.
processmanualsort
=
sortedby
return
self
.
processmanualsort
def
setautosortkey
(
self
,
sortedby
):
"""Set the current sort key for automatic sort."""
self
.
processsort
=
sortedby
return
self
.
processsort
self
.
processautosort
=
sortedby
return
self
.
processautosort
def
resetsort
(
self
):
"""Set the default sort: Auto"""
self
.
setmanualsortkey
(
None
)
self
.
setautosortkey
(
'cpu_percent'
)
def
getsortlist
(
self
,
sortedby
=
None
):
"""Get the sorted processlist."""
...
...
glances/outputs/glances_curses.py
浏览文件 @
77b3a888
...
...
@@ -203,6 +203,7 @@ class GlancesCurses(object):
elif
self
.
pressedkey
==
ord
(
'a'
):
# 'a' > Sort processes automatically
self
.
args
.
process_sorted_by
=
'auto'
glances_processes
.
resetsort
()
elif
self
.
pressedkey
==
ord
(
'b'
):
# 'b' > Switch between bit/s and Byte/s for network IO
# self.net_byteps_tag = not self.net_byteps_tag
...
...
@@ -210,6 +211,7 @@ class GlancesCurses(object):
elif
self
.
pressedkey
==
ord
(
'c'
):
# 'c' > Sort processes by CPU usage
self
.
args
.
process_sorted_by
=
'cpu_percent'
glances_processes
.
setmanualsortkey
(
self
.
args
.
process_sorted_by
)
elif
self
.
pressedkey
==
ord
(
'd'
):
# 'd' > Show/hide disk I/O stats
self
.
args
.
disable_diskio
=
not
self
.
args
.
disable_diskio
...
...
@@ -225,18 +227,21 @@ class GlancesCurses(object):
elif
self
.
pressedkey
==
ord
(
'i'
):
# 'i' > Sort processes by IO rate (not available on OS X)
self
.
args
.
process_sorted_by
=
'io_counters'
glances_processes
.
setmanualsortkey
(
self
.
args
.
process_sorted_by
)
elif
self
.
pressedkey
==
ord
(
'l'
):
# 'l' > Show/hide log messages
self
.
args
.
disable_log
=
not
self
.
args
.
disable_log
elif
self
.
pressedkey
==
ord
(
'm'
):
# 'm' > Sort processes by MEM usage
self
.
args
.
process_sorted_by
=
'memory_percent'
glances_processes
.
setmanualsortkey
(
self
.
args
.
process_sorted_by
)
elif
self
.
pressedkey
==
ord
(
'n'
):
# 'n' > Show/hide network stats
self
.
args
.
disable_network
=
not
self
.
args
.
disable_network
elif
self
.
pressedkey
==
ord
(
'p'
):
# 'p' > Sort processes by name
self
.
args
.
process_sorted_by
=
'name'
glances_processes
.
setmanualsortkey
(
self
.
args
.
process_sorted_by
)
elif
self
.
pressedkey
==
ord
(
'r'
):
# 'r' > Reset history
self
.
reset_history_tag
=
not
self
.
reset_history_tag
...
...
glances/plugins/glances_processcount.py
浏览文件 @
77b3a888
...
...
@@ -107,17 +107,13 @@ class Plugin(GlancesPlugin):
ret
.
append
(
self
.
curse_add_line
(
msg
))
# Display sort information
try
:
args
.
process_sorted_by
except
AttributeError
:
args
.
process_sorted_by
=
glances_processes
.
getsortkey
()
if
args
.
process_sorted_by
==
'auto'
:
if
glances_processes
.
getmanualsortkey
()
is
None
:
msg
=
_
(
"sorted automatically"
)
ret
.
append
(
self
.
curse_add_line
(
msg
))
msg
=
_
(
" by {0}"
).
format
(
glances_processes
.
getsortkey
())
msg
=
_
(
" by {0}"
).
format
(
glances_processes
.
get
auto
sortkey
())
ret
.
append
(
self
.
curse_add_line
(
msg
))
else
:
msg
=
_
(
"sorted by {0}"
).
format
(
args
.
process_sorted_by
)
msg
=
_
(
"sorted by {0}"
).
format
(
glances_processes
.
getmanualsortkey
()
)
ret
.
append
(
self
.
curse_add_line
(
msg
))
# Return the message with decoration
...
...
glances/plugins/glances_processlist.py
浏览文件 @
77b3a888
...
...
@@ -74,14 +74,10 @@ class Plugin(GlancesPlugin):
return
ret
# Compute the sort key
try
:
args
.
process_sorted_by
except
AttributeError
:
args
.
process_sorted_by
=
glances_processes
.
getsortkey
()
if
args
.
process_sorted_by
==
'auto'
:
process_sort_key
=
glances_processes
.
getsortkey
()
if
glances_processes
.
getmanualsortkey
()
is
None
:
process_sort_key
=
glances_processes
.
getautosortkey
()
else
:
process_sort_key
=
args
.
process_sorted_by
process_sort_key
=
glances_processes
.
getmanualsortkey
()
sort_style
=
'SORT'
# Header
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录