diff options
author | Abhinav Upadhyay <er.abhinav.upadhyay@gmail.com> | 2017-06-06 21:49:15 +0530 |
---|---|---|
committer | Trent Mick <trentm@gmail.com> | 2017-06-06 21:49:15 +0530 |
commit | 4af92467466addefc2ac3add59029f7678a7cf2a (patch) | |
tree | 6add9bf254437bc3f931fe3713acaae8a67faf57 | |
parent | 17f15d36c74db52a0de7ea5b7a1a5376ae61ddcd (diff) | |
download | illumos-joyent-4af92467466addefc2ac3add59029f7678a7cf2a.tar.gz |
Ignore spaces around the probe specifier name in dtrace's output.cr2046-Ignore
When using one of the tracing options, such as -n, -i, -P, -f, if
the probe specifier contains any leading or trailing spaces, then
the first line of output produced by dtrace prints the probe name as
it is (along with the spaces). Moreover, if the probe also includes
a predicate or an action, then also there is a trailing space in the
probe name in the output. Following are couple of examples:
localhost$ sudo dtrace -n ' syscall:::entry '
dtrace: description ' syscall:::entry ' matched 482 probes
lcalhost$ sudo dtrace -n 'syscall:::entry {@num[probefunc] = count();}'
dtrace: description 'syscall:::entry ' matched 482 probes
This change skips the leading spaces in the probe name before
starting to process them. Also, when splitting the probe name
from the predicate and actions in compile_str(), it uses space
as one of the separators so that any trailing space after the
probe name will also be avoided in the output.
Also, add a test case (dtraceUtil/tst.TestProbeDescription.d.ksh) - which
checks that there are no leading or trailing spaces in the probe name
in dtrace's output when used using the -n option.
3 files changed, 60 insertions, 6 deletions
diff --git a/usr/src/cmd/dtrace/dtrace.c b/usr/src/cmd/dtrace/dtrace.c index f005629fc9..9ca412ab67 100644 --- a/usr/src/cmd/dtrace/dtrace.c +++ b/usr/src/cmd/dtrace/dtrace.c @@ -32,6 +32,7 @@ #include <sys/stat.h> #include <sys/wait.h> +#include <ctype.h> #include <dtrace.h> #include <stdlib.h> #include <stdarg.h> @@ -737,7 +738,7 @@ compile_str(dtrace_cmd_t *dcp) dcp->dc_spec, g_cflags | DTRACE_C_PSPEC, g_argc, g_argv)) == NULL) dfatal("invalid probe specifier %s", dcp->dc_arg); - if ((p = strpbrk(dcp->dc_arg, "{/;")) != NULL) + if ((p = strpbrk(dcp->dc_arg, "{/; ")) != NULL) *p = '\0'; /* crop name for reporting */ dcp->dc_desc = "description"; @@ -1157,6 +1158,14 @@ intr(int signo) g_impatient = 1; } +static char * +skip_leading_spaces(char *s) +{ + while (isspace(*s)) + s++; + return (s); +} + int main(int argc, char *argv[]) { @@ -1409,7 +1418,7 @@ main(int argc, char *argv[]) dcp = &g_cmdv[g_cmdc++]; dcp->dc_func = compile_str; dcp->dc_spec = DTRACE_PROBESPEC_FUNC; - dcp->dc_arg = optarg; + dcp->dc_arg = skip_leading_spaces(optarg); break; case 'F': @@ -1426,7 +1435,7 @@ main(int argc, char *argv[]) dcp = &g_cmdv[g_cmdc++]; dcp->dc_func = compile_str; dcp->dc_spec = DTRACE_PROBESPEC_NAME; - dcp->dc_arg = optarg; + dcp->dc_arg = skip_leading_spaces(optarg); break; case 'I': @@ -1443,21 +1452,21 @@ main(int argc, char *argv[]) dcp = &g_cmdv[g_cmdc++]; dcp->dc_func = compile_str; dcp->dc_spec = DTRACE_PROBESPEC_MOD; - dcp->dc_arg = optarg; + dcp->dc_arg = skip_leading_spaces(optarg); break; case 'n': dcp = &g_cmdv[g_cmdc++]; dcp->dc_func = compile_str; dcp->dc_spec = DTRACE_PROBESPEC_NAME; - dcp->dc_arg = optarg; + dcp->dc_arg = skip_leading_spaces(optarg); break; case 'P': dcp = &g_cmdv[g_cmdc++]; dcp->dc_func = compile_str; dcp->dc_spec = DTRACE_PROBESPEC_PROVIDER; - dcp->dc_arg = optarg; + dcp->dc_arg = skip_leading_spaces(optarg); break; case 'q': diff --git a/usr/src/cmd/dtrace/test/tst/common/dtraceUtil/tst.TestProbeDescription.d.ksh b/usr/src/cmd/dtrace/test/tst/common/dtraceUtil/tst.TestProbeDescription.d.ksh new file mode 100644 index 0000000000..541392c83a --- /dev/null +++ b/usr/src/cmd/dtrace/test/tst/common/dtraceUtil/tst.TestProbeDescription.d.ksh @@ -0,0 +1,44 @@ +#!/bin/ksh -p +# +# This file and its contents are supplied under the terms of the +# Common Development and Distribution License ("CDDL"), version 1.0. +# You may only use this file in accordance with the terms of version +# 1.0 of the CDDL. +# +# A full copy of the text of the CDDL should have accompanied this +# source. A copy of the CDDL is also available via the Internet at +# http://www.illumos.org/license/CDDL. +# + +# +# Copyright (c) 2017 Abhinav Upadhyay <abhinav@NetBSD.org>. +# All rights reserved. +# + +## +# +# ASSERTION: +# The probe name in the output for the -n option should not have any +# leading or trailing spaces. +# +# SECTION: dtrace Utility/-n Option; +# +## + +if [ $# != 1 ]; then + echo expected one argument: '<'dtrace-path'>' + exit 2 +fi + +dtrace=$1 + +o1=$($dtrace -c date -n ' syscall::write:entry {@num[probefunc] = count();}' \ + 2>&1 > /dev/null) + +if [ "$status" -ne 0 ]; then + echo $tst: dtrace failed + exit $status +fi + +o2=$(echo "$o1" | head -n 1) +echo "$o2" diff --git a/usr/src/cmd/dtrace/test/tst/common/dtraceUtil/tst.TestProbeDescription.d.ksh.out b/usr/src/cmd/dtrace/test/tst/common/dtraceUtil/tst.TestProbeDescription.d.ksh.out new file mode 100644 index 0000000000..73916df133 --- /dev/null +++ b/usr/src/cmd/dtrace/test/tst/common/dtraceUtil/tst.TestProbeDescription.d.ksh.out @@ -0,0 +1 @@ +dtrace: description 'syscall::write:entry' matched 1 probe |