summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorMartin Pieuchot <mpi@cvs.openbsd.org>2020-04-23 18:36:52 +0000
committerMartin Pieuchot <mpi@cvs.openbsd.org>2020-04-23 18:36:52 +0000
commit5ac974a527901effb41f7289022a88d576eaa141 (patch)
tree5da80edfb07dff5b517b2da87c64d207b3f65478 /usr.sbin
parent45b4e71ee04d9f3e26ffc78e99186370b8f4de22 (diff)
Implement builtin 'cpu' keyword.
This is useful to know which CPU recorded a given event. While here document 'retval' and comment out 'ustack' until we have a way to capture userland stacks.
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/btrace/TODO1
-rw-r--r--usr.sbin/btrace/bt.532
-rw-r--r--usr.sbin/btrace/bt_parse.y6
-rw-r--r--usr.sbin/btrace/bt_parser.h3
-rw-r--r--usr.sbin/btrace/btrace.c7
5 files changed, 30 insertions, 19 deletions
diff --git a/usr.sbin/btrace/TODO b/usr.sbin/btrace/TODO
index a9e603f7161..bd583eee7b2 100644
--- a/usr.sbin/btrace/TODO
+++ b/usr.sbin/btrace/TODO
@@ -10,7 +10,6 @@ Missing language features:
- str(args->buf, args->count)
- @ = hist(x)
- @ = lhist(x, min, max, step)
-- 'cpu' builtin, reports cpuid
- 'argv'
- $1 support
diff --git a/usr.sbin/btrace/bt.5 b/usr.sbin/btrace/bt.5
index 1c273875f57..acef0d08400 100644
--- a/usr.sbin/btrace/bt.5
+++ b/usr.sbin/btrace/bt.5
@@ -1,4 +1,4 @@
-.\" $OpenBSD: bt.5,v 1.4 2020/03/20 12:07:48 kn Exp $
+.\" $OpenBSD: bt.5,v 1.5 2020/04/23 18:36:51 mpi 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 20 2020 $
+.Dd $Mdocdate: April 23 2020 $
.Dt BT 5
.Os
.Sh NAME
@@ -87,22 +87,26 @@ by the associated
Variable names with special meaning:
.Pp
.Bl -tag -width "kstack " -compact
-.It Va pid
-Process ID of the current thread
-.It Va tid
-Thread ID of the current thread
-.It Va comm
-Command name of the current process
-.It Va nsecs
-Timestamp of the event in nanoseconds
-.It Va kstack
-Kernel stack of the current thread
-.It Va ustack
-Userland stack of the current thread
.It Va argN
Argument
.Va N
of the corresponding probe
+.It Va comm
+Command name of the current process
+.It Va cpu
+ID of the processor that recorded the event
+.It Va kstack
+Kernel stack of the current thread
+.It Va nsecs
+Timestamp of the event in nanoseconds
+.It Va pid
+Process ID of the current thread
+.It Va retval
+Return value of the traced syscall
+.It Va tid
+Thread ID of the current thread
+.\".It Va ustack
+.\"Userland stack of the current thread
.El
.Pp
Functions:
diff --git a/usr.sbin/btrace/bt_parse.y b/usr.sbin/btrace/bt_parse.y
index 6a6bef6ecaa..44067875cba 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.11 2020/04/23 14:54:12 mpi Exp $ */
+/* $OpenBSD: bt_parse.y,v 1.12 2020/04/23 18:36:51 mpi Exp $ */
/*
* Copyright (c) 2019 - 2020 Martin Pieuchot <mpi@openbsd.org>
@@ -101,7 +101,7 @@ static int yylex(void);
%token ERROR OP_EQ OP_NEQ BEGIN END
/* Builtins */
%token ARG0 ARG1 ARG2 ARG3 ARG4 ARG5 ARG6 ARG7 ARG8 ARG9
-%token COMM HZ KSTACK USTACK NSECS PID RETVAL TID
+%token COMM CPU HZ KSTACK USTACK NSECS PID RETVAL TID
/* Functions */
%token F_CLEAR F_DELETE F_EXIT F_PRINT F_PRINTF F_TIME F_ZERO
/* Map functions */
@@ -155,6 +155,7 @@ predicate : /* empty */ { $$ = NULL; }
builtin : PID { $$ = B_AT_BI_PID; }
| TID { $$ = B_AT_BI_TID; }
| COMM { $$ = B_AT_BI_COMM; }
+ | CPU { $$ = B_AT_BI_CPU; }
| NSECS { $$ = B_AT_BI_NSECS; }
| KSTACK { $$ = B_AT_BI_KSTACK; }
| USTACK { $$ = B_AT_BI_USTACK; }
@@ -537,6 +538,7 @@ lookup(char *s)
{ "clear", F_CLEAR },
{ "comm", COMM },
{ "count", M_COUNT },
+ { "cpu", CPU },
{ "delete", F_DELETE },
{ "exit", F_EXIT },
{ "hz", HZ },
diff --git a/usr.sbin/btrace/bt_parser.h b/usr.sbin/btrace/bt_parser.h
index f495063cf7f..3ad26b76309 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.6 2020/04/15 15:00:04 mpi Exp $ */
+/* $OpenBSD: bt_parser.h,v 1.7 2020/04/23 18:36:51 mpi Exp $ */
/*
* Copyright (c) 2019-2020 Martin Pieuchot <mpi@openbsd.org>
@@ -111,6 +111,7 @@ struct bt_arg {
B_AT_BI_PID,
B_AT_BI_TID,
B_AT_BI_COMM,
+ B_AT_BI_CPU,
B_AT_BI_NSECS,
B_AT_BI_KSTACK,
B_AT_BI_USTACK,
diff --git a/usr.sbin/btrace/btrace.c b/usr.sbin/btrace/btrace.c
index d0815350041..ff59a507b39 100644
--- a/usr.sbin/btrace/btrace.c
+++ b/usr.sbin/btrace/btrace.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: btrace.c,v 1.16 2020/04/23 14:54:12 mpi Exp $ */
+/* $OpenBSD: btrace.c,v 1.17 2020/04/23 18:36:51 mpi Exp $ */
/*
* Copyright (c) 2019 - 2020 Martin Pieuchot <mpi@openbsd.org>
@@ -947,6 +947,10 @@ ba2str(struct bt_arg *ba, struct dt_evt *dtev)
case B_AT_BI_COMM:
str = dtev->dtev_comm;
break;
+ case B_AT_BI_CPU:
+ snprintf(buf, sizeof(buf) - 1, "%u", dtev->dtev_cpu);
+ str = buf;
+ break;
case B_AT_BI_PID:
snprintf(buf, sizeof(buf) - 1, "%d", dtev->dtev_pid);
str = buf;
@@ -1018,6 +1022,7 @@ ba2dtflags(struct bt_arg *ba)
case B_AT_BI_COMM:
flags |= DTEVT_EXECNAME;
break;
+ case B_AT_BI_CPU:
case B_AT_BI_PID:
case B_AT_BI_TID:
case B_AT_BI_NSECS: