xref: /freebsd/usr.bin/ktrace/ktrace.1 (revision 2e3f49888ec8851bafb22011533217487764fdb0)
1.\" Copyright (c) 1990, 1993
2.\"	The Regents of the University of California.  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.\" 3. Neither the name of the University nor the names of its contributors
13.\"    may be used to endorse or promote products derived from this software
14.\"    without specific prior written permission.
15.\"
16.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26.\" SUCH DAMAGE.
27.\"
28.Dd August 26, 2019
29.Dt KTRACE 1
30.Os
31.Sh NAME
32.Nm ktrace
33.Nd enable kernel process tracing
34.Sh SYNOPSIS
35.Nm
36.Op Fl aCcdi
37.Op Fl f Ar trfile
38.Op Fl g Ar pgrp | Fl p Ar pid
39.Op Fl t Ar trstr
40.Nm
41.Op Fl adi
42.Op Fl f Ar trfile
43.Op Fl t Ar trstr
44.Ar command
45.Sh DESCRIPTION
46The
47.Nm
48utility enables kernel trace logging for the specified processes.
49Kernel trace data is logged to the file
50.Pa ktrace.out .
51The kernel operations that are traced include system calls, namei
52translations, signal processing, and
53.Tn I/O .
54.Pp
55Once tracing is enabled on a process, trace data will be logged until
56either the process exits or the trace point is cleared.
57A traced process can generate enormous amounts of log data quickly;
58It is strongly suggested that users memorize how to disable tracing before
59attempting to trace a process.
60The following command is sufficient to disable tracing on all user-owned
61processes, and, if executed by root, all processes:
62.Pp
63.Dl \&$ ktrace -C
64.Pp
65The trace file is not human readable; use
66.Xr kdump 1
67to decode it.
68.Pp
69The utility may be used only with a kernel that has been built with the
70.Dq KTRACE
71option in the kernel configuration file.
72.Pp
73The options are:
74.Bl -tag -width indent
75.It Fl a
76Append to the trace file instead of recreating it.
77.It Fl C
78Disable tracing on all user-owned processes, and, if executed by root, all
79processes in the system.
80.It Fl c
81Clear the specified trace points associated with the given file or processes.
82.It Fl d
83Descendants; perform the operation for all current children of the
84designated processes.
85See also the
86.Fl i
87option.
88.It Fl f Ar trfile
89Log trace records to
90.Ar trfile
91instead of
92.Pa ktrace.out .
93.It Fl g Ar pgid
94Enable (disable) tracing on all processes in the process group (only one
95.Fl g
96flag is permitted).
97.It Fl i
98Inherit; pass the trace flags to all future children of the designated
99processes.
100See also the
101.Fl d
102option.
103.It Fl p Ar pid
104Enable (disable) tracing on the indicated process id (only one
105.Fl p
106flag is permitted).
107.It Fl t Ar trstr
108Specify the list of trace points to enable or disable, one per letter.
109If an explicit list is not specified, the default set of trace points is used.
110.Pp
111The following trace points are supported:
112.Pp
113.Bl -tag -width flag -compact
114.It Cm c
115trace system calls
116.It Cm f
117trace page faults
118.It Cm i
119trace
120.Tn I/O
121.It Cm n
122trace namei translations
123.It Cm p
124trace capability check failures
125.It Cm s
126trace signal processing
127.It Cm t
128trace various structures
129.It Cm u
130userland traces generated by
131.Xr utrace 2
132.It Cm w
133context switches
134.It Cm y
135trace
136.Xr sysctl 3
137requests
138.It Cm +
139trace the default set of trace points -
140.Cm c , i , n , p , s , t , u , y
141.El
142.It Ar command
143Execute
144.Ar command
145with the specified trace flags.
146.El
147.Pp
148The
149.Fl p ,
150.Fl g ,
151and
152.Ar command
153options are mutually exclusive.
154.Sh EXAMPLES
155Run "make", then trace it and any child processes:
156.Dl $ ktrace -i make
157.Pp
158Trace all kernel operations of process id 34:
159.Dl $ ktrace -p 34
160.Pp
161Trace all kernel operations of processes in process group 15 and
162pass the trace flags to all current and future children:
163.Dl $ ktrace -idg 15
164.Pp
165Disable all tracing of process 65:
166.Dl $ ktrace -cp 65
167.Pp
168Disable tracing signals on process 70 and all current children:
169.Dl $ ktrace -t s -cdp 70
170.Pp
171Enable tracing of
172.Tn I/O
173on process 67:
174.Dl $ ktrace -ti -p 67
175.Pp
176Disable all tracing to the file "tracedata":
177.Dl $ ktrace -c -f tracedata
178.Pp
179Disable tracing of all user-owned processes:
180.Dl $ ktrace -C
181.Sh SEE ALSO
182.Xr dtrace 1 ,
183.Xr kdump 1 ,
184.Xr truss 1 ,
185.Xr ktrace 2 ,
186.Xr utrace 2
187.Sh HISTORY
188The
189.Nm
190command appeared in
191.Bx 4.4 .
192.Sh BUGS
193Only works if
194.Ar trfile
195is a regular file.
196