2006-03-26 14:20:54 +02:00
|
|
|
.\" Copyright (c) 2005-2006 Joseph Koshy. All rights reserved.
|
2005-06-09 21:45:09 +02:00
|
|
|
.\"
|
|
|
|
.\" Redistribution and use in source and binary forms, with or without
|
|
|
|
.\" modification, are permitted provided that the following conditions
|
|
|
|
.\" are met:
|
|
|
|
.\" 1. Redistributions of source code must retain the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer.
|
|
|
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer in the
|
|
|
|
.\" documentation and/or other materials provided with the distribution.
|
|
|
|
.\"
|
2012-02-17 12:09:51 +01:00
|
|
|
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
.\" SUCH DAMAGE.
|
2005-06-09 21:45:09 +02:00
|
|
|
.\"
|
|
|
|
.\" $FreeBSD$
|
|
|
|
.\"
|
2006-03-26 14:20:54 +02:00
|
|
|
.Dd March 26, 2006
|
2005-06-09 21:45:09 +02:00
|
|
|
.Dt PMCLOG 3
|
2010-04-14 21:08:06 +02:00
|
|
|
.Os
|
2005-06-09 21:45:09 +02:00
|
|
|
.Sh NAME
|
|
|
|
.Nm pmclog_open ,
|
|
|
|
.Nm pmclog_close ,
|
|
|
|
.Nm pmclog_read ,
|
|
|
|
.Nm pmclog_feed
|
|
|
|
.Nd parse event log data generated by
|
|
|
|
.Xr hwpmc 4
|
|
|
|
.Sh LIBRARY
|
|
|
|
.Lb libpmc
|
|
|
|
.Sh SYNOPSIS
|
|
|
|
.In pmclog.h
|
|
|
|
.Ft "void *"
|
|
|
|
.Fn pmclog_open "int fd"
|
|
|
|
.Ft void
|
|
|
|
.Fn pmclog_close "void *cookie"
|
|
|
|
.Ft int
|
|
|
|
.Fn pmclog_read "void *cookie" "struct pmclog_ev *ev"
|
|
|
|
.Ft int
|
|
|
|
.Fn pmclog_feed "void *cookie" "char *data" "int len"
|
|
|
|
.Sh DESCRIPTION
|
|
|
|
These functions provide a way for application programs to extract
|
|
|
|
events from an event stream generated by
|
|
|
|
.Xr hwpmc 4 .
|
|
|
|
.Pp
|
|
|
|
A new event log parser is allocated using
|
|
|
|
.Fn pmclog_open .
|
|
|
|
Argument
|
|
|
|
.Fa fd
|
|
|
|
may be a file descriptor opened for reading if the event stream is
|
|
|
|
present in a file, or the constant
|
|
|
|
.Dv PMCLOG_FD_NONE
|
|
|
|
for an event stream present in memory.
|
|
|
|
This function returns a cookie that is passed into the other functions
|
|
|
|
in this API set.
|
|
|
|
.Pp
|
|
|
|
Function
|
|
|
|
.Fn pmclog_read
|
|
|
|
returns the next available event in the event stream associated with
|
|
|
|
argument
|
|
|
|
.Fa cookie .
|
|
|
|
Argument
|
|
|
|
.Fa ev
|
|
|
|
points to an event descriptor that which will contain the result of a
|
|
|
|
successfully parsed event.
|
|
|
|
.Pp
|
|
|
|
An event descriptor returned by
|
|
|
|
.Fn pmclog_read
|
|
|
|
has the following structure:
|
|
|
|
.Bd -literal
|
|
|
|
struct pmclog_ev {
|
|
|
|
enum pmclog_state pl_state; /* parser state after 'get_event()' */
|
|
|
|
off_t pl_offset; /* byte offset in stream */
|
|
|
|
size_t pl_count; /* count of records so far */
|
|
|
|
struct timespec pl_ts; /* log entry timestamp */
|
|
|
|
enum pmclog_type pl_type; /* log entry kind */
|
|
|
|
union { /* log entry data */
|
2006-03-26 14:20:54 +02:00
|
|
|
struct pmclog_ev_closelog pl_cl;
|
|
|
|
struct pmclog_ev_dropnotify pl_d;
|
|
|
|
struct pmclog_ev_initialize pl_i;
|
|
|
|
struct pmclog_ev_map_in pl_mi;
|
|
|
|
struct pmclog_ev_map_out pl_mo;
|
|
|
|
struct pmclog_ev_pcsample pl_s;
|
|
|
|
struct pmclog_ev_pmcallocate pl_a;
|
|
|
|
struct pmclog_ev_pmcattach pl_t;
|
|
|
|
struct pmclog_ev_pmcdetach pl_d;
|
|
|
|
struct pmclog_ev_proccsw pl_c;
|
|
|
|
struct pmclog_ev_procexec pl_x;
|
|
|
|
struct pmclog_ev_procexit pl_e;
|
|
|
|
struct pmclog_ev_procfork pl_f;
|
|
|
|
struct pmclog_ev_sysexit pl_e;
|
|
|
|
struct pmclog_ev_userdata pl_u;
|
2005-06-09 21:45:09 +02:00
|
|
|
} pl_u;
|
|
|
|
};
|
|
|
|
.Ed
|
|
|
|
.Pp
|
|
|
|
The current state of the parser is recorded in
|
|
|
|
.Va pl_state .
|
|
|
|
This field can take on the following values:
|
2005-06-24 18:13:36 +02:00
|
|
|
.Bl -tag -width ".Dv PMCLOG_REQUIRE_DATA"
|
2005-06-09 21:45:09 +02:00
|
|
|
.It Dv PMCLOG_EOF
|
2005-06-24 18:13:36 +02:00
|
|
|
(For file based parsers only)
|
2005-06-09 21:45:09 +02:00
|
|
|
An end-of-file condition was encountered on the configured file
|
|
|
|
descriptor.
|
|
|
|
.It Dv PMCLOG_ERROR
|
|
|
|
An error occurred during parsing.
|
|
|
|
.It Dv PMCLOG_OK
|
|
|
|
A complete event record was read into
|
2005-06-24 18:13:36 +02:00
|
|
|
.Fa *ev .
|
2005-06-09 21:45:09 +02:00
|
|
|
.It Dv PMCLOG_REQUIRE_DATA
|
|
|
|
There was insufficient data in the event stream to assemble a complete
|
|
|
|
event record.
|
|
|
|
For memory based parsers, more data can be fed to the
|
|
|
|
parser using function
|
|
|
|
.Fn pmclog_feed .
|
|
|
|
For file based parsers, function
|
|
|
|
.Fn pmclog_read
|
|
|
|
may be retried when data is available on the configured file
|
|
|
|
descriptor.
|
|
|
|
.El
|
|
|
|
.Pp
|
|
|
|
The rest of the event structure is valid only if field
|
|
|
|
.Va pl_state
|
|
|
|
contains
|
|
|
|
.Dv PMCLOG_OK .
|
|
|
|
Field
|
|
|
|
.Va pl_offset
|
|
|
|
contains the offset of the current record in the byte stream.
|
|
|
|
Field
|
|
|
|
.Va pl_count
|
|
|
|
contains the serial number of this event.
|
|
|
|
Field
|
|
|
|
.Va pl_ts
|
|
|
|
contains a timestamp with the system time when the event occurred.
|
|
|
|
Field
|
|
|
|
.Va pl_type
|
|
|
|
denotes the kind of the event returned in argument
|
|
|
|
.Fa *ev
|
|
|
|
and is one of the following:
|
2005-06-24 18:13:36 +02:00
|
|
|
.Bl -tag -width ".Dv PMCLOG_TYPE_PMCALLOCATE"
|
2005-07-21 08:42:30 +02:00
|
|
|
.It Dv PMCLOG_TYPE_CLOSELOG
|
|
|
|
A marker indicating a successful close of a log file.
|
|
|
|
This record will be the last record of a log file.
|
2005-06-09 21:45:09 +02:00
|
|
|
.It Dv PMCLOG_TYPE_DROPNOTIFY
|
2005-07-21 08:42:30 +02:00
|
|
|
A marker indicating that
|
2005-06-09 21:45:09 +02:00
|
|
|
.Xr hwpmc 4
|
|
|
|
had to drop data due to a resource constraint.
|
|
|
|
.It Dv PMCLOG_TYPE_INITIALIZE
|
2005-07-21 08:42:30 +02:00
|
|
|
An initialization record.
|
|
|
|
This is the first record in a log file.
|
2006-03-26 14:20:54 +02:00
|
|
|
.It Dv PMCLOG_TYPE_MAP_IN
|
|
|
|
A record describing the introduction of a mapping to an executable
|
|
|
|
object by a
|
2006-09-17 23:27:35 +02:00
|
|
|
.Xr kldload 2
|
2006-03-26 14:20:54 +02:00
|
|
|
or
|
|
|
|
.Xr mmap 2
|
|
|
|
system call.
|
|
|
|
.It Dv PMCLOG_TYPE_MAP_OUT
|
|
|
|
A record describing the removal of a mapping to an executable
|
|
|
|
object by a
|
|
|
|
.Xr kldunload 2
|
|
|
|
or
|
|
|
|
.Xr munmap 2
|
|
|
|
system call.
|
2005-06-09 21:45:09 +02:00
|
|
|
.It Dv PMCLOG_TYPE_PCSAMPLE
|
|
|
|
A record containing an instruction pointer sample.
|
|
|
|
.It Dv PMCLOG_TYPE_PMCALLOCATE
|
|
|
|
A record describing a PMC allocation operation.
|
|
|
|
.It Dv PMCLOG_TYPE_PMCATTACH
|
|
|
|
A record describing a PMC attach operation.
|
2005-07-21 08:42:30 +02:00
|
|
|
.It Dv PMCLOG_TYPE_PMCDETACH
|
|
|
|
A record describing a PMC detach operation.
|
2005-06-09 21:45:09 +02:00
|
|
|
.It Dv PMCLOG_TYPE_PROCCSW
|
|
|
|
A record describing a PMC reading at the time of a process context switch.
|
2005-07-21 08:42:30 +02:00
|
|
|
.It Dv PMCLOG_TYPE_PROCEXEC
|
|
|
|
A record describing an
|
|
|
|
.Xr execve 2
|
|
|
|
by a target process.
|
2005-06-09 21:45:09 +02:00
|
|
|
.It Dv PMCLOG_TYPE_PROCEXIT
|
|
|
|
A record describing the accumulated PMC reading for a process at the
|
|
|
|
time of
|
|
|
|
.Xr _exit 2 .
|
2005-07-21 08:42:30 +02:00
|
|
|
.It Dv PMCLOG_TYPE_PROCFORK
|
|
|
|
A record describing a
|
|
|
|
.Xr fork 2
|
2005-06-09 21:45:09 +02:00
|
|
|
by a target process.
|
2005-07-21 08:42:30 +02:00
|
|
|
.It Dv PMCLOG_TYPE_SYSEXIT
|
|
|
|
A record describing a process exit, sent to processes
|
|
|
|
owning system-wide sampling PMCs.
|
2005-06-09 21:45:09 +02:00
|
|
|
.It Dv PMCLOG_TYPE_USERDATA
|
|
|
|
A record containing user data.
|
|
|
|
.El
|
|
|
|
.Pp
|
|
|
|
Function
|
|
|
|
.Fn pmclog_feed
|
|
|
|
is used with parsers configured to parse memory based event streams.
|
|
|
|
It is intended to be called when function
|
|
|
|
.Fn pmclog_read
|
|
|
|
indicates the need for more data by a returning
|
|
|
|
.Dv PMCLOG_REQUIRE_DATA
|
|
|
|
in field
|
|
|
|
.Va pl_state
|
|
|
|
of its event structure argument.
|
|
|
|
Argument
|
|
|
|
.Fa data
|
|
|
|
points to the start of a memory buffer containing fresh event data.
|
|
|
|
Argument
|
|
|
|
.Fa len
|
2005-06-24 18:13:36 +02:00
|
|
|
indicates the number of data bytes available.
|
2005-06-09 21:45:09 +02:00
|
|
|
The memory range
|
2005-06-24 18:13:36 +02:00
|
|
|
.Bq Fa data , Fa data No + Fa len
|
2005-06-09 21:45:09 +02:00
|
|
|
must remain valid till the next time
|
|
|
|
.Fn pmclog_read
|
|
|
|
returns an error.
|
|
|
|
It is an error to use
|
|
|
|
.Fn pmclog_feed
|
|
|
|
on a parser configured to parse file data.
|
|
|
|
.Pp
|
|
|
|
Function
|
|
|
|
.Fn pmclog_close
|
|
|
|
releases the internal state allocated by a prior call
|
|
|
|
to
|
|
|
|
.Fn pmclog_open .
|
|
|
|
.Sh RETURN VALUES
|
|
|
|
Function
|
|
|
|
.Fn pmclog_open
|
2005-06-24 18:13:36 +02:00
|
|
|
will return a
|
|
|
|
.No non- Ns Dv NULL
|
|
|
|
value if successful or
|
|
|
|
.Dv NULL
|
|
|
|
otherwise.
|
2005-06-09 21:45:09 +02:00
|
|
|
.Pp
|
|
|
|
Function
|
|
|
|
.Fn pmclog_read
|
|
|
|
will return 0 in case a complete event record was successfully read,
|
2005-06-24 18:13:36 +02:00
|
|
|
or will return \-1 and will set the
|
2005-06-09 21:45:09 +02:00
|
|
|
.Va pl_state
|
|
|
|
field of the event record to the appropriate code in case of an error.
|
|
|
|
.Pp
|
|
|
|
Function
|
|
|
|
.Fn pmclog_feed
|
2005-06-24 18:13:36 +02:00
|
|
|
will return 0 on success or \-1 in case of failure.
|
2005-06-09 21:45:09 +02:00
|
|
|
.Sh EXAMPLES
|
2005-06-24 18:13:36 +02:00
|
|
|
A template for using the log file parsing API is shown below in pseudocode:
|
2005-06-09 21:45:09 +02:00
|
|
|
.Bd -literal
|
|
|
|
void *parser; /* cookie */
|
|
|
|
struct pmclog_ev ev; /* parsed event */
|
|
|
|
int fd; /* file descriptor */
|
|
|
|
|
|
|
|
fd = open(filename, O_RDONLY); /* open log file */
|
|
|
|
parser = pmclog_open(fd); /* initialize parser */
|
|
|
|
if (parser == NULL)
|
|
|
|
--handle an out of memory error--;
|
|
|
|
|
|
|
|
/* read and parse data */
|
|
|
|
while (pmclog_read(parser, &ev) == 0) {
|
|
|
|
assert(ev.pl_state == PMCLOG_OK);
|
|
|
|
/* process the event */
|
|
|
|
switch (ev.pl_type) {
|
|
|
|
case PMCLOG_TYPE_ALLOCATE:
|
|
|
|
--process a pmc allocation record--
|
|
|
|
break;
|
|
|
|
case PMCLOG_TYPE_PROCCSW:
|
|
|
|
--process a thread context switch record--
|
|
|
|
break;
|
|
|
|
case PMCLOG_TYPE_PCSAMPLE:
|
|
|
|
--process a PC sample--
|
|
|
|
break;
|
|
|
|
--and so on--
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* examine parser state */
|
|
|
|
switch (ev.pl_state) {
|
|
|
|
case PMCLOG_EOF:
|
|
|
|
--normal termination--
|
|
|
|
break;
|
|
|
|
case PMCLOG_ERROR:
|
|
|
|
--look at errno here--
|
|
|
|
break;
|
|
|
|
case PMCLOG_REQUIRE_DATA:
|
|
|
|
--arrange for more data to be available for parsing--
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
/*NOTREACHED*/
|
|
|
|
}
|
|
|
|
|
|
|
|
pmclog_close(parser); /* cleanup */
|
|
|
|
.Ed
|
|
|
|
.Sh ERRORS
|
|
|
|
A call to
|
|
|
|
.Fn pmclog_init_parser
|
|
|
|
may fail with any of the errors returned by
|
|
|
|
.Xr malloc 3 .
|
|
|
|
.Pp
|
|
|
|
A call to
|
|
|
|
.Fn pmclog_read
|
|
|
|
for a file based parser may fail with any of the errors returned by
|
|
|
|
.Xr read 2 .
|
|
|
|
.Sh SEE ALSO
|
|
|
|
.Xr read 2 ,
|
|
|
|
.Xr malloc 3 ,
|
|
|
|
.Xr pmc 3 ,
|
2005-06-24 18:13:36 +02:00
|
|
|
.Xr hwpmc 4 ,
|
|
|
|
.Xr pmcstat 8
|
2005-07-21 08:42:30 +02:00
|
|
|
.Sh HISTORY
|
|
|
|
The
|
2005-11-17 14:00:00 +01:00
|
|
|
.Nm pmclog
|
2005-07-21 08:42:30 +02:00
|
|
|
API
|
|
|
|
.Ud
|
|
|
|
It first appeared in
|
|
|
|
.Fx 6.0 .
|