-
Notifications
You must be signed in to change notification settings - Fork 132
Expand file tree
/
Copy pathperf_top.py
More file actions
126 lines (104 loc) · 4.32 KB
/
perf_top.py
File metadata and controls
126 lines (104 loc) · 4.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/usr/bin/env python
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# See LICENSE for more details.
#
# Copyright: 2022 IBM
# Author: Disha Goel <disgoel@linux.vnet.ibm.com>
import time
import platform
import threading
import tempfile
import os
from avocado import Test
from avocado.utils import distro, dmesg, process, genio
from avocado.utils.software_manager.manager import SoftwareManager
class perf_top(Test):
"""
Tests perf top and it's options with all
possible flags with the help of yaml file
:avocado: tags=perf,top
"""
def setUp(self):
'''
Install the basic packages to support perf
'''
# Check for basic utilities
smm = SoftwareManager()
detected_distro = distro.detect()
self.distro_name = detected_distro.name
deps = ['gcc', 'make', 'ebizzy']
if 'Ubuntu' in self.distro_name:
deps.extend(['linux-tools-common', 'linux-tools-%s' %
platform.uname()[2]])
elif 'debian' in detected_distro.name:
deps.extend(['linux-perf'])
elif self.distro_name in ['rhel', 'SuSE', 'fedora', 'centos']:
deps.extend(['perf', 'python3-pexpect'])
else:
self.cancel("Install the package for perf supported \
by %s" % detected_distro.name)
for package in deps:
if not smm.check_installed(package) and not smm.install(package):
self.cancel('%s is needed for the test to be run' % package)
# Getting the parameters from yaml file
self.option = self.params.get('option', default='')
# Clear the dmesg by that we can capture delta at the end of the test
dmesg.clear_dmesg()
# Creating a temporary file
self.temp_file = tempfile.NamedTemporaryFile().name
def run_ebizzy(self):
process.run("ebizzy -S 30", ignore_status=True, shell=True)
def test_top(self):
if self.option in ["-k", "--vmlinux", "--kallsyms"]:
if self.distro_name in ['rhel', 'fedora', 'centos']:
self.option = self.option + " /boot/vmlinuz-" + \
platform.uname()[2]
elif self.distro_name in ['SuSE', 'Ubuntu']:
self.option = self.option + " /boot/vmlinux-" + \
platform.uname()[2]
cmd = f"perf top {self.option}"
self.log.info(f"Running command: {cmd}")
proc = process.SubProcess(cmd)
proc.start()
time.sleep(10) # let perf top run for a short while
# Try to stop gracefully (like pressing 'q')
if proc.poll() is None:
process.run(f"pkill -SIGINT -f '{cmd}'", ignore_status=True)
time.sleep(1)
proc.wait()
# Check for dmesg errors
dmesg.collect_errors_dmesg([
'WARNING: CPU:', 'Oops', 'Segfault',
'soft lockup', 'Unable to handle'
])
# Check exit code and stderr for issues
if proc.result.exit_status != 0:
self.fail(f"perf top failed with option {self.option}: "
f"{proc.result.stderr.decode('utf-8', 'ignore')}")
dmesg.collect_errors_dmesg(['WARNING: CPU:', 'Oops', 'Segfault',
'soft lockup', 'Unable to handle'])
def test_workload_output(self):
workload_thread = threading.Thread(target=self.run_ebizzy)
workload_thread.start()
process.getoutput("perf top -a > %s " % self.temp_file, timeout=35)
workload_thread.join(timeout=5)
perf_top_output = genio.read_file(self.temp_file).splitlines()
flag = False
for lines in perf_top_output:
if "ebizzy" in lines:
flag = True
break
if flag is False:
self.fail("ebizzy workload not captured in perf top")
def tearDown(self):
if os.path.isfile(self.temp_file):
process.system('rm -f %s' % self.temp_file)