[DTrace-devel] [PATCH v2] test: clean up orphaned tracing events between tests
Eugene Loh
eugene.loh at oracle.com
Wed Jun 7 17:22:11 UTC 2023
Reviewed-by: Eugene Loh <eugene.loh at oracle.com>
But I guess I'm curious why EVENTS is used inside the awk script while
KPROBES and UPROBES are not; they are "hardwired" inside the awk script
to values that are already defined. In case the issue is defining more
"awk -v" variable values, one way around that (including for the
existing "-v tracefs") is to use stuff like:
awk 'END { fn = '$KPROBES'; print >> fn; }'
With regards to argument lists for user-defined functions, the awk man
page says "The convention is to separate local variables from real
parameters by extra spaces in the parameter list."
Should the /^===/ clause end with "next;"?
A few comments in the awk would be nice. And maybe a more descriptive
name for "re"?
Are there dt_pid events that need to be cleaned up?
On 6/7/23 12:32, Kris Van Hees via DTrace-devel wrote:
> diff --git a/test/utils/clean_probes.sh b/test/utils/clean_probes.sh
> +#!/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 tracefs=${TRACEFS} \
> + '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) ")_"; }
> +
> + !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 {
> + fn = tracefs"/kprobe_events";
> + for (i = 0; i < kpc; i++) {
> + print "Orphaned kprobe "kpv[i];
> + print "-:"kpv[i] >> fn;
> + if (i % 20 == 19)
> + close(fn);
> + }
> + close(fn);
> +
> + fn = tracefs"/uprobe_events";
> + for (i = 0; i < upc; i++) {
> + print "Orphaned uprobe "upv[i];
> + print "-:"upv[i] >> fn;
> + if (i % 20 == 19)
> + close(fn);
> + }
> + close(fn);
> +
> + diff = timeDiff(start, getTimestamp());
> + txt = sprintf(" (%d kprobes, %d uprobes)", kpc, upc);
> + print "Cleaning took " diff txt;
> + }'
> +
> +exit 0
More information about the DTrace-devel
mailing list