summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudio Jeker <claudio@cvs.openbsd.org>2023-06-27 14:17:01 +0000
committerClaudio Jeker <claudio@cvs.openbsd.org>2023-06-27 14:17:01 +0000
commit413cb3610f9bf48df165848c3be0e600c954ebbb (patch)
treeee30b4e929dc70f99da6f304b6f42164be2e1960
parent9e519156ef2930f56937698916fd69122db9b231 (diff)
Make it possible to store the kstack or ustack in a map (as value, not key).
Additionally fix the bacmp() function to work on integers and strings. bacmp() is used when maps are printed out since the output is sorted by value. Also adjust the rule parser to look into correctly into if branches to figure out which values to request from the kernel. OK kn@
-rw-r--r--usr.sbin/btrace/btrace.c62
-rw-r--r--usr.sbin/btrace/map.c7
2 files changed, 49 insertions, 20 deletions
diff --git a/usr.sbin/btrace/btrace.c b/usr.sbin/btrace/btrace.c
index 21c91884a64..25333f98510 100644
--- a/usr.sbin/btrace/btrace.c
+++ b/usr.sbin/btrace/btrace.c
@@ -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
diff --git a/usr.sbin/btrace/map.c b/usr.sbin/btrace/map.c
index c35d2a4fbbd..be416e226e8 100644
--- a/usr.sbin/btrace/map.c
+++ b/usr.sbin/btrace/map.c
@@ -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);
}