1 .\" Copyright (c) 2005-2006 Joseph Koshy. All rights reserved.
3 .\" Redistribution and use in source and binary forms, with or without
4 .\" modification, are permitted provided that the following conditions
6 .\" 1. Redistributions of source code must retain the above copyright
7 .\" notice, this list of conditions and the following disclaimer.
8 .\" 2. Redistributions in binary form must reproduce the above copyright
9 .\" notice, this list of conditions and the following disclaimer in the
10 .\" documentation and/or other materials provided with the distribution.
12 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
13 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
14 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
15 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
16 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
17 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
18 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
19 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
20 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
21 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 .Nd parse event log data generated by
39 .Fn pmclog_open "int fd"
41 .Fn pmclog_close "void *cookie"
43 .Fn pmclog_read "void *cookie" "struct pmclog_ev *ev"
45 .Fn pmclog_feed "void *cookie" "char *data" "int len"
47 These functions provide a way for application programs to extract
48 events from an event stream generated by
51 A new event log parser is allocated using
55 may be a file descriptor opened for reading if the event stream is
56 present in a file, or the constant
58 for an event stream present in memory.
59 This function returns a cookie that is passed into the other functions
64 returns the next available event in the event stream associated with
69 points to an event descriptor that which will contain the result of a
70 successfully parsed event.
72 An event descriptor returned by
74 has the following structure:
77 enum pmclog_state pl_state; /* parser state after 'get_event()' */
78 off_t pl_offset; /* byte offset in stream */
79 size_t pl_count; /* count of records so far */
80 struct timespec pl_ts; /* log entry timestamp */
81 enum pmclog_type pl_type; /* log entry kind */
82 union { /* log entry data */
83 struct pmclog_ev_callchain pl_cc;
84 struct pmclog_ev_closelog pl_cl;
85 struct pmclog_ev_dropnotify pl_d;
86 struct pmclog_ev_initialize pl_i;
87 struct pmclog_ev_map_in pl_mi;
88 struct pmclog_ev_map_out pl_mo;
89 struct pmclog_ev_pmcallocate pl_a;
90 struct pmclog_ev_pmcallocatedyn pl_ad;
91 struct pmclog_ev_pmcattach pl_t;
92 struct pmclog_ev_pmcdetach pl_d;
93 struct pmclog_ev_proccsw pl_c;
94 struct pmclog_ev_procexec pl_x;
95 struct pmclog_ev_procexit pl_e;
96 struct pmclog_ev_procfork pl_f;
97 struct pmclog_ev_sysexit pl_e;
98 struct pmclog_ev_userdata pl_u;
103 The current state of the parser is recorded in
105 This field can take on the following values:
106 .Bl -tag -width ".Dv PMCLOG_REQUIRE_DATA"
108 (For file based parsers only)
109 An end-of-file condition was encountered on the configured file
112 An error occurred during parsing.
114 A complete event record was read into
116 .It Dv PMCLOG_REQUIRE_DATA
117 There was insufficient data in the event stream to assemble a complete
119 For memory based parsers, more data can be fed to the
120 parser using function
122 For file based parsers, function
124 may be retried when data is available on the configured file
128 The rest of the event structure is valid only if field
134 contains the offset of the current record in the byte stream.
137 contains the serial number of this event.
140 contains a timestamp with the system time when the event occurred.
143 denotes the kind of the event returned in argument
145 and is one of the following:
146 .Bl -tag -width ".Dv PMCLOG_TYPE_PMCALLOCATE"
147 .It Dv PMCLOG_TYPE_CLOSELOG
148 A marker indicating a successful close of a log file.
149 This record will be the last record of a log file.
150 .It Dv PMCLOG_TYPE_DROPNOTIFY
151 A marker indicating that
153 had to drop data due to a resource constraint.
154 .It Dv PMCLOG_TYPE_INITIALIZE
155 An initialization record.
156 This is the first record in a log file.
157 .It Dv PMCLOG_TYPE_MAP_IN
158 A record describing the introduction of a mapping to an executable
164 .It Dv PMCLOG_TYPE_MAP_OUT
165 A record describing the removal of a mapping to an executable
171 .It Dv PMCLOG_TYPE_PCSAMPLE
172 A record containing an instruction pointer sample.
173 .It Dv PMCLOG_TYPE_PMCALLOCATE
174 A record describing a PMC allocation operation.
175 .It Dv PMCLOG_TYPE_PMCATTACH
176 A record describing a PMC attach operation.
177 .It Dv PMCLOG_TYPE_PMCDETACH
178 A record describing a PMC detach operation.
179 .It Dv PMCLOG_TYPE_PROCCSW
180 A record describing a PMC reading at the time of a process context switch.
181 .It Dv PMCLOG_TYPE_PROCEXEC
182 A record describing an
185 .It Dv PMCLOG_TYPE_PROCEXIT
186 A record describing the accumulated PMC reading for a process at the
189 .It Dv PMCLOG_TYPE_PROCFORK
190 A record describing a
193 .It Dv PMCLOG_TYPE_SYSEXIT
194 A record describing a process exit, sent to processes
195 owning system-wide sampling PMCs.
196 .It Dv PMCLOG_TYPE_USERDATA
197 A record containing user data.
202 is used with parsers configured to parse memory based event streams.
203 It is intended to be called when function
205 indicates the need for more data by a returning
206 .Dv PMCLOG_REQUIRE_DATA
209 of its event structure argument.
212 points to the start of a memory buffer containing fresh event data.
215 indicates the number of data bytes available.
217 .Bq Fa data , Fa data No + Fa len
218 must remain valid till the next time
221 It is an error to use
223 on a parser configured to parse file data.
227 releases the internal state allocated by a prior call
235 value if successful or
241 will return 0 in case a complete event record was successfully read,
242 or will return \-1 and will set the
244 field of the event record to the appropriate code in case of an error.
248 will return 0 on success or \-1 in case of failure.
250 A template for using the log file parsing API is shown below in pseudocode:
252 void *parser; /* cookie */
253 struct pmclog_ev ev; /* parsed event */
254 int fd; /* file descriptor */
256 fd = open(filename, O_RDONLY); /* open log file */
257 parser = pmclog_open(fd); /* initialize parser */
259 --handle an out of memory error--;
261 /* read and parse data */
262 while (pmclog_read(parser, &ev) == 0) {
263 assert(ev.pl_state == PMCLOG_OK);
264 /* process the event */
265 switch (ev.pl_type) {
266 case PMCLOG_TYPE_ALLOCATE:
267 --process a pmc allocation record--
269 case PMCLOG_TYPE_PROCCSW:
270 --process a thread context switch record--
272 case PMCLOG_TYPE_CALLCHAIN:
273 --process a callchain sample--
279 /* examine parser state */
280 switch (ev.pl_state) {
282 --normal termination--
285 --look at errno here--
287 case PMCLOG_REQUIRE_DATA:
288 --arrange for more data to be available for parsing--
295 pmclog_close(parser); /* cleanup */
299 .Fn pmclog_init_parser
300 may fail with any of the errors returned by
305 for a file based parser may fail with any of the errors returned by
316 API first appeared in