[DTrace-devel] [PATCH v2] test: clean up orphaned tracing events between tests
Kris Van Hees
kris.van.hees at oracle.com
Wed Jun 7 18:03:36 UTC 2023
On Wed, Jun 07, 2023 at 01:22:11PM -0400, Eugene Loh via DTrace-devel wrote:
> 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; }'
True, I can just put in KPROBES and UPROBES. I was using the env names mostly
to make things more readable so functionally it doesn't really matter. But I
will make pass them in.
> 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."
I know, but I don't think that actually makes much sense (and looks kind of
odd). It also seems to depend on which AWK implementation you prefer (some
do not really suggest any conventions).
> Should the /^===/ clause end with "next;"?
Yes, might as well (and it is cleaner).
> A few comments in the awk would be nice. And maybe a more descriptive name
> for "re"?
re is quite common as a name for a regular expression.
> Are there dt_pid events that need to be cleaned up?
We can't because they are not identifiable by pid of the dtrace that created
them.
> 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
>
> _______________________________________________
> DTrace-devel mailing list
> DTrace-devel at oss.oracle.com
> https://oss.oracle.com/mailman/listinfo/dtrace-devel
More information about the DTrace-devel
mailing list