- Uniformly use .In for header file references.
[dragonfly.git] / lib / libc / sys / ktrace.2
1 .\" Copyright (c) 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.2    8.1 (Berkeley) 6/4/93
33 .\" $FreeBSD: src/lib/libc/sys/ktrace.2,v 1.9.2.7 2001/12/14 18:34:01 ru Exp $
34 .\" $DragonFly: src/lib/libc/sys/ktrace.2,v 1.3 2006/05/26 19:39:37 swildner Exp $
35 .\"
36 .Dd June 4, 1993
37 .Dt KTRACE 2
38 .Os
39 .Sh NAME
40 .Nm ktrace
41 .Nd process tracing
42 .Sh LIBRARY
43 .Lb libc
44 .Sh SYNOPSIS
45 .In sys/param.h
46 .In sys/time.h
47 .In sys/uio.h
48 .In sys/ktrace.h
49 .Ft int
50 .Fn ktrace "const char *tracefile" "int ops" "int trpoints" "int pid"
51 .Sh DESCRIPTION
52 The
53 .Fn ktrace
54 function enables or disables tracing of one or more processes.
55 Users may only trace their own processes.
56 Only the super-user can trace setuid or setgid programs.
57 .Pp
58 The
59 .Fa tracefile
60 gives the pathname of the file to be used for tracing.
61 The file must exist and be a regular file writable by the calling process.
62 All trace records are always appended to the file,
63 so the file must be truncated to zero length to discard
64 previous trace data.
65 If tracing points are being disabled (see KTROP_CLEAR below),
66 .Fa tracefile
67 may be NULL.
68 .Pp
69 The
70 .Fa ops
71 parameter specifies the requested ktrace operation.
72 The defined operations are:
73 .Bl -column KTRFLAG_DESCENDXXX -offset indent
74 .It "KTROP_SET  Enable trace points specified in"
75 .Fa trpoints .
76 .It "KTROP_CLEAR        Disable trace points specified in
77 .Fa trpoints .
78 .It "KTROP_CLEARFILE    Stop all tracing."
79 .It "KTRFLAG_DESCEND    The tracing change should apply to the"
80 specified process and all its current children.
81 .El
82 .Pp
83 The
84 .Fa trpoints
85 parameter specifies the trace points of interest.
86 The defined trace points are:
87 .Bl -column KTRFAC_SYSCALLXXX -offset indent
88 .It "KTRFAC_SYSCALL     Trace system calls."
89 .It "KTRFAC_SYSRET      Trace return values from system calls."
90 .It "KTRFAC_NAMEI       Trace name lookup operations."
91 .It "KTRFAC_GENIO       Trace all I/O (note that this option can"
92 generate much output).
93 .It "KTRFAC_PSIG        Trace posted signals."
94 .It "KTRFAC_CSW Trace context switch points."
95 .It "KTRFAC_INHERIT     Inherit tracing to future children."
96 .El
97 .Pp
98 Each tracing event outputs a record composed of a generic header
99 followed by a trace point specific structure.
100 The generic header is:
101 .Bd -literal
102 struct ktr_header {
103         int     ktr_len;                /* length of buf */
104         short   ktr_type;               /* trace record type */
105         pid_t   ktr_pid;                /* process id */
106         char    ktr_comm[MAXCOMLEN+1];  /* command name */
107         struct  timeval ktr_time;       /* timestamp */
108         caddr_t ktr_buf;
109 };
110 .Ed
111 .Pp
112 The
113 .Va ktr_len
114 field specifies the length of the
115 .Va ktr_type
116 data that follows this header.
117 The
118 .Va ktr_pid
119 and
120 .Va ktr_comm
121 fields specify the process and command generating the record.
122 The
123 .Va ktr_time
124 field gives the time (with microsecond resolution)
125 that the record was generated.
126 The
127 .Va ktr_buf
128 is an internal kernel pointer and is not useful.
129 .Pp
130 The generic header is followed by
131 .Va ktr_len
132 bytes of a
133 .Va ktr_type
134 record.
135 The type specific records are defined in the
136 .In sys/ktrace.h
137 include file.
138 .Sh RETURN VALUES
139 .Rv -std ktrace
140 .Sh ERRORS
141 .Fn Ktrace
142 will fail if:
143 .Bl -tag -width Er
144 .It Bq Er ENOTDIR
145 A component of the path prefix is not a directory.
146 .It Bq Er ENAMETOOLONG
147 A component of a pathname exceeded 255 characters,
148 or an entire path name exceeded 1023 characters.
149 .It Bq Er ENOENT
150 The named tracefile does not exist.
151 .It Bq Er EACCES
152 Search permission is denied for a component of the path prefix.
153 .It Bq Er ELOOP
154 Too many symbolic links were encountered in translating the pathname.
155 .It Bq Er EIO
156 An I/O error occurred while reading from or writing to the file system.
157 .It Bq Er ENOSYS
158 The kernel was not compiled with
159 .Nm
160 support.
161 .El
162 .Sh SEE ALSO
163 .Xr kdump 1 ,
164 .Xr ktrace 1
165 .Sh HISTORY
166 A
167 .Fn ktrace
168 function call first appeared in
169 .Bx 4.4 .