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       int posix_trace_create_withlog(pid_t pid,
24           const trace_attr_t *restrict attr, int file_desc,
25           trace_id_t *restrict trid);
26       int posix_trace_flush(trace_id_t trid);
27       int posix_trace_shutdown(trace_id_t trid);
28

DESCRIPTION

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

RETURN VALUE

189       Upon  successful  completion,  these  functions shall return a value of
190       zero. Otherwise, they shall return the corresponding error number.
191
192       The  posix_trace_create()  and  posix_trace_create_withlog()  functions
193       store  the  trace  stream  identifier value in the object pointed to by
194       trid, if successful.
195

ERRORS

197       The  posix_trace_create()  and  posix_trace_create_withlog()  functions
198       shall fail if:
199
200       EAGAIN No  more  trace streams can be started now.  {TRACE_SYS_MAX} has
201              been exceeded.
202
203       EINTR  The operation was interrupted by a signal. No trace  stream  was
204              created.
205
206       EINVAL One or more of the trace parameters specified by the attr param‐
207              eter is invalid.
208
209       ENOMEM The implementation does not currently have sufficient memory  to
210              create the trace stream with the specified parameters.
211
212       EPERM  The  caller  does  not  have appropriate privileges to trace the
213              process specified by pid.
214
215       ESRCH  The pid argument does not refer to an existing process.
216
217       The posix_trace_create_withlog() function shall fail if:
218
219       EBADF  The file_desc argument is not a valid file descriptor  open  for
220              writing.
221
222       EINVAL The  file_desc  argument  refers to a file with a file type that
223              does not support the log policy associated with the trace log.
224
225       ENOSPC No space left on device. The device corresponding to  the  argu‐
226              ment  file_desc  does  not  contain the space required to create
227              this trace log.
228
229       The posix_trace_flush() and posix_trace_shutdown() functions shall fail
230       if:
231
232       EINVAL The  value of the trid argument does not correspond to an active
233              trace stream with log.
234
235       EFBIG  The trace log file has attempted to  exceed  an  implementation-
236              defined maximum file size.
237
238       ENOSPC No space left on device.
239
240       The following sections are informative.
241

EXAMPLES

243       None.
244

APPLICATION USAGE

246       None.
247

RATIONALE

249       None.
250

FUTURE DIRECTIONS

252       The         posix_trace_create(),         posix_trace_create_withlog(),
253       posix_trace_flush(),  and  posix_trace_shutdown()  functions   may   be
254       removed in a future version.
255

SEE ALSO

257       clock_getres(), exec, posix_trace_attr_destroy(), posix_trace_clear(),
258       posix_trace_close(), posix_trace_eventid_equal(), posix_trace_event‐
259       typelist_getnext_id(), posix_trace_get_attr(), posix_trace_get_fil‐
260       ter(), posix_trace_getnext_event(), posix_trace_start(),
261       posix_trace_start(), time()
262
263       The Base Definitions volume of POSIX.1‐2017, <sys_types.h>, <trace.h>
264
266       Portions  of  this text are reprinted and reproduced in electronic form
267       from IEEE Std 1003.1-2017, Standard for Information Technology --  Por‐
268       table  Operating System Interface (POSIX), The Open Group Base Specifi‐
269       cations Issue 7, 2018 Edition, Copyright (C) 2018 by the  Institute  of
270       Electrical  and  Electronics Engineers, Inc and The Open Group.  In the
271       event of any discrepancy between this version and the original IEEE and
272       The  Open Group Standard, the original IEEE and The Open Group Standard
273       is the referee document. The original Standard can be  obtained  online
274       at http://www.opengroup.org/unix/online.html .
275
276       Any  typographical  or  formatting  errors that appear in this page are
277       most likely to have been introduced during the conversion of the source
278       files  to  man page format. To report such errors, see https://www.ker
279       nel.org/doc/man-pages/reporting_bugs.html .
280
281
282
283IEEE/The Open Group                  2017               POSIX_TRACE_CREATE(3P)
Impressum