Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
libvirt
提交
7e6cb82d
L
libvirt
项目概览
openeuler
/
libvirt
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
L
libvirt
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
7e6cb82d
编写于
6月 07, 2011
作者:
M
Minoru Usui
提交者:
Eric Blake
6月 14, 2011
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
virNodeGetCPUStats: Implement virsh support
Signed-off-by:
N
Minoru Usui
<
usui@mxm.nes.nec.co.jp
>
上级
daea15aa
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
137 addition
and
0 deletion
+137
-0
tools/virsh.c
tools/virsh.c
+130
-0
tools/virsh.pod
tools/virsh.pod
+7
-0
未找到文件。
tools/virsh.c
浏览文件 @
7e6cb82d
...
...
@@ -3713,6 +3713,135 @@ cmdNodeinfo(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
return
true
;
}
/*
* "nodecpustats" command
*/
static
const
vshCmdInfo
info_nodecpustats
[]
=
{
{
"help"
,
N_
(
"Prints cpu stats of the node."
)},
{
"desc"
,
N_
(
"Returns cpu stats of the node."
)},
{
NULL
,
NULL
}
};
static
const
vshCmdOptDef
opts_node_cpustats
[]
=
{
{
"cpu"
,
VSH_OT_INT
,
0
,
N_
(
"prints specified cpu statistics only."
)},
{
"percent"
,
VSH_OT_BOOL
,
0
,
N_
(
"prints by percentage during 1 second."
)},
{
NULL
,
0
,
0
,
NULL
}
};
static
bool
cmdNodeCPUStats
(
vshControl
*
ctl
,
const
vshCmd
*
cmd
ATTRIBUTE_UNUSED
)
{
int
i
,
j
;
bool
flag_utilization
=
false
;
bool
flag_percent
=
vshCommandOptBool
(
cmd
,
"percent"
);
int
cpuNum
=
VIR_CPU_STATS_ALL_CPUS
;
virCPUStatsPtr
params
;
int
nparams
=
0
;
bool
ret
=
false
;
struct
cpu_stats
{
unsigned
long
long
user
;
unsigned
long
long
sys
;
unsigned
long
long
idle
;
unsigned
long
long
iowait
;
unsigned
long
long
util
;
}
cpu_stats
[
2
];
double
user_time
,
sys_time
,
idle_time
,
iowait_time
,
total_time
;
double
usage
;
if
(
!
vshConnectionUsability
(
ctl
,
ctl
->
conn
))
return
false
;
if
(
vshCommandOptInt
(
cmd
,
"cpu"
,
&
cpuNum
)
<
0
)
{
vshError
(
ctl
,
"%s"
,
_
(
"Invalid value of cpuNum"
));
return
false
;
}
if
(
virNodeGetCPUStats
(
ctl
->
conn
,
cpuNum
,
NULL
,
&
nparams
,
0
)
!=
0
)
{
vshError
(
ctl
,
"%s"
,
_
(
"Unable to get number of cpu stats"
));
return
false
;
}
if
(
nparams
==
0
)
{
/* nothing to output */
return
true
;
}
memset
(
cpu_stats
,
0
,
sizeof
(
cpu_stats
));
params
=
vshCalloc
(
ctl
,
nparams
,
sizeof
(
*
params
));
i
=
0
;
do
{
if
(
virNodeGetCPUStats
(
ctl
->
conn
,
cpuNum
,
params
,
&
nparams
,
0
)
!=
0
)
{
vshError
(
ctl
,
"%s"
,
_
(
"Unable to get node cpu stats"
));
goto
cleanup
;
}
for
(
j
=
0
;
j
<
nparams
;
j
++
)
{
unsigned
long
long
value
=
params
[
j
].
value
;
if
(
STREQ
(
params
[
j
].
field
,
VIR_CPU_STATS_KERNEL
))
{
cpu_stats
[
i
].
sys
=
value
;
}
else
if
(
STREQ
(
params
[
j
].
field
,
VIR_CPU_STATS_USER
))
{
cpu_stats
[
i
].
user
=
value
;
}
else
if
(
STREQ
(
params
[
j
].
field
,
VIR_CPU_STATS_IDLE
))
{
cpu_stats
[
i
].
idle
=
value
;
}
else
if
(
STREQ
(
params
[
j
].
field
,
VIR_CPU_STATS_IOWAIT
))
{
cpu_stats
[
i
].
iowait
=
value
;
}
else
if
(
STREQ
(
params
[
j
].
field
,
VIR_CPU_STATS_UTILIZATION
))
{
cpu_stats
[
i
].
util
=
value
;
flag_utilization
=
true
;
}
}
if
(
flag_utilization
||
!
flag_percent
)
break
;
i
++
;
sleep
(
1
);
}
while
(
i
<
2
);
if
(
!
flag_percent
)
{
if
(
!
flag_utilization
)
{
vshPrint
(
ctl
,
"%-15s %20llu
\n
"
,
_
(
"user :"
),
cpu_stats
[
0
].
user
);
vshPrint
(
ctl
,
"%-15s %20llu
\n
"
,
_
(
"system:"
),
cpu_stats
[
0
].
sys
);
vshPrint
(
ctl
,
"%-15s %20llu
\n
"
,
_
(
"idle :"
),
cpu_stats
[
0
].
idle
);
vshPrint
(
ctl
,
"%-15s %20llu
\n
"
,
_
(
"iowait:"
),
cpu_stats
[
0
].
iowait
);
}
}
else
{
if
(
flag_utilization
)
{
usage
=
cpu_stats
[
0
].
util
;
vshPrint
(
ctl
,
"%-15s %5.1lf%%
\n
"
,
_
(
"usage:"
),
usage
);
vshPrint
(
ctl
,
"%-15s %5.1lf%%
\n
"
,
_
(
"idle :"
),
100
-
usage
);
}
else
{
user_time
=
cpu_stats
[
1
].
user
-
cpu_stats
[
0
].
user
;
sys_time
=
cpu_stats
[
1
].
sys
-
cpu_stats
[
0
].
sys
;
idle_time
=
cpu_stats
[
1
].
idle
-
cpu_stats
[
0
].
idle
;
iowait_time
=
cpu_stats
[
1
].
iowait
-
cpu_stats
[
0
].
iowait
;
total_time
=
user_time
+
sys_time
+
idle_time
+
iowait_time
;
usage
=
(
user_time
+
sys_time
)
/
total_time
*
100
;
vshPrint
(
ctl
,
"%-15s %5.1lf%%
\n
"
,
_
(
"usage:"
),
usage
);
vshPrint
(
ctl
,
"%-15s %5.1lf%%
\n
"
,
_
(
" user :"
),
user_time
/
total_time
*
100
);
vshPrint
(
ctl
,
"%-15s %5.1lf%%
\n
"
,
_
(
" system:"
),
sys_time
/
total_time
*
100
);
vshPrint
(
ctl
,
"%-15s %5.1lf%%
\n
"
,
_
(
"idle :"
),
idle_time
/
total_time
*
100
);
vshPrint
(
ctl
,
"%-15s %5.1lf%%
\n
"
,
_
(
"iowait:"
),
iowait_time
/
total_time
*
100
);
}
}
ret
=
true
;
cleanup:
VIR_FREE
(
params
);
return
ret
;
}
/*
* "capabilities" command
*/
...
...
@@ -11393,6 +11522,7 @@ static const vshCmdDef hostAndHypervisorCmds[] = {
VSH_CMD_FLAG_NOCONNECT
},
{
"freecell"
,
cmdFreecell
,
opts_freecell
,
info_freecell
,
0
},
{
"hostname"
,
cmdHostname
,
NULL
,
info_hostname
,
0
},
{
"nodecpustats"
,
cmdNodeCPUStats
,
opts_node_cpustats
,
info_nodecpustats
,
0
},
{
"nodeinfo"
,
cmdNodeinfo
,
NULL
,
info_nodeinfo
,
0
},
{
"qemu-monitor-command"
,
cmdQemuMonitorCommand
,
opts_qemu_monitor_command
,
info_qemu_monitor_command
,
0
},
...
...
tools/virsh.pod
浏览文件 @
7e6cb82d
...
...
@@ -239,6 +239,13 @@ and size of the physical memory. The output corresponds to virNodeInfo
structure. Specifically, the "CPU socket(s)" field means number of CPU
sockets per NUMA cell.
=item B<nodecpustats> optional I<cpu> I<--percent>
Returns cpu stats of the node.
If I<cpu> is specified, this will prints specified cpu statistics only.
If I<--percent> is specified, this will prints percentage of each kind of cpu
statistics during 1 second.
=item B<capabilities>
Print an XML document describing the capabilities of the hypervisor
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录