xref: /freebsd/usr.bin/ktrace/ktrace.1 (revision 22cf89c938886d14f5796fc49f9f020c23ea8eaf)
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.\"	@(#)ktrace.1	8.1 (Berkeley) 6/6/93
29.\"
30.Dd August 26, 2019
31.Dt KTRACE 1
32.Os
33.Sh NAME
34.Nm ktrace
35.Nd enable kernel process tracing
36.Sh SYNOPSIS
37.Nm
38.Op Fl aCcdi
39.Op Fl f Ar trfile
40.Op Fl g Ar pgrp | Fl p Ar pid
41.Op Fl t Ar trstr
42.Nm
43.Op Fl adi
44.Op Fl f Ar trfile
45.Op Fl t Ar trstr
46.Ar command
47.Sh DESCRIPTION
48The
49.Nm
50utility enables kernel trace logging for the specified processes.
51Kernel trace data is logged to the file
52.Pa ktrace.out .
53The kernel operations that are traced include system calls, namei
54translations, signal processing, and
55.Tn I/O .
56.Pp
57Once tracing is enabled on a process, trace data will be logged until
58either the process exits or the trace point is cleared.
59A traced process can generate enormous amounts of log data quickly;
60It is strongly suggested that users memorize how to disable tracing before
61attempting to trace a process.
62The following command is sufficient to disable tracing on all user-owned
63processes, and, if executed by root, all processes:
64.Pp
65.Dl \&$ ktrace -C
66.Pp
67The trace file is not human readable; use
68.Xr kdump 1
69to decode it.
70.Pp
71The utility may be used only with a kernel that has been built with the
72.Dq KTRACE
73option in the kernel configuration file.
74.Pp
75The options are:
76.Bl -tag -width indent
77.It Fl a
78Append to the trace file instead of recreating it.
79.It Fl C
80Disable tracing on all user-owned processes, and, if executed by root, all
81processes in the system.
82.It Fl c
83Clear the specified trace points associated with the given file or processes.
84.It Fl d
85Descendants; perform the operation for all current children of the
86designated processes.
87See also the
88.Fl i
89option.
90.It Fl f Ar trfile
91Log trace records to
92.Ar trfile
93instead of
94.Pa ktrace.out .
95.It Fl g Ar pgid
96Enable (disable) tracing on all processes in the process group (only one
97.Fl g
98flag is permitted).
99.It Fl i
100Inherit; pass the trace flags to all future children of the designated
101processes.
102See also the
103.Fl d
104option.
105.It Fl p Ar pid
106Enable (disable) tracing on the indicated process id (only one
107.Fl p
108flag is permitted).
109.It Fl t Ar trstr
110Specify the list of trace points to enable or disable, one per letter.
111If an explicit list is not specified, the default set of trace points is used.
112.Pp
113The following trace points are supported:
114.Pp
115.Bl -tag -width flag -compact
116.It Cm c
117trace system calls
118.It Cm f
119trace page faults
120.It Cm i
121trace
122.Tn I/O
123.It Cm n
124trace namei translations
125.It Cm p
126trace capability check failures
127.It Cm s
128trace signal processing
129.It Cm t
130trace various structures
131.It Cm u
132userland traces generated by
133.Xr utrace 2
134.It Cm w
135context switches
136.It Cm y
137trace
138.Xr sysctl 3
139requests
140.It Cm +
141trace the default set of trace points -
142.Cm c , i , n , p , s , t , u , y
143.El
144.It Ar command
145Execute
146.Ar command
147with the specified trace flags.
148.El
149.Pp
150The
151.Fl p ,
152.Fl g ,
153and
154.Ar command
155options are mutually exclusive.
156.Sh EXAMPLES
157Run "make", then trace it and any child processes:
158.Dl $ ktrace -i make
159.Pp
160Trace all kernel operations of process id 34:
161.Dl $ ktrace -p 34
162.Pp
163Trace all kernel operations of processes in process group 15 and
164pass the trace flags to all current and future children:
165.Dl $ ktrace -idg 15
166.Pp
167Disable all tracing of process 65:
168.Dl $ ktrace -cp 65
169.Pp
170Disable tracing signals on process 70 and all current children:
171.Dl $ ktrace -t s -cdp 70
172.Pp
173Enable tracing of
174.Tn I/O
175on process 67:
176.Dl $ ktrace -ti -p 67
177.Pp
178Disable all tracing to the file "tracedata":
179.Dl $ ktrace -c -f tracedata
180.Pp
181Disable tracing of all user-owned processes:
182.Dl $ ktrace -C
183.Sh SEE ALSO
184.Xr dtrace 1 ,
185.Xr kdump 1 ,
186.Xr truss 1 ,
187.Xr ktrace 2 ,
188.Xr utrace 2
189.Sh HISTORY
190The
191.Nm
192command appeared in
193.Bx 4.4 .
194.Sh BUGS
195Only works if
196.Ar trfile
197is a regular file.
198