This adds support for the modulo operator to btrace(8). I was trying to use it like this:
$start = nsecs; /* ... */ $elapsed = nsecs - $start; printf("%d.%09d seconds\n", $elapsed / 1000000000, $elapsed % 1000000000); and noticed it was missing. ok? Index: bt_parse.y =================================================================== RCS file: /cvs/src/usr.sbin/btrace/bt_parse.y,v retrieving revision 1.53 diff -u -p -r1.53 bt_parse.y --- bt_parse.y 11 Sep 2023 19:01:26 -0000 1.53 +++ bt_parse.y 10 Oct 2023 16:07:45 -0000 @@ -184,7 +184,7 @@ filter : /* empty */ { $$ = NULL; } * Give higher precedence to: * 1. && and || * 2. ==, !=, <<, <, >=, >, +, =, &, ^, | - * 3. * and / + * 3. * , / , % */ expr : expr OP_LAND term { $$ = ba_op(B_AT_OP_LAND, $1, $3); } | expr OP_LOR term { $$ = ba_op(B_AT_OP_LOR, $1, $3); } @@ -207,6 +207,7 @@ term : term OP_EQ fterm { $$ = ba_op(B_A fterm : fterm '*' factor { $$ = ba_op(B_AT_OP_MULT, $1, $3); } | fterm '/' factor { $$ = ba_op(B_AT_OP_DIVIDE, $1, $3); } + | fterm '%' factor { $$ = ba_op(B_AT_OP_MODULO, $1, $3); } | factor ; Index: bt_parser.h =================================================================== RCS file: /cvs/src/usr.sbin/btrace/bt_parser.h,v retrieving revision 1.24 diff -u -p -r1.24 bt_parser.h --- bt_parser.h 11 Sep 2023 19:01:26 -0000 1.24 +++ bt_parser.h 10 Oct 2023 16:07:45 -0000 @@ -163,6 +163,7 @@ struct bt_arg { B_AT_OP_MINUS, B_AT_OP_MULT, B_AT_OP_DIVIDE, + B_AT_OP_MODULO, B_AT_OP_BAND, B_AT_OP_XOR, B_AT_OP_BOR, Index: btrace.c =================================================================== RCS file: /cvs/src/usr.sbin/btrace/btrace.c,v retrieving revision 1.78 diff -u -p -r1.78 btrace.c --- btrace.c 15 Sep 2023 10:59:02 -0000 1.78 +++ btrace.c 10 Oct 2023 16:07:45 -0000 @@ -1416,6 +1416,9 @@ baexpr2long(struct bt_arg *ba, struct dt case B_AT_OP_DIVIDE: result = lval / rval; break; + case B_AT_OP_MODULO: + result = lval % rval; + break; case B_AT_OP_BAND: result = lval & rval; break; @@ -1526,6 +1529,8 @@ ba_name(struct bt_arg *ba) return "*"; case B_AT_OP_DIVIDE: return "/"; + case B_AT_OP_MODULO: + return "%"; case B_AT_OP_BAND: return "&"; case B_AT_OP_XOR: