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 Joseph Koshy ``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 Joseph Koshy 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_closelog pl_cl;
86 struct pmclog_ev_dropnotify pl_d;
87 struct pmclog_ev_initialize pl_i;
88 struct pmclog_ev_map_in pl_mi;
89 struct pmclog_ev_map_out pl_mo;
90 struct pmclog_ev_pcsample pl_s;
91 struct pmclog_ev_pmcallocate pl_a;
92 struct pmclog_ev_pmcattach pl_t;
93 struct pmclog_ev_pmcdetach pl_d;
94 struct pmclog_ev_proccsw pl_c;
95 struct pmclog_ev_procexec pl_x;
96 struct pmclog_ev_procexit pl_e;
97 struct pmclog_ev_procfork pl_f;
98 struct pmclog_ev_sysexit pl_e;
99 struct pmclog_ev_userdata pl_u;
104 The current state of the parser is recorded in
106 This field can take on the following values:
107 .Bl -tag -width ".Dv PMCLOG_REQUIRE_DATA"
109 (For file based parsers only)
110 An end-of-file condition was encountered on the configured file
113 An error occurred during parsing.
115 A complete event record was read into
117 .It Dv PMCLOG_REQUIRE_DATA
118 There was insufficient data in the event stream to assemble a complete
120 For memory based parsers, more data can be fed to the
121 parser using function
123 For file based parsers, function
125 may be retried when data is available on the configured file
129 The rest of the event structure is valid only if field
135 contains the offset of the current record in the byte stream.
138 contains the serial number of this event.
141 contains a timestamp with the system time when the event occurred.
144 denotes the kind of the event returned in argument
146 and is one of the following:
147 .Bl -tag -width ".Dv PMCLOG_TYPE_PMCALLOCATE"
148 .It Dv PMCLOG_TYPE_CLOSELOG
149 A marker indicating a successful close of a log file.
150 This record will be the last record of a log file.
151 .It Dv PMCLOG_TYPE_DROPNOTIFY
152 A marker indicating that
154 had to drop data due to a resource constraint.
155 .It Dv PMCLOG_TYPE_INITIALIZE
156 An initialization record.
157 This is the first record in a log file.
158 .It Dv PMCLOG_TYPE_MAP_IN
159 A record describing the introduction of a mapping to an executable
165 .It Dv PMCLOG_TYPE_MAP_OUT
166 A record describing the removal of a mapping to an executable
172 .It Dv PMCLOG_TYPE_PCSAMPLE
173 A record containing an instruction pointer sample.
174 .It Dv PMCLOG_TYPE_PMCALLOCATE
175 A record describing a PMC allocation operation.
176 .It Dv PMCLOG_TYPE_PMCATTACH
177 A record describing a PMC attach operation.
178 .It Dv PMCLOG_TYPE_PMCDETACH
179 A record describing a PMC detach operation.
180 .It Dv PMCLOG_TYPE_PROCCSW
181 A record describing a PMC reading at the time of a process context switch.
182 .It Dv PMCLOG_TYPE_PROCEXEC
183 A record describing an
186 .It Dv PMCLOG_TYPE_PROCEXIT
187 A record describing the accumulated PMC reading for a process at the
190 .It Dv PMCLOG_TYPE_PROCFORK
191 A record describing a
194 .It Dv PMCLOG_TYPE_SYSEXIT
195 A record describing a process exit, sent to processes
196 owning system-wide sampling PMCs.
197 .It Dv PMCLOG_TYPE_USERDATA
198 A record containing user data.
203 is used with parsers configured to parse memory based event streams.
204 It is intended to be called when function
206 indicates the need for more data by a returning
207 .Dv PMCLOG_REQUIRE_DATA
210 of its event structure argument.
213 points to the start of a memory buffer containing fresh event data.
216 indicates the number of data bytes available.
218 .Bq Fa data , Fa data No + Fa len
219 must remain valid till the next time
222 It is an error to use
224 on a parser configured to parse file data.
228 releases the internal state allocated by a prior call
236 value if successful or
242 will return 0 in case a complete event record was successfully read,
243 or will return \-1 and will set the
245 field of the event record to the appropriate code in case of an error.
249 will return 0 on success or \-1 in case of failure.
251 A template for using the log file parsing API is shown below in pseudocode:
253 void *parser; /* cookie */
254 struct pmclog_ev ev; /* parsed event */
255 int fd; /* file descriptor */
257 fd = open(filename, O_RDONLY); /* open log file */
258 parser = pmclog_open(fd); /* initialize parser */
260 --handle an out of memory error--;
262 /* read and parse data */
263 while (pmclog_read(parser, &ev) == 0) {
264 assert(ev.pl_state == PMCLOG_OK);
265 /* process the event */
266 switch (ev.pl_type) {
267 case PMCLOG_TYPE_ALLOCATE:
268 --process a pmc allocation record--
270 case PMCLOG_TYPE_PROCCSW:
271 --process a thread context switch record--
273 case PMCLOG_TYPE_PCSAMPLE:
274 --process a PC sample--
280 /* examine parser state */
281 switch (ev.pl_state) {
283 --normal termination--
286 --look at errno here--
288 case PMCLOG_REQUIRE_DATA:
289 --arrange for more data to be available for parsing--
296 pmclog_close(parser); /* cleanup */
300 .Fn pmclog_init_parser
301 may fail with any of the errors returned by
306 for a file based parser may fail with any of the errors returned by