1.\" $NetBSD: ktrace.1,v 1.39 2007/08/27 16:35:47 dsl 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 August 27, 2007 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 i 185trace 186.Tn I/O 187.It Cm l 188trace Mach out of line data when running Mach binaries with COMPAT_MACH 189(currently limited to i386 and powerpc ports). 190.It Cm m 191trace Mach messages when running Mach binaries with COMPAT_MACH 192(currently limited to i386 and powerpc ports). 193.It Cm n 194trace namei translations 195.It Cm S 196trace MIB access (sysctl) 197.It Cm s 198trace signal processing 199.\" .It Cm U 200.\" trace scheduler activations upcall data 201.It Cm u 202trace user data 203.It Cm v 204trace exec environment 205.It Cm w 206trace context switches 207.It Cm + 208trace the default set of trace points (c, e, i, l, m, n, s, u) 209.It Cm - 210do not trace following trace points 211.El 212.It Fl e Ar emulation 213If an emulation of a process is unknown, 214interpret system call maps assuming the named emulation instead of 215default "netbsd". 216.It Ar command 217Execute 218.Ar command 219with the specified trace flags. 220.It Fl v Ar version 221Determines the 222.Ar version 223of the file generated. 224Version 0 is the compatible ktrace format, and 225version 1 is the new format with lwp IDs and nanosecond (instead of 226microsecond) timestamps. 227.El 228.Pp 229The 230.Fl p , 231.Fl g , 232and 233.Ar command 234options are mutually exclusive. 235The 236.Fl R 237and 238.Fl T 239options are also mutually exclusive. 240.Sh EXAMPLES 241# trace all kernel operations of process id 34 242.Dl $ ktrace -p 34 243.Pp 244.Bd -literal 245# trace all kernel operations of processes in process group 15 and 246# pass the trace flags to all current and future children 247.Ed 248.Dl $ ktrace -idg 15 249.Pp 250# disable all tracing of process 65 251.Dl $ ktrace -cp 65 252.Pp 253# disable tracing signals on process 70 and all current children 254.Dl $ ktrace -t s -cdp 70 255.Pp 256# enable tracing of 257.Tn I/O 258on process 67 259.Dl $ ktrace -ti -p 67 260.Pp 261# run the command "w", tracing only system calls 262.Dl $ ktrace -tc w 263.Pp 264# disable all tracing to the file "tracedata" 265.Dl $ ktrace -c -f tracedata 266.Pp 267# disable tracing of all processes owned by the user 268.Dl $ ktrace -C 269.Pp 270# run the command "w", displaying to standard output 271.Dl $ ktruss w 272.Pp 273# trace process 42 and log the records to "ktruss.out" 274.Dl $ ktruss -p 42 -o ktruss.out 275.Pp 276# poll ktruss.out for available records and print them 277.Dl $ ktruss -lf ktruss.out 278.Sh SEE ALSO 279.Xr kdump 1 , 280.Xr ktrace 2 281.Sh HISTORY 282The 283.Nm 284command appears in 285.Bx 4.4 . 286