1.\" $NetBSD: ktrace.1,v 1.24 2003/08/07 11:14:14 agc 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 July 17, 2003 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 aCcdis 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 aCcdilRT 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 adiRT 61.Op Fl e Ar emulation 62.Op Fl m Ar maxdata 63.Op Fl o Ar outfile 64.Op Fl t Ar trstr 65command 66.Sh DESCRIPTION 67.Nm 68enables kernel trace logging for the specified processes. 69Kernel trace data is logged to the file 70.Pa ktrace.out . 71The kernel operations that are traced include system calls, namei 72translations, signal processing, and 73.Tn I/O . 74.Pp 75Once tracing is enabled on a process, trace data will be logged until 76either the process exits or the trace point is cleared. 77A traced process can generate enormous amounts of log data quickly; 78It is strongly suggested that users memorize how to disable tracing before 79attempting to trace a process. 80The following command is sufficient to disable tracing on all user owned 81processes, and, if executed by root, all processes: 82.Pp 83.Dl \&$ ktrace -C 84.Pp 85The trace file is not human readable; use 86.Xr kdump 1 87to decode it. 88.Pp 89.Nm ktruss 90is functionally the same as 91.Nm ktrace 92except that trace output is printed 93on standard output or to the file specified with the 94.Fl o 95option. 96.Nm ktruss 97is useful to see the kernel operations interleaved with 98the program output. 99.Pp 100The options are as follows: 101.Bl -tag -width indent 102.It Fl a 103Append to the trace file instead of truncating it. 104.It Fl C 105Disable tracing on all user owned processes, and, if executed by root, all 106processes in the system. 107.It Fl c 108Clear the trace points associated with the specified file or processes. 109.It Fl d 110Descendants; perform the operation for all current children of the 111designated processes. 112.It Fl f Ar trfile 113Log trace records to 114.Ar trfile 115instead of 116.Pa ktrace.out . 117.It Fl f Ar infile 118Read the trace records from 119.Ar infile 120and print them in a human readable format to standard out. 121.It Fl g Ar pgid 122Enable (disable) tracing on all processes in the process group (only one 123.Fl g 124flag is permitted). 125.It Fl i 126Inherit; pass the trace flags to all future children of the designated 127processes. 128.It Fl l 129Poll the trace file for new data and print it to standard out. 130Only for use together with the 131.Fl f 132option. 133.It Fl m Ar maxdata 134Print at most 135.Ar maxdata 136bytes of data. 137This is used for pointer type arguments, e.g., strings. 138The data will be escaped in C-style unless 139.Fl x 140is specified when it will be output in hex and ascii. 141.It Fl o Ar outfile 142Log trace records to 143.Ar outfile . 144Without this option ktruss will print its output in a human 145readable format to standard out. 146.It Fl p Ar pid 147Enable (disable) tracing on the indicated process id (only one 148.Fl p 149flag is permitted). 150.It Fl s 151Write to the trace file with synchronized I/O. 152.It Fl R 153Display relative time stamps to output. 154.It Fl T 155Same as the 156.Fl R 157option, but use absolute timestamps instead. 158.It Fl t Ar trstr 159The string argument represents the kernel trace points, one per letter. 160The following table equates the letters with the tracepoints: 161.Pp 162.Bl -tag -width flag -compact 163.It Cm A 164trace all tracepoints 165.It Cm a 166trace exec arguments 167.It Cm c 168trace system calls 169.It Cm e 170trace emulation changes 171.It Cm i 172trace 173.Tn I/O 174.It Cm m 175trace Mach messages when running Mach binaries with COMPAT_MACH 176(currently limited to i386 and powerpc ports). 177.It Cm n 178trace namei translations 179.It Cm s 180trace signal processing 181.It Cm u 182trace user data 183.It Cm v 184trace exec environment 185.It Cm w 186trace context switches 187.It Cm + 188trace the default set of trace points (c, e, i, m, n, s, u) 189.It Cm - 190do not trace following trace points 191.El 192.It Fl e Ar emulation 193If an emulation of a process is unknown, 194interpret system call maps assuming the named emulation instead of 195default "netbsd". 196.It Ar command 197Execute 198.Ar command 199with the specified trace flags. 200.El 201.Pp 202The 203.Fl p , 204.Fl g , 205and 206.Ar command 207options are mutually exclusive. 208The 209.Fl R 210and 211.Fl T 212options are also mutually exclusive. 213.Sh EXAMPLES 214# trace all kernel operations of process id 34 215.Dl $ ktrace -p 34 216.Pp 217.Bd -literal 218# trace all kernel operations of processes in process group 15 and 219# pass the trace flags to all current and future children 220.Ed 221.Dl $ ktrace -idg 15 222.Pp 223# disable all tracing of process 65 224.Dl $ ktrace -cp 65 225.Pp 226# disable tracing signals on process 70 and all current children 227.Dl $ ktrace -t s -cdp 70 228.Pp 229# enable tracing of 230.Tn I/O 231on process 67 232.Dl $ ktrace -ti -p 67 233.Pp 234# run the command "w", tracing only system calls 235.Dl $ ktrace -tc w 236.Pp 237# disable all tracing to the file "tracedata" 238.Dl $ ktrace -c -f tracedata 239.Pp 240# disable tracing of all processes owned by the user 241.Dl $ ktrace -C 242.Pp 243# run the command "w", displaying to standard output 244.Dl $ ktruss w 245.Pp 246# trace process 42 and log the records to "ktruss.out" 247.Dl $ ktruss -p 42 -o ktruss.out 248.Pp 249# poll ktruss.out for available records and print them 250.Dl $ ktruss -lf ktruss.out 251.Sh SEE ALSO 252.Xr kdump 1 253.Sh HISTORY 254The 255.Nm 256command appears in 257.Bx 4.4 . 258