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