Skip to content

Commit

Permalink
test: clean up orphaned tracing events between tests
Browse files Browse the repository at this point in the history
Signed-off-by: Kris Van Hees <kris.van.hees@oracle.com>
Reviewed-by: Nick Alcock <nick.alcock@oracle.com>
Reviewed-by: Eugene Loh <eugene.loh@oracle.com>
  • Loading branch information
kvanhees committed Jun 7, 2023
1 parent 54eaa89 commit ec0c3cf
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 1 deletion.
2 changes: 2 additions & 0 deletions runtest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1500,6 +1500,8 @@ for dt in $dtrace; do
cp -f $tmpdir/test.out $base.r
fi
test/utils/clean_probes.sh >> $LOGFILE
log "\n"
if [[ -n $regression ]]; then
Expand Down
2 changes: 1 addition & 1 deletion test/utils/Build
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# http://oss.oracle.com/licenses/upl.

TEST_UTILS = baddof badioctl workload_kernel workload_user showUSDT print-stack-layout
TEST_SCRIPTS = check_result.sh cpc_get_events.sh cpc_temp_skip_bug.sh perf_count_event.sh workload_analyze_loop.sh workload_get_iterations.sh
TEST_SCRIPTS = check_result.sh clean_probes.sh cpc_get_events.sh cpc_temp_skip_bug.sh perf_count_event.sh workload_analyze_loop.sh workload_get_iterations.sh

define test-util-template
CMDS += $(1)
Expand Down
101 changes: 101 additions & 0 deletions test/utils/clean_probes.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#!/usr/bin/bash

TRACEFS=/sys/kernel/debug/tracing
EVENTS=${TRACEFS}/available_events
KPROBES=${TRACEFS}/kprobe_events
UPROBES=${TRACEFS}/uprobe_events

# Check permissions
if [[ ! -r ${EVENTS} ]]; then
echo "ERROR: Cannot read ${EVENTS}" > /dev/stderr
exit 1
elif [[ ! -w ${KPROBES} ]]; then
echo "ERROR: Cannot write to ${KPROBES}" > /dev/stderr
exit 1
elif [[ ! -w ${UPROBES} ]]; then
echo "ERROR: Cannot write to ${UPROBES}" > /dev/stderr
exit 1
fi

# Scan the list of events for any orphaned DTrace probes
{
ps -C dtrace -o pid=
echo '==='
cat ${EVENTS}
} | \
awk -v kfn=${KPROBES} -v ufn=${UPROBES} \
'function getTimestamp(dt) {
cmd = "date +\"%s.%N\"";
cmd | getline dt;
close(cmd);
return dt;
}
function timeDiff(t0, t1, s0, n0, s1, n1) {
tmp = $0;
$0 = t0;
sub(/\./, " ");
s0 = int($1);
n0 = int($2);
$0 = t1;
sub(/\./, " ");
s1 = int($1);
n1 = int($2);
if (n1 < n0) {
s1--;
n1 += 1000000000;
}
$0 = tmp;
return sprintf("%d.%09d", s1 - s0, n1 - n0);
}
BEGIN { start = getTimestamp(); }
/^===/ {
re = "^dt_(" substr(pids, 2) ")_";
next;
}
!re {
pids = pids "|" int($1);
next;
}
$1 !~ /^dt_[0-9]/ { next; }
$1 ~ re { next; }
{ sub(/:/, "/"); }
{
if (/_fbt_/)
kpv[kpc++] = $0;
else
upv[upc++] = $0;
}
END {
for (i = 0; i < kpc; i++) {
print "Orphaned kprobe "kpv[i];
print "-:"kpv[i] >> kfn;
if (i % 20 == 19)
close(kfn);
}
close(kfn);
for (i = 0; i < upc; i++) {
print "Orphaned uprobe "upv[i];
print "-:"upv[i] >> ufn;
if (i % 20 == 19)
close(ufn);
}
close(ufn);
diff = timeDiff(start, getTimestamp());
txt = sprintf(" (%d kprobes, %d uprobes)", kpc, upc);
print "Cleaning took " diff txt;
}'

exit 0

0 comments on commit ec0c3cf

Please sign in to comment.