xref: /netbsd-src/usr.bin/ktrace/ktrace.1 (revision bdc22b2e01993381dcefeff2bc9b56ca75a4235c)
1.\"	$NetBSD: ktrace.1,v 1.43 2015/01/08 22:03:42 riastradh Exp $
2.\"
3.\" Copyright (c) 1990, 1993
4.\"	The Regents of the University of California.  All rights reserved.
5.\"
6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions
8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright
10.\"    notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\"    notice, this list of conditions and the following disclaimer in the
13.\"    documentation and/or other materials provided with the distribution.
14.\" 3. Neither the name of the University nor the names of its contributors
15.\"    may be used to endorse or promote products derived from this software
16.\"    without specific prior written permission.
17.\"
18.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28.\" SUCH DAMAGE.
29.\"
30.\"	@(#)ktrace.1	8.1 (Berkeley) 6/6/93
31.\"
32.Dd January 8, 2015
33.Dt KTRACE 1
34.Os
35.Sh NAME
36.Nm ktrace , ktruss
37.Nd enable kernel process tracing
38.Sh SYNOPSIS
39.Nm
40.Op Fl aCcdins
41.Op Fl f Ar trfile
42.Op Fl g Ar pgrp
43.Op Fl p Ar pid
44.Op Fl t Ar trstr
45.Nm
46.Op Fl adis
47.Op Fl f Ar trfile
48.Op Fl t Ar trstr
49.Ar command
50.Nm ktruss
51.Op Fl aCcdilnRT
52.Op Fl e Ar emulation
53.Op Fl f Ar infile
54.Op Fl g Ar pgrp
55.Op Fl m Ar maxdata
56.Op Fl o Ar outfile
57.Op Fl p Ar pid
58.Op Fl t Ar trstr
59.Nm ktruss
60.Op Fl adinRT
61.Op Fl e Ar emulation
62.Op Fl m Ar maxdata
63.Op Fl o Ar outfile
64.Op Fl t Ar trstr
65.Op Fl v Ar vers
66command
67.Sh DESCRIPTION
68.Nm
69enables kernel trace logging for the specified processes.
70Kernel trace data is logged to the file
71.Pa ktrace.out .
72The kernel operations that are traced include system calls, namei
73translations, signal processing, and
74.Tn I/O .
75.Pp
76Once tracing is enabled on a process, trace data will be logged until
77either the process exits or the trace point is cleared.
78A traced process can generate enormous amounts of log data quickly;
79It is strongly suggested that users memorize how to disable tracing before
80attempting to trace a process.
81The following command is sufficient to disable tracing on all user owned
82processes, and, if executed by root, all processes:
83.Pp
84.Dl \&$ ktrace -C
85.Pp
86The trace file is not human readable; use
87.Xr kdump 1
88to decode it.
89.Pp
90.Nm ktruss
91is functionally the same as
92.Nm ktrace
93except that trace output is printed
94on standard output or to the file specified with the
95.Fl o
96option.
97.Nm ktruss
98is useful to see the kernel operations interleaved with
99the program output.
100.Pp
101The options are as follows:
102.Bl -tag -width indent
103.It Fl a
104Append to the trace file instead of truncating it.
105.It Fl C
106Disable tracing on all user owned processes, and, if executed by root, all
107processes in the system.
108.It Fl c
109Clear the trace points associated with the specified file or processes.
110.It Fl d
111Descendants; perform the operation for all current children of the
112designated processes.
113.It Fl f Ar trfile
114Log trace records to
115.Ar trfile
116instead of
117.Pa ktrace.out .
118.It Fl f Ar infile
119Read the trace records from
120.Ar infile
121and print them in a human readable format to standard out.
122.It Fl g Ar pgid
123Enable (disable) tracing on all processes in the process group (only one
124.Fl g
125flag is permitted).
126.It Fl i
127Inherit; pass the trace flags to all future children of the designated
128processes.
129.It Fl l
130Poll the trace file for new data and print it to standard out.
131Only for use together with the
132.Fl f
133option.
134.It Fl m Ar maxdata
135Print at most
136.Ar maxdata
137bytes of data.
138This is used for pointer type arguments, e.g., strings.
139The data will be escaped in C-style unless
140.Fl x
141is specified when it will be output in hex and ascii.
142.It Fl n
143Stop tracing if attempts to write to the trace file would block.
144This option always affects
145.Nm ktruss
146and only affects
147.Nm ktrace
148when writing to
149.Dv stdout .
150If this flag is not set, then the traced program will block until it can
151write more data to the trace file descriptor.
152.It Fl o Ar outfile
153Log trace records to
154.Ar outfile .
155Without this option
156.Nm ktruss
157will print its output in a human
158readable format to standard out.
159.It Fl p Ar pid
160Enable (disable) tracing on the indicated process id (only one
161.Fl p
162flag is permitted).
163.It Fl s
164Write to the trace file with synchronized I/O.
165.It Fl R
166Display relative time stamps to output.
167.It Fl T
168Same as the
169.Fl R
170option, but use absolute timestamps instead.
171.It Fl t Ar trstr
172The string argument represents the kernel trace points, one per letter.
173The following table equates the letters with the tracepoints:
174.Pp
175.Bl -tag -width flag -compact
176.It Cm A
177trace all tracepoints
178.It Cm a
179trace exec arguments
180.It Cm c
181trace system calls
182.It Cm e
183trace emulation changes
184.It Cm f
185trace open file descriptors after exec
186.It Cm i
187trace
188.Tn I/O
189.It Cm n
190trace namei translations
191.It Cm S
192trace MIB access (sysctl)
193.It Cm s
194trace signal processing
195.\" .It Cm U
196.\" trace scheduler activations upcall data
197.It Cm u
198trace user data
199.It Cm v
200trace exec environment
201.It Cm w
202trace context switches
203.It Cm +
204trace the default set of trace points (c, e, i, n, s, u)
205.It Cm -
206do not trace following trace points
207.El
208.It Fl e Ar emulation
209If an emulation of a process is unknown,
210interpret system call maps assuming the named emulation instead of
211default "netbsd".
212.It Ar command
213Execute
214.Ar command
215with the specified trace flags.
216.It Fl v Ar version
217Determines the
218.Ar version
219of the file generated.
220Version 0 is the compatible ktrace format, and
221version 1 is the new format with lwp IDs and nanosecond (instead of
222microsecond) timestamps.
223.El
224.Pp
225The
226.Fl p ,
227.Fl g ,
228and
229.Ar command
230options are mutually exclusive.
231The
232.Fl R
233and
234.Fl T
235options are also mutually exclusive.
236.Sh EXAMPLES
237# trace all kernel operations of process id 34
238.Dl $ ktrace -p 34
239.Pp
240.Bd -literal
241# trace all kernel operations of processes in process group 15 and
242# pass the trace flags to all current and future children
243.Ed
244.Dl $ ktrace -idg 15
245.Pp
246# disable all tracing of process 65
247.Dl $ ktrace -cp 65
248.Pp
249# disable tracing signals on process 70 and all current children
250.Dl $ ktrace -t s -cdp 70
251.Pp
252# enable tracing of
253.Tn I/O
254on process 67
255.Dl $ ktrace -ti -p 67
256.Pp
257# run the command "w", tracing only system calls
258.Dl $ ktrace -tc w
259.Pp
260# disable all tracing to the file "tracedata"
261.Dl $ ktrace -c -f tracedata
262.Pp
263# disable tracing of all processes owned by the user
264.Dl $ ktrace -C
265.Pp
266# run the command "w", displaying to standard output
267.Dl $ ktruss w
268.Pp
269# trace process 42 and log the records to "ktruss.out"
270.Dl $ ktruss -p 42 -o ktruss.out
271.Pp
272# poll ktruss.out for available records and print them
273.Dl $ ktruss -lf ktruss.out
274.Sh SEE ALSO
275.Xr kdump 1 ,
276.Xr ktrace 2
277.Sh HISTORY
278The
279.Nm
280command appears in
281.Bx 4.4 .
282