Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
tp-qemu
提交
158d4eb9
T
tp-qemu
项目概览
openeuler
/
tp-qemu
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
tp-qemu
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
158d4eb9
编写于
4月 21, 2020
作者:
Y
YongxueHong
提交者:
GitHub
4月 21, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #2188 from kimi1978wy/1821603
check_cpu_utilization: cpu utilization check with all hv flags
上级
a4260786
6317e812
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
164 addition
and
0 deletion
+164
-0
qemu/tests/cfg/hv_check_cpu_utilization.cfg
qemu/tests/cfg/hv_check_cpu_utilization.cfg
+20
-0
qemu/tests/hv_check_cpu_utilization.py
qemu/tests/hv_check_cpu_utilization.py
+144
-0
未找到文件。
qemu/tests/cfg/hv_check_cpu_utilization.cfg
0 → 100644
浏览文件 @
158d4eb9
- hv_check_cpu_utilization:
only Windows
type = hv_check_cpu_utilization
clone_master = yes
master_images_clone = image1
remove_image_image1 =yes
nics = ""
cdroms = ""
cpu_model_flags = "hv_crash"
host_check_times = 900
host_check_interval = 2
serives_to_stop = wuauserv bits dosvc SysMain
service_check_cmd = sc query %s
service_stop_cmd = sc stop {0} & sc config {0} start=disabled
reg_cmd = reg add "HKLM\SYSTEM\CurrentControlSet\Services\SecurityHealthService" /v Start /d 4 /t REG_DWORD /f
host_check_cmd = top -H -p %s -n ${host_check_times} -d ${host_check_interval} -b > fixed-top-pc-result
vcpn_thread_pattern = r'thread_id.?[:|=]\s*(\d+)'
thread_process_cmd = "cat fixed-top-pc-result |grep %s|awk -F ' ' ' {print $9;}'|awk '{sum+=$1} END {print sum/NR}'"
thread_cpu_level = 5
post_command = rm -f fixed-top-pc-result
qemu/tests/hv_check_cpu_utilization.py
0 → 100644
浏览文件 @
158d4eb9
import
time
import
threading
import
re
import
logging
from
virttest
import
utils_misc
from
virttest
import
utils_test
from
virttest
import
error_context
from
avocado.utils
import
process
def
_check_cpu_usage
(
session
):
"""
Check windows guest cpu usage by wmic. This function is used within
utils_misc.wait_for(), to check cpu usage repeatedly.
param session: a session object to send wmic commands
"""
status
,
output
=
session
.
cmd_status_output
(
"wmic cpu get loadpercentage /value"
)
if
not
status
:
result
=
re
.
search
(
r
'LoadPercentage=(\d+)'
,
output
)
if
result
:
percent
=
int
(
result
.
group
(
1
))
if
percent
>
1
:
logging
.
warning
(
"Guest cpu usage :%s%%"
,
percent
)
def
_check_cpu_thread_func
(
session
,
timeout
):
"""
Repeatedlly checking guest cpu usage, until timeout has arrived.
param session: a session object to send commands
param timeout: total checking time
"""
utils_misc
.
wait_for
(
lambda
:
_check_cpu_usage
(
session
),
timeout
,
0
,
5
)
def
_pin_vm_threads
(
vm
,
node
):
"""
Pin guest to certain numa node.
param vm: a vm object
param node: a numa node to pin to
"""
node
=
utils_misc
.
NumaNode
(
node
)
utils_test
.
qemu
.
pin_vm_threads
(
vm
,
node
)
def
_stop_service
(
test
,
params
,
session
,
service
):
"""
Check & stop windows system service
param session: a session to send commands
param service: the name of the service to stop
"""
service_check_cmd
=
params
.
get
(
"service_check_cmd"
)
service_stop_cmd
=
params
.
get
(
"service_stop_cmd"
)
s
,
o
=
session
.
cmd_status_output
(
"sc query"
)
if
s
:
test
.
error
(
"Failed to query service list, "
"status=%s, output=%s"
%
(
s
,
o
))
service_item
=
re
.
search
(
r
'SERVICE_NAME:\s+%s'
%
service
,
o
,
re
.
I
|
re
.
M
)
if
not
service_item
:
return
s
,
o
=
session
.
cmd_status_output
(
service_check_cmd
%
service
)
if
s
:
test
.
error
(
"Failed to get status for service: %s, "
"status=%s, output=%s"
%
(
service
,
s
,
o
))
if
re
.
search
(
r
'STOPPED'
,
o
,
re
.
I
|
re
.
M
):
return
session
.
cmd
(
service_stop_cmd
.
format
(
service
))
@
error_context
.
context_aware
def
run
(
test
,
params
,
env
):
"""
Cpu utilization test with hv flags.
1)Start a Windows guest vm.
2)Pin the vm to certain numa node, to keep accuracy.
3)Stop serval Windows services & background processes on guest.
to lower the cpu usage to minimum.
4)Reboot vm to apply changes, then wait for serveral minutes to make
sure the cpu is chill down.
5)Start both checking the guest&host's cpu usage, monitoring the value.
6)Compare the average utilization value to standard values.
param test: the test object
param params: the params of the test
param env: the testing environment object
"""
vm
=
env
.
get_vm
(
params
[
"main_vm"
])
# pin guest vcpus/memory/vhost threads to last numa node of host
_pin_vm_threads
(
vm
,
params
.
get_numeric
(
"numa_node"
,
-
1
))
vm
.
verify_alive
()
timeout
=
params
.
get_numeric
(
"login_timeout"
,
240
)
host_check_times
=
params
.
get_numeric
(
"host_check_times"
,
900
)
host_check_interval
=
params
.
get_numeric
(
"host_check_interval"
,
2
)
guest_check_timeout
=
host_check_times
*
host_check_interval
thread_cpu_level
=
params
.
get_numeric
(
"thread_cpu_level"
,
5
)
session
=
vm
.
wait_for_serial_login
(
timeout
=
timeout
)
service_names
=
params
.
get
(
"serives_to_stop"
).
split
()
# check and stop services
for
service
in
service_names
:
_stop_service
(
test
,
params
,
session
,
service
)
# stop windows defender
session
.
cmd
(
params
[
"reg_cmd"
])
session
=
vm
.
reboot
(
session
,
timeout
=
timeout
,
serial
=
True
)
# wait for the guest to chill
time
.
sleep
(
900
)
# start background checking guest cpu usage
thread
=
threading
.
Thread
(
target
=
_check_cpu_thread_func
,
args
=
(
session
,
guest_check_timeout
))
thread
.
start
()
time
.
sleep
(
60
)
# start checking host cpu usage
pid
=
vm
.
get_pid
()
process
.
system
(
params
[
"host_check_cmd"
]
%
pid
,
shell
=
True
)
thread
.
join
(
guest_check_timeout
+
360
)
vcpu_thread_pattern
=
params
.
get
(
"vcpu_thread_pattern"
,
r
'thread_id.?[:|=]\s*(\d+)'
)
vcpu_ids
=
vm
.
get_vcpu_pids
(
vcpu_thread_pattern
)
for
thread_id
in
vcpu_ids
:
# output result
host_cpu_usage
=
process
.
system_output
(
params
[
"thread_process_cmd"
]
%
thread_id
,
shell
=
True
)
host_cpu_usage
=
float
(
host_cpu_usage
.
decode
())
if
host_cpu_usage
>
thread_cpu_level
:
test
.
fail
(
"The cpu usage of thread %s is %s"
" > %s"
%
(
thread_id
,
host_cpu_usage
,
thread_cpu_level
))
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录