]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - cddl/usr.sbin/dwatch/dwatch.1
MFC r334594: dwatch(1): Update manual to reference actual release
[FreeBSD/FreeBSD.git] / cddl / usr.sbin / dwatch / dwatch.1
1 .\" Copyright (c) 2014-2018 Devin Teske
2 .\" All rights reserved.
3 .\"
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
6 .\" are met:
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\"    notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\"    notice, this list of conditions and the following disclaimer in the
11 .\"    documentation and/or other materials provided with the distribution.
12 .\"
13 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
14 .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15 .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16 .\" DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
17 .\" INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18 .\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 .\" SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
21 .\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
22 .\" ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
23 .\" POSSIBILITY OF SUCH DAMAGE.
24 .\"
25 .\" $FreeBSD$
26 .\"
27 .Dd February 9, 2018
28 .Dt DWATCH 1
29 .Os
30 .Sh NAME
31 .Nm dwatch
32 .Nd watch processes as they trigger a particular DTrace probe
33 .Sh SYNOPSIS
34 .Nm
35 .Op Fl 1defFmnPqRvVwxy
36 .Op Fl B Ar num
37 .Op Fl E Ar code
38 .Op Fl g Ar group
39 .Op Fl j Ar jail
40 .Op Fl k Ar name
41 .Op Fl K Ar num
42 .Op Fl N Ar count
43 .Op Fl o Ar file
44 .Op Fl O Ar cmd
45 .Op Fl p Ar pid
46 .Op Fl r Ar regex
47 .Op Fl t Ar test
48 .Op Fl T Ar time
49 .Op Fl u Ar user
50 .Op Fl X Ar profile
51 .Op Fl z Ar regex
52 .Op Fl -
53 .Op probe[,...]
54 .Op args ...
55 .Nm
56 .Fl l
57 .Op Fl fmnPqy
58 .Op Fl r Ar regex
59 .Op probe ...
60 .Nm
61 .Fl Q
62 .Op Fl 1qy
63 .Op Fl r Ar regex
64 .Sh DESCRIPTION
65 The
66 .Nm
67 utility uses
68 .Xr dtrace 1
69 to display process info when a given DTrace probe point is triggered.
70 Only the root user or users with
71 .Xr sudo 8
72 access can run this command.
73 .Pp
74 .Nm
75 automates the process of generating DTrace scripts to coalesce trace output by
76 date/time,
77 process info,
78 and
79 .Op optionally
80 probe-specific data.
81 .Pp
82 Output format without options is:
83 .Pp
84 .Dl date/time uid.gid execname[pid]: psargs
85 .Pp
86 For example,
87 the command
88 .Ql dwatch BEGIN
89 produces:
90 .Pp
91 .Dl INFO Watching 'dtrace:::BEGIN' ...
92 .Dl 2017 May 29 08:23:20 0.0 dtrace[60671]: dtrace -s /dev/stdin
93 .Pp
94 The
95 .Fl F
96 option causes
97 .Nm
98 to instead coalesce trace output by date/time,
99 process info,
100 and probe traversal.
101 .Pp
102 Output format with the
103 .Ql Fl F
104 option is:
105 .Pp
106 .Dl date/time uid.gid execname[pid]: {->,<-, |} prov:mod:func:name ...
107 .Pp
108 For example,
109 the command
110 .Ql dwatch -F BEGIN
111 produces:
112 .Pp
113 .Dl INFO Watching 'dtrace:::BEGIN' ...
114 .Dl 2017 May 29 21:34:41 0.0 dtrace[86593]:  | dtrace:::BEGIN ...
115 .Pp
116 The
117 .Fl R
118 option causes
119 .Nm
120 to display a process tree containing the parent,
121 grandparent,
122 and ancestor process info.
123 .Pp
124 Output format with the
125 .Ql Fl R
126 option is:
127 .Pp
128 .Dl date/time uid0.gid0 execname[pid0]: psargs0
129 .Dl " -+= pid3 uid3.gid3 psargs3"
130 .Dl "  \e\\-+= pid2 uid2.gid2 psargs2"
131 .Dl "    \e\\-+= pid1 uid1.gid1 psargs1"
132 .Dl "      \e\\-+= pid0 uid0.guid0 psargs0"
133 .Pp
134 For example,
135 the command
136 .Ql dwatch -R BEGIN
137 produces:
138 .Pp
139 .Dl INFO Watching 'dtrace:::BEGIN' ...
140 .Dl 2017 May 29 21:38:54 0.0 dtrace[86899]: dtrace -s /dev/stdin
141 .Dl " -+= 86855 604.604 -bash"
142 .Dl "  \e\\-+= 86857 604.604 /bin/sh /usr/sbin/dwatch -R BEGIN"
143 .Dl "    \e\\-+= 86897 0.0 sudo dtrace -s /dev/stdin"
144 .Dl "      \e\\-+= 86899 0.0 dtrace -s /dev/stdin"
145 .Pp
146 Of particular interest is the ability to filter using regular expressions.
147 The
148 .Ql Fl g Ar group ,
149 .Ql Fl p Ar pid ,
150 .Ql Fl r Ar regex ,
151 .Ql Fl u Ar user ,
152 and
153 .Ql Fl z Ar regex
154 options can be combined with
155 .Ql Fl R
156 to match on parent process criteria as well as current process info.
157 .Pp
158 In contrast,
159 the
160 .Ql Fl j Ar jail ,
161 and
162 .Ql Fl k Ar name
163 options apply only to the current process even if
164 .Ql Fl R
165 is given.
166 .Pp
167 The
168 .Ql Fl E Ar code
169 option gives the ability to customize probe-specific data.
170 For example,
171 the command:
172 .Pp
173 .Dl dwatch -E 'printf("%s", copyinstr(arg0))' chdir
174 .Pp
175 displays the path argument sent to
176 .Xr chdir 2
177 calls.
178 .Pp
179 Profiles can be written for more complex routines and/or convenience.
180 To list available profiles use the
181 .Ql Fl Q
182 option.
183 Use the
184 .Ql Fl X Ar profile
185 option to use a particular profile.
186 .Pp
187 For example,
188 the command
189 .Ql dwatch -X kill
190 displays arguments sent to
191 .Xr kill 2 .
192 .Sh OPTIONS
193 If a
194 .Ar probe
195 argument does not contain colon
196 .Pq Qo Li ":" Qc
197 and none of
198 .Ql Fl P ,
199 .Ql Fl m ,
200 .Ql Fl f ,
201 or
202 .Ql Fl n
203 are given,
204 the probe argument is intelligently mapped to its most-likely value.
205 Use
206 .Ql Nm Fl l Ar name
207 to see what probes will match a given name.
208 .Pp
209 Multiple probes must be given as a single
210 .Pq quoted
211 argument,
212 separated by comma and/or whitespace.
213 Any/all arguments following said probes will be passed to
214 .Xr dtrace 1
215 unmodified.
216 .Bl -tag -width "-c count"
217 .It Fl 1
218 Print one line per process/profile
219 .Pq Default; disables Ql Fl R .
220 .It Fl B Ar num
221 Maximum number of arguments to display
222 .Pq Default 64 .
223 .It Fl d
224 Debug.
225 Send
226 .Xr dtrace 1
227 script to stdout instead of executing.
228 .It Fl e
229 Exit after compiling request but prior to enabling probes.
230 .It Fl E Ar code
231 DTrace
232 .Ar code
233 for event details.
234 If `-',
235 read from stdin.
236 This allows customization of what is printed after date/time and process info.
237 By default,
238 the name and arguments of the program triggering the probe are shown.
239 Can be specified multiple times.
240 .It Fl f
241 Enable probes matching the specified function names.
242 .It Fl F
243 Coalesce trace output by probe.
244 .It Fl g Ar group
245 Group filter.
246 Only show processes matching
247 .Ar group
248 name/gid.
249 This can be an
250 .Xr awk 1
251 regular expression to match a numerical gid.
252 .It Fl j Ar jail
253 Jail filter.
254 Only show processes matching
255 .Ar jail
256 name/jid.
257 .It Fl k Ar name
258 Only show processes matching
259 .Ar name .
260 Can also be of the format
261 .Ql Li name*
262 to indicate
263 .Dq Li begins with ,
264 .Ql Li *name
265 to indicate
266 .Dq Li ends with ,
267 or
268 .Ql Li *name*
269 to indicate
270 .Dq Li contains .
271 Can be specified multiple times.
272 .It Fl K Ar num
273 Maximum directory depth to display
274 .Pq Default 64 .
275 .It Fl l
276 List available probes on standard output and exit.
277 .It Fl m
278 Enable probes matching the specified module names.
279 .It Fl X Ar profile
280 Load profile from DWATCH_PROFILES_PATH.
281 .It Fl n
282 Enable probes matching the specified probe names.
283 .It Fl N Ar count
284 Exit after
285 .Ar count
286 matching entries
287 .Pq Default 0 for disabled .
288 .It Fl o Ar file
289 Set output file.
290 If
291 .Ql Li - ,
292 the path
293 .Ql Li /dev/stdout
294 is used.
295 .It Fl O Ar cmd
296 Execute
297 .Ar cmd
298 for each event.
299 This can be any valid
300 .Xr sh 1
301 command.
302 The environment variables
303 .Ql Li $TAG
304 and
305 .Ql Li $DETAILS
306 are set for the given
307 .Ar cmd .
308 .It Fl p Ar pid
309 Process id filter.
310 Only show processes with matching
311 .Ar pid .
312 This can be an
313 .Xr awk 1
314 regular expression.
315 .It Fl P
316 Enable probe matching the specified provider name.
317 .It Fl q
318 Quiet.
319 Hide informational messages and all dtrace(1) errors.
320 .It Fl Q
321 List available profiles in DWATCH_PROFILES_PATH and exit.
322 .It Fl r Ar regex
323 Filter.
324 Only show blocks matching
325 .Xr awk 1
326 regular expression.
327 .It Fl R
328 Show parent,
329 grandparent,
330 and ancestor of process.
331 .It Fl t Ar test
332 Test clause
333 .Pq predicate
334 to limit events
335 .Pq Default none .
336 Can be specified multiple times.
337 .It Fl T Ar time
338 Timeout.
339 The format is
340 .Ql Li #[smhd]
341 or just
342 .Ql Li #
343 for seconds.
344 .It Fl u Ar user
345 User filter.
346 Only show processes matching
347 .Ar user
348 name/uid.
349 This can be an
350 .Xr awk 1
351 regular expression to match a numerical UID.
352 .It Fl v
353 Verbose.
354 Show all errors from
355 .Xr dtrace 1 .
356 .It Fl V
357 Report
358 .Nm
359 version on standard output and exit.
360 .It Fl w
361 Permit destructive actions
362 .Pq copyout*, stop, panic, etc. .
363 .It Fl x
364 Trace.
365 Print
366 .Ql Li <probe-id>
367 when a probe is triggered.
368 .It Fl y
369 Always treat stdout as console
370 .Pq enable colors/columns/etc. .
371 .It Fl z Ar regex
372 Only show processes matching
373 .Xr awk 1
374 regular expression.
375 .El
376 .Sh PROFILES
377 Profiles customize the data printed during events.
378 Profiles are loaded from a colon-separated list of directories in
379 .Ev DWATCH_PROFILES_PATH .
380 This is an incomplete list of profiles with basic descriptions:
381 .Bl -tag -width "vop_readdir"
382 .It chmod
383 Print mode and path from
384 .Xr chmod 2 ,
385 .Xr lchmod 2 ,
386 .Xr fchmodat 2
387 .It errno
388 Print non-zero errno results from system calls
389 .It io
390 Print disk I/O details provided by
391 .Xr dtrace_io 4
392 .It ip
393 Print IPv4 and IPv6 details provided by
394 .Xr dtrace_ip 4
395 .It kill
396 Print signal and pid from
397 .Xr kill 2
398 .It nanosleep
399 Print requested time from
400 .Xr nanosleep 2
401 .It open
402 Print path from
403 .Xr open 2 ,
404 .Xr openat 2
405 .It proc
406 Print process execution details provided by
407 .Xr dtrace_proc 4
408 .It proc-signal
409 Print process signal details provided by
410 .Xr dtrace_proc 4
411 .It rw
412 Print buffer contents from
413 .Xr read 2 ,
414 .Xr write 2
415 .It sched
416 Print CPU scheduling details provided by
417 .Xr dtrace_sched 4
418 .It tcp
419 Print TCP address/port details provided by
420 .Xr dtrace_tcp 4
421 .It tcp-io
422 Print TCP I/O details provided by
423 .Xr dtrace_tcp 4
424 .It udp
425 Print UDP I/O details provided by
426 .Xr dtrace_udp 4
427 .It vop_create
428 Print filesystem paths being created by
429 .Xr VOP_CREATE 9
430 .It vop_lookup
431 Print filesystem paths being looked-up by
432 .Xr VOP_LOOKUP 9
433 .It vop_mkdir
434 Print directory paths being created by
435 .Xr VOP_MKDIR 9
436 .It vop_mknod
437 Print device node paths being created by
438 .Xr VOP_MKNOD 9
439 .It vop_readdir
440 Print directory paths being read by
441 .Xr VOP_READDIR 9
442 .It vop_remove
443 Print filesystem paths being removed by
444 .Xr VOP_REMOVE 9
445 .It vop_rename
446 Print filesystem paths being renamed by
447 .Xr VOP_RENAME 9
448 .It vop_rmdir
449 Print directory paths being removed by
450 .Xr VOP_RMDIR 9
451 .It vop_symlink
452 Print symlink paths being created by
453 .Xr VOP_SYMLINK 9
454 .El
455 .Sh ENVIRONMENT
456 These environment variables affect the execution of
457 .Nm :
458 .Bl -tag -width "DWATCH_PROFILES_PATH"
459 .It Ev DWATCH_PROFILES_PATH
460 If
461 .Ev DWATCH_PROFILES_PATH
462 is set,
463 .Nm
464 searches for profiles in the colon-separated list of directories in that
465 variable instead of the default
466 .Ql Li /usr/libexec/dwatch:/usr/local/libexec/dwatch .
467 If set to NULL,
468 profiles are not loaded.
469 .El
470 .Sh EXIT STATUS
471 .Ex -std
472 .Sh EXAMPLES
473 Watch processes entering system CPU scheduler.
474 .Bd -literal -offset indent
475 dwatch on-cpu
476 .Ed
477 .Pp
478 List available profiles,
479 one line per profile.
480 .Bd -literal -offset indent
481 dwatch -1 -Q
482 .Ed
483 .Pp
484 Do not execute
485 .Xr dtrace 1
486 but display script on stdout and exit.
487 .Bd -literal -offset indent
488 dwatch -d fsync
489 .Ed
490 .Pp
491 Compile and test but do not execute code generated with given probe.
492 .Bd -literal -offset indent
493 dwatch -e test_probe
494 .Ed
495 .Pp
496 Print argument one being passed to each call of zfs_sync().
497 .Bd -literal -offset indent
498 dwatch -E 'printf("%i", arg1)' zfs_sync
499 .Ed
500 .Pp
501 Watch all functions named
502 .Ql Li read .
503 .Bd -literal -offset indent
504 dwatch -f read
505 .Ed
506 .Pp
507 Watch all probe traversal.
508 .Bd -literal -offset indent
509 dwatch -F :
510 .Ed
511 .Pp
512 Watch syscall probe traversal.
513 .Bd -literal -offset indent
514 dwatch -F syscall
515 .Ed
516 .Pp
517 Display only processes belonging to wheel super-group.
518 .Bd -literal -offset indent
519 dwatch -g wheel execve
520 .Ed
521 .Pp
522 Display only processes belonging to groups
523 .Ql Li daemon
524 or
525 .Ql Li nobody .
526 .Bd -literal -offset indent
527 dwatch -g '1|65534' execve
528 .Ed
529 .Pp
530 Ignore jails,
531 displaying only base system processes.
532 .Bd -literal -offset indent
533 dwatch -j 0 execve
534 .Ed
535 .Pp
536 Display only processes running inside the jail named
537 .Ql Li myjail .
538 .Bd -literal -offset indent
539 dwatch -j myjail execve
540 .Ed
541 .Pp
542 Watch syscall traversal by ruby processes.
543 .Bd -literal -offset indent
544 dwatch -k 'ruby*' -F syscall
545 .Ed
546 .Pp
547 Watch syscall traversal by processes containing
548 .Ql Li daemon
549 in their name.
550 .Bd -literal -offset indent
551 dwatch -k '*daemon*' -F syscall
552 .Ed
553 .Pp
554 Watch signals being passed to
555 .Xr kill 2 .
556 .Bd -literal -offset indent
557 dwatch -X kill
558 .Ed
559 .Pp
560 Watch signals being passed between
561 .Xr bash 1
562 and
563 .Xr vi 1 .
564 .Bd -literal -offset indent
565 dwatch -k bash -k vi -X kill
566 .Ed
567 .Pp
568 Display a list of unique functions available.
569 .Bd -literal -offset indent
570 dwatch -l -f
571 .Ed
572 .Pp
573 List available probes for functions ending in
574 .Ql Li read .
575 .Bd -literal -offset indent
576 dwatch -l -f '*read'
577 .Ed
578 .Pp
579 List available probes ending in
580 .Dq Li read .
581 .Bd -literal -offset indent
582 dwatch -l -r 'read$'
583 .Ed
584 .Pp
585 Display a list of unique providers.
586 .Bd -literal -offset indent
587 dwatch -l -P
588 .Ed
589 .Pp
590 Watch paths being removed by
591 .Xr VOP_REMOVE 9 .
592 .Bd -literal -offset indent
593 dwatch -X vop_remove
594 .Ed
595 .Pp
596 Watch the name
597 .Ql Li read
598 instead of the function
599 .Ql Li read .
600 The
601 .Nm
602 selection algorithm will commonly favor the function named
603 .Ql Li read
604 when not given a type
605 .Pq using So Fl P Sc , So Fl m Sc , So Fl f Sc , or So Fl n Sc
606 because there are more probes matching the function named
607 .Ql Li read
608 than probes matching
609 .Ql Li read
610 for any other type.
611 .Bd -literal -offset indent
612 dwatch -n read
613 .Ed
614 .Pp
615 Display the first process to call
616 .Xr kill 2
617 and then exit.
618 .Bd -literal -offset indent
619 dwatch -N 1 kill
620 .Ed
621 .Pp
622 Watch processes forked by pid 1234.
623 .Bd -literal -offset indent
624 dwatch -p 1234 execve
625 .Ed
626 .Pp
627 Watch processes forked by either pid 1234 or pid 5678.
628 .Bd -literal -offset indent
629 dwatch -p '1234|5678' execve
630 .Ed
631 .Pp
632 Watch the provider
633 .Ql Li random
634 instead of the function
635 .Ql Li random .
636 The
637 .Nm
638 selection algorithm will commonly favor the function named
639 .Ql Li random
640 when not given a type
641 .Pq using So Fl P Sc , So Fl m Sc , So Fl f Sc , or So Fl n Sc
642 because there are more probes matching the function named
643 .Ql Li random
644 than probes matching the provider named
645 .Ql Li random .
646 .Bd -literal -offset indent
647 dwatch -P random
648 .Ed
649 .Pp
650 Display available profiles matching
651 .Ql Li vop .
652 .Bd -literal -offset indent
653 dwatch -Q -r vop
654 .Ed
655 .Pp
656 Watch
657 .Xr VOP_LOOKUP 9
658 paths containing
659 .Ql Li /lib/ .
660 .Bd -literal -offset indent
661 dwatch -r /lib/ -X vop_lookup
662 .Ed
663 .Pp
664 Show process tree for each command as it is executed.
665 .Bd -literal -offset indent
666 dwatch -R execve
667 .Ed
668 .Pp
669 Watch processes forked by pid 1234 or children thereof.
670 .Bd -literal -offset indent
671 dwatch -R -p 1234 execve
672 .Ed
673 .Pp
674 Display processes calling
675 .Xr write 2
676 with
677 .Dq nbytes
678 less than 10.
679 .Bd -literal -offset indent
680 dwatch -t 'arg2<10' -E 'printf("%d",arg2)' write
681 .Ed
682 .Pp
683 Display
684 .Xr write 2
685 buffer when
686 .Dq execname
687 is not
688 .Ql Li dtrace
689 and
690 .Dq nbytes
691 is less than 10.
692 .Bd -literal -offset indent
693 dwatch -X write -t 'execname != "dtrace" && this->nbytes < 10'
694 .Ed
695 .Pp
696 Watch
697 .Ql Li statfs
698 for 5 minutes and exit.
699 .Bd -literal -offset indent
700 dwatch -T 5m statfs
701 .Ed
702 .Pp
703 Display only processes belonging to the root super-user.
704 .Bd -literal -offset indent
705 dwatch -u root execve
706 .Ed
707 .Pp
708 Display only processes belonging to users
709 .Ql Li daemon
710 or
711 .Ql Li nobody .
712 .Bd -literal -offset indent
713 dwatch -u '1|65534' execve
714 .Ed
715 .Pp
716 Print version and exit.
717 .Bd -literal -offset indent
718 dwatch -V
719 .Ed
720 .Pp
721 View the first 100 scheduler preemptions.
722 .Bd -literal -offset indent
723 dwatch -y -N 100 preempt | less -R
724 .Ed
725 .Pp
726 Display processes matching either
727 .Dq Li mkdir
728 or
729 .Dq Li rmdir .
730 .Bd -literal -offset indent
731 dwatch -z '(mk|rm)dir' execve
732 .Ed
733 .Pp
734 Run a command and watch network activity only while that command runs.
735 .Bd -literal -offset indent
736 dwatch -X tcp -- -c "nc -zvw10 google.com 22"
737 .Ed
738 .Pp
739 Watch
740 .Xr open 2
741 and
742 .Xr openat 2
743 calls only while pid 1234 is active.
744 .Bd -literal -offset indent
745 dwatch -X open -- -p 1234
746 .Ed
747 .Pp
748 Watch probe traversal for a given command.
749 Note that
750 .Dq Li -c true
751 is passed to
752 .Xr dtrace 1
753 since it appears after the
754 .Nm
755 probe argument.
756 .Bd -literal -offset indent
757 dwatch -F 'pid$target:::entry' -c true
758 .Ed
759 .Sh SEE ALSO
760 .Xr dtrace 1
761 .Sh HISTORY
762 .Nm
763 first appeared in
764 .Fx 11.2 .
765 .Sh AUTHORS
766 .An Devin Teske Aq Mt dteske@FreeBSD.org