diff options
author | Martin Pieuchot <mpi@cvs.openbsd.org> | 2020-03-19 15:52:31 +0000 |
---|---|---|
committer | Martin Pieuchot <mpi@cvs.openbsd.org> | 2020-03-19 15:52:31 +0000 |
commit | 4a2423738b02851ea9c4b7a0482a9abdfc4a2207 (patch) | |
tree | 1b5d03fcbce09cb7dc9d3bce2fa4ca01b37f0ba5 /usr.sbin/btrace | |
parent | 8ce9041f59352de2148f577d6c5ad76ba120e05f (diff) |
Add support for unnamed map.
The following is now possible but won't print anything by default:
# btrace -e 'profile:hz:99 { @[kstack] = count() }'
ok patrick@, tobhe@
Diffstat (limited to 'usr.sbin/btrace')
-rw-r--r-- | usr.sbin/btrace/bt_parse.y | 16 | ||||
-rw-r--r-- | usr.sbin/btrace/bt_parser.h | 4 | ||||
-rw-r--r-- | usr.sbin/btrace/map.c | 5 |
3 files changed, 20 insertions, 5 deletions
diff --git a/usr.sbin/btrace/bt_parse.y b/usr.sbin/btrace/bt_parse.y index ee85b1bb83d..0be86d1a01b 100644 --- a/usr.sbin/btrace/bt_parse.y +++ b/usr.sbin/btrace/bt_parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: bt_parse.y,v 1.8 2020/01/28 16:39:51 mpi Exp $ */ +/* $OpenBSD: bt_parse.y,v 1.9 2020/03/19 15:52:30 mpi Exp $ */ /* * Copyright (c) 2019 - 2020 Martin Pieuchot <mpi@openbsd.org> @@ -41,13 +41,16 @@ #include "bt_parser.h" +/* Name for the default map @[], hopefully nobody will use this one ;) */ +#define UNNAMED_MAP "___unnamed_map_doesnt_have_any_name" + /* Number of rules to evaluate. */ struct bt_ruleq g_rules = TAILQ_HEAD_INITIALIZER(g_rules); /* Number of probes except BEGIN/END. */ int g_nprobes; -/* List of global variables. */ +/* List of global variables, including maps. */ SLIST_HEAD(, bt_var) g_variables; struct bt_rule *br_new(struct bt_probe *, struct bt_filter *, struct bt_stmt *, @@ -203,6 +206,7 @@ term : '(' term ')' { $$ = $2; } ; gvar : '@' STRING { $$ = $2; } + | '@' { $$ = UNNAMED_MAP; } map : gvar '[' arg ']' { $$ = bm_get($1, $3); } ; @@ -406,6 +410,14 @@ bs_append(struct bt_stmt *ds0, struct bt_stmt *ds1) return ds0; } +const char * +bv_name(struct bt_var *bv) +{ + if (strncmp(bv->bv_name, UNNAMED_MAP, strlen(UNNAMED_MAP)) == 0) + return ""; + return bv->bv_name; +} + /* Return the global variable corresponding to `vname'. */ struct bt_var * bv_find(const char *vname) diff --git a/usr.sbin/btrace/bt_parser.h b/usr.sbin/btrace/bt_parser.h index 9c18fce9bb2..9b87673fcf5 100644 --- a/usr.sbin/btrace/bt_parser.h +++ b/usr.sbin/btrace/bt_parser.h @@ -1,4 +1,4 @@ -/* $OpenBSD: bt_parser.h,v 1.4 2020/01/28 16:39:51 mpi Exp $ */ +/* $OpenBSD: bt_parser.h,v 1.5 2020/03/19 15:52:30 mpi Exp $ */ /* * Copyright (c) 2019 Martin Pieuchot <mpi@openbsd.org> @@ -165,6 +165,8 @@ int btparse(const char *, size_t, const char *, int); #define ba_new(v, t) ba_new0((void *)(v), (t)) struct bt_arg *ba_new0(void *, enum bt_argtype); +const char *bv_name(struct bt_var *); + void bm_insert(struct bt_var *, struct bt_arg *, struct bt_arg *); diff --git a/usr.sbin/btrace/map.c b/usr.sbin/btrace/map.c index 1c4581b9824..d4064d2df18 100644 --- a/usr.sbin/btrace/map.c +++ b/usr.sbin/btrace/map.c @@ -1,4 +1,4 @@ -/* $OpenBSD: map.c,v 1.3 2020/01/28 16:39:51 mpi Exp $ */ +/* $OpenBSD: map.c,v 1.4 2020/03/19 15:52:30 mpi Exp $ */ /* * Copyright (c) 2020 Martin Pieuchot <mpi@openbsd.org> @@ -207,7 +207,8 @@ map_print(struct bt_var *bv, size_t top) } if (mcur == NULL) break; - printf("@map[%s]: %s\n", mcur->mkey, ba2str(mcur->mval, NULL)); + printf("@%s[%s]: %s\n", bv_name(bv), mcur->mkey, + ba2str(mcur->mval, NULL)); bprev = mcur->mval; } } |