Skip to content

Commit eb2d812

Browse files
committed
perf/perf_sdt_probe: enhance test to run all sdt events
This patch adds logic to test all the SDT events present and later removes them. Also increase the sleep time to avoid failure in cases where perf list is not updated after adding probe. Signed-off-by: Disha Goel <disgoel@linux.ibm.com>
1 parent d74c03e commit eb2d812

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

perf/perf_sdt_probe.py

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ class PerfSDT(Test):
3434
"""
3535

3636
def run_cmd(self, cmd):
37-
if process.system(cmd, ignore_status=True, sudo=True, shell=True):
37+
if process.system(cmd, sudo=True, shell=True):
3838
self.is_fail += 1
3939
return
4040

4141
@staticmethod
4242
def run_cmd_out(cmd):
4343
return process.system_output(cmd, shell=True,
44-
ignore_status=True, sudo=True).decode("utf-8")
44+
sudo=True).decode("utf-8")
4545

4646
def add_library(self):
4747
"""
@@ -73,14 +73,14 @@ def add_library(self):
7373
self.run_cmd(perf_add)
7474
if self.is_fail:
7575
self.fail("Unable to add %s to builid-cache" % self.libpthread)
76-
time.sleep(10)
76+
time.sleep(30)
7777
# Add the libc.so.6 to perf
7878
perf_libc_add = "perf buildid-cache -v --add %s" % self.libc
7979
self.is_fail = 0
8080
self.run_cmd(perf_libc_add)
8181
if self.is_fail:
8282
self.fail("Unable to add %s to builid-cache" % self.libc)
83-
time.sleep(10)
83+
time.sleep(30)
8484
# Check if libpthread has valid SDT markers
8585
new_val = 0
8686
result = self.run_cmd_out("perf list")
@@ -98,15 +98,21 @@ def remove_library(self, param):
9898
self.fail("Unable to remove %s from builid-cache" % param)
9999

100100
def enable_sdt_marker_probe(self):
101-
self.sdt_marker = "sdt_libc:memory_mallopt_mmap_max"
102-
if self.sdt_marker not in self.run_cmd_out("perf list"):
103-
self.fail("SDT marker %s not available" % self.sdt_marker)
104-
105-
enable_sdt_probe = "perf probe --add %s" % self.sdt_marker
106-
self.is_fail = 0
107-
self.run_cmd(enable_sdt_probe)
108-
if self.is_fail:
109-
self.fail("Unable to probe SDT marker event %s" % self.sdt_marker)
101+
self.sdt_events = process.system_output(
102+
"perf list --raw-dump sdt", shell=True).decode().split()
103+
for self.event in self.sdt_events:
104+
self.event = self.event.split('@')[0].strip()
105+
try:
106+
self.run_cmd("perf probe --add %s" % self.event)
107+
except Exception as e:
108+
error_message = str(e)
109+
if ('File exists' in error_message or
110+
'already exists' in error_message):
111+
self.log.info(
112+
f"Event {self.event} already exists, skipping.")
113+
else:
114+
self.fail(
115+
f"Failed to add event {self.event}: {error_message}")
110116

111117
def disable_sdt_marker_probe(self):
112118
disable_sdt_probe = "perf probe -d \\*"
@@ -118,13 +124,13 @@ def disable_sdt_marker_probe(self):
118124

119125
def record_sdt_marker_probe(self):
120126
record_sdt_probe = "perf record -o %s -e %s -aR sleep 1" % (
121-
self.temp_file, self.sdt_marker)
127+
self.temp_file, self.event)
122128
self.is_fail = 0
123129
self.run_cmd(record_sdt_probe)
124130
if self.is_fail or not os.path.exists(self.temp_file):
125131
self.disable_sdt_marker_probe()
126132
self.fail("Perf record of SDT marker event %s failed"
127-
% self.sdt_marker)
133+
% self.event)
128134

129135
def setUp(self):
130136
"""

0 commit comments

Comments
 (0)