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