1POSIX_TRACE_CREATE(3P)     POSIX Programmer's Manual    POSIX_TRACE_CREATE(3P)
2
3
4

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10

NAME

12       posix_trace_create,   posix_trace_create_withlog,    posix_trace_flush,
13       posix_trace_shutdown - trace stream initialization, flush, and shutdown
14       from a process (TRACING)
15

SYNOPSIS

17       #include <sys/types.h>
18       #include <trace.h>
19
20       int posix_trace_create(pid_t pid,
21              const trace_attr_t *restrict attr,
22              trace_id_t *restrict trid);
23
24
25       int posix_trace_create_withlog(pid_t pid,
26              const trace_attr_t *restrict attr, int file_desc,
27              trace_id_t *restrict trid);
28       int posix_trace_flush(trace_id_t trid);
29
30
31       int posix_trace_shutdown(trace_id_t trid);
32
33

DESCRIPTION

35       The posix_trace_create() function shall create an active trace  stream.
36       It allocates all the resources needed by the trace stream being created
37       for tracing the process specified by pid in accordance  with  the  attr
38       argument.  The  attr  argument represents the initial attributes of the
39       trace  stream  and  shall  have  been  initialized  by   the   function
40       posix_trace_attr_init()  prior to the posix_trace_create() call. If the
41       argument attr is NULL, the default attributes shall be used.  The  attr
42       attributes  object  shall  be  manipulated  through  a set of functions
43       described  in  the  posix_trace_attr  family  of  functions.   If   the
44       attributes  of  the  object  pointed to by attr are modified later, the
45       attributes of the trace stream shall not be affected. The creation-time
46       attribute  of  the newly created trace stream shall be set to the value
47       of the system clock, if the Timers option is not supported, or  to  the
48       value of the CLOCK_REALTIME clock, if the Timers option is supported.
49
50       The  pid  argument  represents the target process to be traced.  If the
51       process executing this function does not have appropriate privileges to
52       trace the process identified by pid, an error shall be returned. If the
53       pid argument is zero, the calling process shall be traced.
54
55       The posix_trace_create() function shall store the trace stream  identi‐
56       fier of the new trace stream in the object pointed to by the trid argu‐
57       ment. This trace stream identifier shall be used in subsequent calls to
58       control  tracing.  The  trid argument may only be used by the following
59       functions:
60
61
62
63
64
65
66
67  posix_trace_clear()                       posix_trace_getnext_event()
68  posix_trace_eventid_equal()               posix_trace_shutdown()
69  posix_trace_eventid_get_name()            posix_trace_start()
70  posix_trace_eventtypelist_getnext_id()    posix_trace_stop()
71  posix_trace_eventtypelist_rewind()        posix_trace_timedgetnext_event()
72  posix_trace_get_attr()                    posix_trace_trid_eventid_open()
73  posix_trace_get_status()                  posix_trace_trygetnext_event()
74
75
76       If the Trace Event Filter option is supported, the following additional
77       functions may use the trid argument:
78
79               posix_trace_get_filter()    posix_trace_set_filter()
80
81       In particular, notice that the operations normally used by a trace ana‐
82       lyzer process, such  as  posix_trace_rewind()  or  posix_trace_close(),
83       cannot  be  invoked  using  the trace stream identifier returned by the
84       posix_trace_create() function.
85
86       A trace stream shall be created in a suspended  state.   If  the  Trace
87       Event  Filter option is supported, its trace event type filter shall be
88       empty.
89
90       The posix_trace_create() function may be called multiple times from the
91       same  or  different  processes, with the system-wide limit indicated by
92       the runtime invariant value  {TRACE_SYS_MAX},  which  has  the  minimum
93       value {_POSIX_TRACE_SYS_MAX}.
94
95       The  trace stream identifier returned by the posix_trace_create() func‐
96       tion in the argument pointed to by trid is valid only  in  the  process
97       that  made  the function call. If it is used from another process, that
98       is a child process, in functions defined in IEEE Std 1003.1-2001, these
99       functions shall return with the error [EINVAL].
100
101       The   posix_trace_create_withlog()  function  shall  be  equivalent  to
102       posix_trace_create(), except that it associates a trace log  with  this
103       stream. The file_desc argument shall be the file descriptor designating
104       the trace log  destination.  The  function  shall  fail  if  this  file
105       descriptor  refers  to  a  file with a file type that is not compatible
106       with the log policy associated with the trace  log.  The  list  of  the
107       appropriate  file  types  that  are  compatible with each log policy is
108       implementation-defined.
109
110       The posix_trace_create_withlog() function shall return in the parameter
111       pointed  to by trid the trace stream identifier, which uniquely identi‐
112       fies the newly created trace stream, and shall be  used  in  subsequent
113       calls  to  control  tracing.  The trid argument may only be used by the
114       following functions:
115
116  posix_trace_clear()                       posix_trace_getnext_event()
117  posix_trace_eventid_equal()               posix_trace_shutdown()
118  posix_trace_eventid_get_name()            posix_trace_start()
119  posix_trace_eventtypelist_getnext_id()    posix_trace_stop()
120  posix_trace_eventtypelist_rewind()        posix_trace_timedgetnext_event()
121  posix_trace_flush()                       posix_trace_trid_eventid_open()
122  posix_trace_get_attr()                    posix_trace_trygetnext_event()
123  posix_trace_get_status()
124
125
126       If the Trace Event Filter option is supported, the following additional
127       functions may use the trid argument:
128
129               posix_trace_get_filter()    posix_trace_set_filter()
130
131       In particular, notice that the operations normally used by a trace ana‐
132       lyzer process, such  as  posix_trace_rewind()  or  posix_trace_close(),
133       cannot  be  invoked  using  the trace stream identifier returned by the
134       posix_trace_create_withlog() function.
135
136       The posix_trace_flush() function shall initiate a flush operation which
137       copies the contents of the trace stream identified by the argument trid
138       into the trace log associated with the trace  stream  at  the  creation
139       time. If no trace log has been associated with the trace stream pointed
140       to by trid, this function shall return an error. The termination of the
141       flush operation can be polled by the posix_trace_get_status() function.
142       During the flush operation, it shall be possible  to  trace  new  trace
143       events up to the point when the trace stream becomes full. After flush‐
144       ing is completed, the space used by the flushed trace events  shall  be
145       available for tracing new trace events.
146
147       If  flushing  the trace stream causes the resulting trace log to become
148       full, the trace log full policy shall be applied.  If  the  trace  log-
149       full-policy attribute is set, the following occurs:
150
151       POSIX_TRACE_UNTIL_FULL
152
153              The  trace  events  that have not yet been flushed shall be dis‐
154              carded.
155
156       POSIX_TRACE_LOOP
157
158              The trace events that have not yet been flushed shall be written
159              to  the  beginning  of the trace log, overwriting previous trace
160              events stored there.
161
162       POSIX_TRACE_APPEND
163
164              The trace events  that  have  not  yet  been  flushed  shall  be
165              appended to the trace log.
166
167
168       The  posix_trace_shutdown()  function  shall  stop the tracing of trace
169       events in the trace stream identified by trid, as if posix_trace_stop()
170       had  been  invoked.  The posix_trace_shutdown() function shall free all
171       the resources associated with the trace stream.
172
173       The posix_trace_shutdown() function shall  not  return  until  all  the
174       resources  associated  with  the trace stream have been freed. When the
175       posix_trace_shutdown() function returns, the trid argument  becomes  an
176       invalid trace stream identifier. A call to this function shall uncondi‐
177       tionally deallocate the  resources  regardless  of  whether  all  trace
178       events  have been retrieved by the analyzer process. Any thread blocked
179       on one of the trace_getnext_event()  functions  (which  specified  this
180       trid) before this call is unblocked with the error [EINVAL].
181
182       If the process exits, invokes a member of the exec family of functions,
183       or is terminated, the trace streams that the process  had  created  and
184       that  have  not yet been shut down, shall be automatically shut down as
185       if an explicit call were made to the posix_trace_shutdown() function.
186
187       For an active trace stream with log,  when  the  posix_trace_shutdown()
188       function  is called, all trace events that have not yet been flushed to
189       the trace log shall be flushed, as in the posix_trace_flush() function,
190       and the trace log shall be closed.
191
192       When  a  trace log is closed, all the information that may be retrieved
193       later from the trace log through the trace interface  shall  have  been
194       written   to  the  trace  log.  This  information  includes  the  trace
195       attributes, the list of trace event types  (with  the  mapping  between
196       trace event names and trace event type identifiers), and the trace sta‐
197       tus.
198
199       In addition, unspecified information shall be written to the trace  log
200       to  allow  detection of a valid trace log during the posix_trace_open()
201       operation.
202
203       The posix_trace_shutdown() function shall not return  until  all  trace
204       events have been flushed.
205

RETURN VALUE

207       Upon  successful  completion,  these  functions shall return a value of
208       zero. Otherwise, they shall return the corresponding error number.
209
210       The posix_trace_create() and   posix_trace_create_withlog()   functions
211       store  the  trace  stream  identifier value in the object pointed to by
212       trid, if successful.
213

ERRORS

215       The posix_trace_create() and   posix_trace_create_withlog()   functions
216       shall fail if:
217
218       EAGAIN No  more  trace  streams can be started now. {TRACE_SYS_MAX} has
219              been exceeded.
220
221       EINTR  The operation was interrupted by a signal. No trace  stream  was
222              created.
223
224       EINVAL One or more of the trace parameters specified by the attr param‐
225              eter is invalid.
226
227       ENOMEM The implementation does not currently have sufficient memory  to
228              create the trace stream with the specified parameters.
229
230       EPERM  The  caller  does  not  have  appropriate privilege to trace the
231              process specified by pid.
232
233       ESRCH  The pid argument does not refer to an existing process.
234
235
236       The posix_trace_create_withlog() function shall fail if:
237
238       EBADF  The file_desc argument is not a valid file descriptor  open  for
239              writing.
240
241       EINVAL The  file_desc  argument  refers to a file with a file type that
242              does not support the log policy associated with the trace log.
243
244       ENOSPC No space left on device. The device corresponding to  the  argu‐
245              ment  file_desc  does  not  contain the space required to create
246              this trace log.
247
248
249       The   posix_trace_flush() and  posix_trace_shutdown()  functions  shall
250       fail if:
251
252       EINVAL The  value of the trid argument does not correspond to an active
253              trace stream with log.
254
255       EFBIG  The trace log file has attempted to  exceed  an  implementation-
256              defined maximum file size.
257
258       ENOSPC No space left on device.
259
260
261       The following sections are informative.
262

EXAMPLES

264       None.
265

APPLICATION USAGE

267       None.
268

RATIONALE

270       None.
271

FUTURE DIRECTIONS

273       None.
274

SEE ALSO

276       clock_getres(),  exec(),  posix_trace_attr_init(), posix_trace_clear(),
277       posix_trace_close(),  posix_trace_eventid_equal(),   posix_trace_event‐
278       typelist_getnext_id(),   posix_trace_flush(),   posix_trace_get_attr(),
279       posix_trace_get_filter(),  posix_trace_get_status(),   posix_trace_get‐
280       next_event(),     posix_trace_open(),     posix_trace_set_filter()    ,
281       posix_trace_shutdown(),   posix_trace_start(),    posix_trace_timedget‐
282       next_event(),   posix_trace_trid_eventid_open(),   posix_trace_start(),
283       time(),  the   Base   Definitions   volume   of   IEEE Std 1003.1-2001,
284       <sys/types.h>, <trace.h>
285
287       Portions  of  this text are reprinted and reproduced in electronic form
288       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
289       --  Portable  Operating  System  Interface (POSIX), The Open Group Base
290       Specifications Issue 6, Copyright (C) 2001-2003  by  the  Institute  of
291       Electrical  and  Electronics  Engineers, Inc and The Open Group. In the
292       event of any discrepancy between this version and the original IEEE and
293       The  Open Group Standard, the original IEEE and The Open Group Standard
294       is the referee document. The original Standard can be  obtained  online
295       at http://www.opengroup.org/unix/online.html .
296
297
298
299IEEE/The Open Group                  2003               POSIX_TRACE_CREATE(3P)
Impressum