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
34 .Nd parse event log data generated by
41 .Fn pmclog_open "int fd"
43 .Fn pmclog_close "void *cookie"
45 .Fn pmclog_read "void *cookie" "struct pmclog_ev *ev"
47 .Fn pmclog_feed "void *cookie" "char *data" "int len"
49 These functions provide a way for application programs to extract
50 events from an event stream generated by
53 A new event log parser is allocated using
57 may be a file descriptor opened for reading if the event stream is
58 present in a file, or the constant
60 for an event stream present in memory.
61 This function returns a cookie that is passed into the other functions
66 returns the next available event in the event stream associated with
71 points to an event descriptor that which will contain the result of a
72 successfully parsed event.
74 An event descriptor returned by
76 has the following structure:
79 enum pmclog_state pl_state; /* parser state after 'get_event()' */
80 off_t pl_offset; /* byte offset in stream */
81 size_t pl_count; /* count of records so far */
82 struct timespec pl_ts; /* log entry timestamp */
83 enum pmclog_type pl_type; /* log entry kind */
84 union { /* log entry data */
85 struct pmclog_ev_callchain pl_cc;
86 struct pmclog_ev_closelog pl_cl;
87 struct pmclog_ev_dropnotify pl_d;
88 struct pmclog_ev_initialize pl_i;
89 struct pmclog_ev_map_in pl_mi;
90 struct pmclog_ev_map_out pl_mo;
91 struct pmclog_ev_pmcallocate pl_a;
92 struct pmclog_ev_pmcallocatedyn pl_ad;
93 struct pmclog_ev_pmcattach pl_t;
94 struct pmclog_ev_pmcdetach pl_d;
95 struct pmclog_ev_proccsw pl_c;
96 struct pmclog_ev_procexec pl_x;
97 struct pmclog_ev_procexit pl_e;
98 struct pmclog_ev_procfork pl_f;
99 struct pmclog_ev_sysexit pl_e;
100 struct pmclog_ev_userdata pl_u;
105 The current state of the parser is recorded in
107 This field can take on the following values:
108 .Bl -tag -width ".Dv PMCLOG_REQUIRE_DATA"
110 (For file based parsers only)
111 An end-of-file condition was encountered on the configured file
114 An error occurred during parsing.
116 A complete event record was read into
118 .It Dv PMCLOG_REQUIRE_DATA
119 There was insufficient data in the event stream to assemble a complete
121 For memory based parsers, more data can be fed to the
122 parser using function
124 For file based parsers, function
126 may be retried when data is available on the configured file
130 The rest of the event structure is valid only if field
136 contains the offset of the current record in the byte stream.
139 contains the serial number of this event.
142 contains a timestamp with the system time when the event occurred.
145 denotes the kind of the event returned in argument
147 and is one of the following:
148 .Bl -tag -width ".Dv PMCLOG_TYPE_PMCALLOCATE"
149 .It Dv PMCLOG_TYPE_CLOSELOG
150 A marker indicating a successful close of a log file.
151 This record will be the last record of a log file.
152 .It Dv PMCLOG_TYPE_DROPNOTIFY
153 A marker indicating that
155 had to drop data due to a resource constraint.
156 .It Dv PMCLOG_TYPE_INITIALIZE
157 An initialization record.
158 This is the first record in a log file.
159 .It Dv PMCLOG_TYPE_MAP_IN
160 A record describing the introduction of a mapping to an executable
166 .It Dv PMCLOG_TYPE_MAP_OUT
167 A record describing the removal of a mapping to an executable
173 .It Dv PMCLOG_TYPE_PCSAMPLE
174 A record containing an instruction pointer sample.
175 .It Dv PMCLOG_TYPE_PMCALLOCATE
176 A record describing a PMC allocation operation.
177 .It Dv PMCLOG_TYPE_PMCATTACH
178 A record describing a PMC attach operation.
179 .It Dv PMCLOG_TYPE_PMCDETACH
180 A record describing a PMC detach operation.
181 .It Dv PMCLOG_TYPE_PROCCSW
182 A record describing a PMC reading at the time of a process context switch.
183 .It Dv PMCLOG_TYPE_PROCEXEC
184 A record describing an
187 .It Dv PMCLOG_TYPE_PROCEXIT
188 A record describing the accumulated PMC reading for a process at the
191 .It Dv PMCLOG_TYPE_PROCFORK
192 A record describing a
195 .It Dv PMCLOG_TYPE_SYSEXIT
196 A record describing a process exit, sent to processes
197 owning system-wide sampling PMCs.
198 .It Dv PMCLOG_TYPE_USERDATA
199 A record containing user data.
204 is used with parsers configured to parse memory based event streams.
205 It is intended to be called when function
207 indicates the need for more data by a returning
208 .Dv PMCLOG_REQUIRE_DATA
211 of its event structure argument.
214 points to the start of a memory buffer containing fresh event data.
217 indicates the number of data bytes available.
219 .Bq Fa data , Fa data No + Fa len
220 must remain valid till the next time
223 It is an error to use
225 on a parser configured to parse file data.
229 releases the internal state allocated by a prior call
237 value if successful or
243 will return 0 in case a complete event record was successfully read,
244 or will return \-1 and will set the
246 field of the event record to the appropriate code in case of an error.
250 will return 0 on success or \-1 in case of failure.
252 A template for using the log file parsing API is shown below in pseudocode:
254 void *parser; /* cookie */
255 struct pmclog_ev ev; /* parsed event */
256 int fd; /* file descriptor */
258 fd = open(filename, O_RDONLY); /* open log file */
259 parser = pmclog_open(fd); /* initialize parser */
261 --handle an out of memory error--;
263 /* read and parse data */
264 while (pmclog_read(parser, &ev) == 0) {
265 assert(ev.pl_state == PMCLOG_OK);
266 /* process the event */
267 switch (ev.pl_type) {
268 case PMCLOG_TYPE_ALLOCATE:
269 --process a pmc allocation record--
271 case PMCLOG_TYPE_PROCCSW:
272 --process a thread context switch record--
274 case PMCLOG_TYPE_CALLCHAIN:
275 --process a callchain sample--
281 /* examine parser state */
282 switch (ev.pl_state) {
284 --normal termination--
287 --look at errno here--
289 case PMCLOG_REQUIRE_DATA:
290 --arrange for more data to be available for parsing--
297 pmclog_close(parser); /* cleanup */
301 .Fn pmclog_init_parser
302 may fail with any of the errors returned by
307 for a file based parser may fail with any of the errors returned by