This commit is contained in:
purplerain 2023-06-27 17:33:20 +00:00
parent 3751effe59
commit 29ec20d7b2
Signed by: purplerain
GPG key ID: F42C07F07E2E35B7
33 changed files with 213 additions and 288 deletions

View file

@ -1,4 +1,4 @@
.\" $OpenBSD: bt.5,v 1.14 2022/03/31 17:27:29 naddy Exp $
.\" $OpenBSD: bt.5,v 1.15 2023/06/27 14:13:33 claudio Exp $
.\"
.\" Copyright (c) 2019 Martin Pieuchot <mpi@openbsd.org>
.\"
@ -14,7 +14,7 @@
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
.Dd $Mdocdate: March 31 2022 $
.Dd $Mdocdate: June 27 2023 $
.Dt BT 5
.Os
.Sh NAME
@ -111,8 +111,8 @@ Full name of the probe.
Return value of the traced syscall.
.It Va tid
Thread ID of the current thread.
.\".It Va ustack
.\"Userland stack of the current thread.
.It Va ustack
Userland stack of the current thread.
.El
.Pp
Functions:
@ -141,10 +141,6 @@ and
with buckets of
.Va step
size.
.It Fn max
Returns the maximum recorded value.
.It Fn min
Returns the minimum recorded value.
.It Fn print "@map"
Print all pairs from
.Va @map .
@ -162,8 +158,6 @@ Return the string from argument
truncated to
.Va index
characters (up to 64, the default) including a guaranteed NUL-terminator.
.It Fn sum
Returns the sum of all recorded values.
.It Fn time timefmt
Print timestamps using
.Xr strftime 3 .
@ -172,6 +166,23 @@ Set all values from
.Va @map
to 0.
.El
.Pp
The following functions only work on a sepcific map entry.
.Bl -tag -width "lhist(value, min, max, step)"
.It "@map[key]" = Fn count
Increase the stored value for
.Va key
by one.
.It "@map[key]" = Fn max "value"
Store the maximum recorded value for
.Va key .
.It "@map[key]" = Fn min "value"
Store the minimum recorded value for
.Va key .
.It "@map[key]" = Fn sum "value"
Store the sum of all recorded values for
.Va key .
.El
.Sh SEE ALSO
.Xr awk 1 ,
.Xr dt 4 ,

View file

@ -1,4 +1,4 @@
/* $OpenBSD: btrace.c,v 1.70 2023/05/12 14:14:16 claudio Exp $ */
/* $OpenBSD: btrace.c,v 1.71 2023/06/27 14:17:00 claudio Exp $ */
/*
* Copyright (c) 2019 - 2021 Martin Pieuchot <mpi@openbsd.org>
@ -450,6 +450,37 @@ rules_do(int fd)
}
}
static uint64_t
rules_action_scan(struct bt_stmt *bs)
{
struct bt_arg *ba;
uint64_t evtflags = 0;
while (bs != NULL) {
SLIST_FOREACH(ba, &bs->bs_args, ba_next)
evtflags |= ba2dtflags(ba);
/* Also check the value for map/hist insertion */
switch (bs->bs_act) {
case B_AC_BUCKETIZE:
case B_AC_INSERT:
ba = (struct bt_arg *)bs->bs_var;
evtflags |= ba2dtflags(ba);
break;
case B_AC_TEST:
evtflags |= rules_action_scan(
(struct bt_stmt *)bs->bs_var);
break;
default:
break;
}
bs = SLIST_NEXT(bs, bs_next);
}
return evtflags;
}
void
rules_setup(int fd)
{
@ -474,21 +505,7 @@ rules_setup(int fd)
evtflags |= ba2dtflags(ba);
}
SLIST_FOREACH(bs, &r->br_action, bs_next) {
SLIST_FOREACH(ba, &bs->bs_args, ba_next)
evtflags |= ba2dtflags(ba);
/* Also check the value for map/hist insertion */
switch (bs->bs_act) {
case B_AC_BUCKETIZE:
case B_AC_INSERT:
ba = (struct bt_arg *)bs->bs_var;
evtflags |= ba2dtflags(ba);
break;
default:
break;
}
}
evtflags |= rules_action_scan(SLIST_FIRST(&r->br_action));
SLIST_FOREACH(bp, &r->br_probes, bp_next) {
debug("parsed probe '%s'", debug_probe_name(bp));
@ -1685,10 +1702,17 @@ ba2dtflags(struct bt_arg *ba)
long
bacmp(struct bt_arg *a, struct bt_arg *b)
{
assert(a->ba_type == b->ba_type);
assert(a->ba_type == B_AT_LONG);
if (a->ba_type != b->ba_type)
return a->ba_type - b->ba_type;
return ba2long(a, NULL) - ba2long(b, NULL);
switch (a->ba_type) {
case B_AT_LONG:
return ba2long(a, NULL) - ba2long(b, NULL);
case B_AT_STR:
return strcmp(ba2str(a, NULL), ba2str(b, NULL));
default:
errx(1, "no compare support for type %d", a->ba_type);
}
}
__dead void

View file

@ -1,4 +1,4 @@
/* $OpenBSD: map.c,v 1.20 2022/04/30 01:29:05 tedu Exp $ */
/* $OpenBSD: map.c,v 1.21 2023/06/27 14:17:00 claudio Exp $ */
/*
* Copyright (c) 2020 Martin Pieuchot <mpi@openbsd.org>
@ -176,6 +176,11 @@ map_insert(struct map *map, const char *key, struct bt_arg *bval,
val += ba2long(bval->ba_value, dtev);
mep->mval->ba_value = (void *)val;
break;
case B_AT_BI_KSTACK:
case B_AT_BI_USTACK:
free(mep->mval);
mep->mval = ba_new(ba2str(bval, dtev), B_AT_STR);
break;
default:
errx(1, "no insert support for type %d", bval->ba_type);
}