pmclog.h revision 157144
1147191Sjkoshy/*-
2157144Sjkoshy * Copyright (c) 2005-2006 Joseph Koshy
3147191Sjkoshy * All rights reserved.
4147191Sjkoshy *
5147191Sjkoshy * Redistribution and use in source and binary forms, with or without
6147191Sjkoshy * modification, are permitted provided that the following conditions
7147191Sjkoshy * are met:
8147191Sjkoshy * 1. Redistributions of source code must retain the above copyright
9147191Sjkoshy *    notice, this list of conditions and the following disclaimer.
10147191Sjkoshy * 2. Redistributions in binary form must reproduce the above copyright
11147191Sjkoshy *    notice, this list of conditions and the following disclaimer in the
12147191Sjkoshy *    documentation and/or other materials provided with the distribution.
13147191Sjkoshy *
14147191Sjkoshy * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15147191Sjkoshy * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16147191Sjkoshy * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17147191Sjkoshy * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18147191Sjkoshy * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19147191Sjkoshy * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20147191Sjkoshy * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21147191Sjkoshy * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22147191Sjkoshy * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23147191Sjkoshy * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24147191Sjkoshy * SUCH DAMAGE.
25147191Sjkoshy *
26147191Sjkoshy * $FreeBSD: head/lib/libpmc/pmclog.h 157144 2006-03-26 12:20:54Z jkoshy $
27147191Sjkoshy */
28147191Sjkoshy
29147191Sjkoshy#ifndef	_PMCLOG_H_
30147191Sjkoshy#define	_PMCLOG_H_
31147191Sjkoshy
32147191Sjkoshy#include <sys/pmclog.h>
33147191Sjkoshy
34147191Sjkoshyenum pmclog_state {
35147191Sjkoshy	PMCLOG_OK,
36147191Sjkoshy	PMCLOG_EOF,
37147191Sjkoshy	PMCLOG_REQUIRE_DATA,
38147191Sjkoshy	PMCLOG_ERROR
39147191Sjkoshy};
40147191Sjkoshy
41147191Sjkoshystruct pmclog_ev_dropnotify {
42147191Sjkoshy};
43147191Sjkoshy
44147191Sjkoshystruct pmclog_ev_closelog {
45147191Sjkoshy};
46147191Sjkoshy
47147191Sjkoshystruct pmclog_ev_initialize {
48147191Sjkoshy	uint32_t	pl_version;
49147191Sjkoshy	uint32_t	pl_arch;
50147191Sjkoshy};
51147191Sjkoshy
52157144Sjkoshystruct pmclog_ev_map_in {
53147191Sjkoshy	pid_t		pl_pid;
54147191Sjkoshy	uintfptr_t	pl_start;
55147191Sjkoshy	char		pl_pathname[PATH_MAX];
56147191Sjkoshy};
57147191Sjkoshy
58157144Sjkoshystruct pmclog_ev_map_out {
59157144Sjkoshy	pid_t		pl_pid;
60157144Sjkoshy	uintfptr_t	pl_start;
61157144Sjkoshy	uintfptr_t	pl_end;
62157144Sjkoshy};
63157144Sjkoshy
64147191Sjkoshystruct pmclog_ev_pcsample {
65147191Sjkoshy	uintfptr_t	pl_pc;
66147191Sjkoshy	pid_t		pl_pid;
67147191Sjkoshy	pmc_id_t	pl_pmcid;
68147708Sjkoshy	uint32_t	pl_usermode;
69147191Sjkoshy};
70147191Sjkoshy
71147191Sjkoshystruct pmclog_ev_pmcallocate {
72147191Sjkoshy	uint32_t	pl_event;
73147191Sjkoshy	const char *	pl_evname;
74147191Sjkoshy	uint32_t	pl_flags;
75147191Sjkoshy	pmc_id_t	pl_pmcid;
76147191Sjkoshy};
77147191Sjkoshy
78147191Sjkoshystruct pmclog_ev_pmcattach {
79147191Sjkoshy	pmc_id_t	pl_pmcid;
80147191Sjkoshy	pid_t		pl_pid;
81147191Sjkoshy	char		pl_pathname[PATH_MAX];
82147191Sjkoshy};
83147191Sjkoshy
84147191Sjkoshystruct pmclog_ev_pmcdetach {
85147191Sjkoshy	pmc_id_t	pl_pmcid;
86147191Sjkoshy	pid_t		pl_pid;
87147191Sjkoshy};
88147191Sjkoshy
89147191Sjkoshystruct pmclog_ev_proccsw {
90147191Sjkoshy	pid_t		pl_pid;
91147191Sjkoshy	pmc_id_t	pl_pmcid;
92147191Sjkoshy	pmc_value_t	pl_value;
93147191Sjkoshy};
94147191Sjkoshy
95147191Sjkoshystruct pmclog_ev_procexec {
96147191Sjkoshy	pid_t		pl_pid;
97147708Sjkoshy	pmc_id_t	pl_pmcid;
98147708Sjkoshy	uintfptr_t	pl_entryaddr;
99147191Sjkoshy	char		pl_pathname[PATH_MAX];
100147191Sjkoshy};
101147191Sjkoshy
102147191Sjkoshystruct pmclog_ev_procexit {
103147191Sjkoshy	uint32_t	pl_pid;
104147191Sjkoshy	pmc_id_t	pl_pmcid;
105147191Sjkoshy	pmc_value_t	pl_value;
106147191Sjkoshy};
107147191Sjkoshy
108147191Sjkoshystruct pmclog_ev_procfork {
109147191Sjkoshy	pid_t		pl_oldpid;
110147191Sjkoshy	pid_t		pl_newpid;
111147191Sjkoshy};
112147191Sjkoshy
113147191Sjkoshystruct pmclog_ev_sysexit {
114147191Sjkoshy	pid_t		pl_pid;
115147191Sjkoshy};
116147191Sjkoshy
117147191Sjkoshystruct pmclog_ev_userdata {
118147191Sjkoshy	uint32_t	pl_userdata;
119147191Sjkoshy};
120147191Sjkoshy
121147191Sjkoshystruct pmclog_ev {
122147191Sjkoshy	enum pmclog_state pl_state;	/* state after 'get_event()' */
123147191Sjkoshy	off_t		  pl_offset;	/* byte offset in stream */
124147191Sjkoshy	size_t		  pl_count;	/* count of records so far */
125147191Sjkoshy	struct timespec   pl_ts;	/* log entry timestamp */
126147191Sjkoshy	enum pmclog_type  pl_type;	/* type of log entry */
127147191Sjkoshy	union { 			/* log entry data */
128147191Sjkoshy		struct pmclog_ev_closelog	pl_cl;
129147191Sjkoshy		struct pmclog_ev_dropnotify	pl_dn;
130147191Sjkoshy		struct pmclog_ev_initialize	pl_i;
131157144Sjkoshy		struct pmclog_ev_map_in		pl_mi;
132157144Sjkoshy		struct pmclog_ev_map_out	pl_mo;
133147191Sjkoshy		struct pmclog_ev_pcsample	pl_s;
134147191Sjkoshy		struct pmclog_ev_pmcallocate	pl_a;
135147191Sjkoshy		struct pmclog_ev_pmcattach	pl_t;
136147191Sjkoshy		struct pmclog_ev_pmcdetach	pl_d;
137147191Sjkoshy		struct pmclog_ev_proccsw	pl_c;
138147191Sjkoshy		struct pmclog_ev_procexec	pl_x;
139147191Sjkoshy		struct pmclog_ev_procexit	pl_e;
140147191Sjkoshy		struct pmclog_ev_procfork	pl_f;
141147191Sjkoshy		struct pmclog_ev_sysexit	pl_se;
142147191Sjkoshy		struct pmclog_ev_userdata	pl_u;
143147191Sjkoshy	} pl_u;
144147191Sjkoshy};
145147191Sjkoshy
146147191Sjkoshy#define	PMCLOG_FD_NONE				(-1)
147147191Sjkoshy
148147191Sjkoshyvoid	*pmclog_open(int _fd);
149147191Sjkoshyint	pmclog_feed(void *_cookie, char *_data, int _len);
150147191Sjkoshyint	pmclog_read(void *_cookie, struct pmclog_ev *_ev);
151147191Sjkoshyvoid	pmclog_close(void *_cookie);
152147191Sjkoshy
153147191Sjkoshy#endif
154147191Sjkoshy
155