1147191Sjkoshy/*-
2174215Sjkoshy * Copyright (c) 2005-2007 Joseph Koshy
3174215Sjkoshy * Copyright (c) 2007 The FreeBSD Foundation
4147191Sjkoshy * All rights reserved.
5147191Sjkoshy *
6174215Sjkoshy * Portions of this software were developed by A. Joseph Koshy under
7174215Sjkoshy * sponsorship from the FreeBSD Foundation and Google, Inc.
8174215Sjkoshy *
9147191Sjkoshy * Redistribution and use in source and binary forms, with or without
10147191Sjkoshy * modification, are permitted provided that the following conditions
11147191Sjkoshy * are met:
12147191Sjkoshy * 1. Redistributions of source code must retain the above copyright
13147191Sjkoshy *    notice, this list of conditions and the following disclaimer.
14147191Sjkoshy * 2. Redistributions in binary form must reproduce the above copyright
15147191Sjkoshy *    notice, this list of conditions and the following disclaimer in the
16147191Sjkoshy *    documentation and/or other materials provided with the distribution.
17147191Sjkoshy *
18147191Sjkoshy * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19147191Sjkoshy * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20147191Sjkoshy * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21147191Sjkoshy * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22147191Sjkoshy * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23147191Sjkoshy * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24147191Sjkoshy * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25147191Sjkoshy * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26147191Sjkoshy * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27147191Sjkoshy * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28147191Sjkoshy * SUCH DAMAGE.
29147191Sjkoshy *
30147191Sjkoshy * $FreeBSD$
31147191Sjkoshy */
32147191Sjkoshy
33147191Sjkoshy#ifndef	_PMCLOG_H_
34147191Sjkoshy#define	_PMCLOG_H_
35147191Sjkoshy
36190395Sfabient#include <sys/cdefs.h>
37147191Sjkoshy#include <sys/pmclog.h>
38147191Sjkoshy
39147191Sjkoshyenum pmclog_state {
40147191Sjkoshy	PMCLOG_OK,
41147191Sjkoshy	PMCLOG_EOF,
42147191Sjkoshy	PMCLOG_REQUIRE_DATA,
43147191Sjkoshy	PMCLOG_ERROR
44147191Sjkoshy};
45147191Sjkoshy
46174215Sjkoshystruct pmclog_ev_callchain {
47174215Sjkoshy	uint32_t	pl_pid;
48174215Sjkoshy	uint32_t	pl_pmcid;
49174215Sjkoshy	uint32_t	pl_cpuflags;
50174215Sjkoshy	uint32_t	pl_npc;
51174215Sjkoshy	uintfptr_t	pl_pc[PMC_CALLCHAIN_DEPTH_MAX];
52174215Sjkoshy};
53174215Sjkoshy
54147191Sjkoshystruct pmclog_ev_dropnotify {
55147191Sjkoshy};
56147191Sjkoshy
57147191Sjkoshystruct pmclog_ev_closelog {
58147191Sjkoshy};
59147191Sjkoshy
60147191Sjkoshystruct pmclog_ev_initialize {
61147191Sjkoshy	uint32_t	pl_version;
62147191Sjkoshy	uint32_t	pl_arch;
63147191Sjkoshy};
64147191Sjkoshy
65157144Sjkoshystruct pmclog_ev_map_in {
66147191Sjkoshy	pid_t		pl_pid;
67147191Sjkoshy	uintfptr_t	pl_start;
68147191Sjkoshy	char		pl_pathname[PATH_MAX];
69147191Sjkoshy};
70147191Sjkoshy
71157144Sjkoshystruct pmclog_ev_map_out {
72157144Sjkoshy	pid_t		pl_pid;
73157144Sjkoshy	uintfptr_t	pl_start;
74157144Sjkoshy	uintfptr_t	pl_end;
75157144Sjkoshy};
76157144Sjkoshy
77147191Sjkoshystruct pmclog_ev_pcsample {
78147191Sjkoshy	uintfptr_t	pl_pc;
79147191Sjkoshy	pid_t		pl_pid;
80147191Sjkoshy	pmc_id_t	pl_pmcid;
81147708Sjkoshy	uint32_t	pl_usermode;
82147191Sjkoshy};
83147191Sjkoshy
84147191Sjkoshystruct pmclog_ev_pmcallocate {
85147191Sjkoshy	uint32_t	pl_event;
86147191Sjkoshy	const char *	pl_evname;
87147191Sjkoshy	uint32_t	pl_flags;
88147191Sjkoshy	pmc_id_t	pl_pmcid;
89147191Sjkoshy};
90147191Sjkoshy
91233628Sfabientstruct pmclog_ev_pmcallocatedyn {
92233628Sfabient	uint32_t	pl_event;
93233628Sfabient	char 		pl_evname[PMC_NAME_MAX];
94233628Sfabient	uint32_t	pl_flags;
95233628Sfabient	pmc_id_t	pl_pmcid;
96233628Sfabient};
97233628Sfabient
98147191Sjkoshystruct pmclog_ev_pmcattach {
99147191Sjkoshy	pmc_id_t	pl_pmcid;
100147191Sjkoshy	pid_t		pl_pid;
101147191Sjkoshy	char		pl_pathname[PATH_MAX];
102147191Sjkoshy};
103147191Sjkoshy
104147191Sjkoshystruct pmclog_ev_pmcdetach {
105147191Sjkoshy	pmc_id_t	pl_pmcid;
106147191Sjkoshy	pid_t		pl_pid;
107147191Sjkoshy};
108147191Sjkoshy
109147191Sjkoshystruct pmclog_ev_proccsw {
110147191Sjkoshy	pid_t		pl_pid;
111147191Sjkoshy	pmc_id_t	pl_pmcid;
112147191Sjkoshy	pmc_value_t	pl_value;
113147191Sjkoshy};
114147191Sjkoshy
115147191Sjkoshystruct pmclog_ev_procexec {
116147191Sjkoshy	pid_t		pl_pid;
117147708Sjkoshy	pmc_id_t	pl_pmcid;
118147708Sjkoshy	uintfptr_t	pl_entryaddr;
119147191Sjkoshy	char		pl_pathname[PATH_MAX];
120147191Sjkoshy};
121147191Sjkoshy
122147191Sjkoshystruct pmclog_ev_procexit {
123147191Sjkoshy	uint32_t	pl_pid;
124147191Sjkoshy	pmc_id_t	pl_pmcid;
125147191Sjkoshy	pmc_value_t	pl_value;
126147191Sjkoshy};
127147191Sjkoshy
128147191Sjkoshystruct pmclog_ev_procfork {
129147191Sjkoshy	pid_t		pl_oldpid;
130147191Sjkoshy	pid_t		pl_newpid;
131147191Sjkoshy};
132147191Sjkoshy
133147191Sjkoshystruct pmclog_ev_sysexit {
134147191Sjkoshy	pid_t		pl_pid;
135147191Sjkoshy};
136147191Sjkoshy
137147191Sjkoshystruct pmclog_ev_userdata {
138147191Sjkoshy	uint32_t	pl_userdata;
139147191Sjkoshy};
140147191Sjkoshy
141147191Sjkoshystruct pmclog_ev {
142147191Sjkoshy	enum pmclog_state pl_state;	/* state after 'get_event()' */
143147191Sjkoshy	off_t		  pl_offset;	/* byte offset in stream */
144147191Sjkoshy	size_t		  pl_count;	/* count of records so far */
145147191Sjkoshy	struct timespec   pl_ts;	/* log entry timestamp */
146147191Sjkoshy	enum pmclog_type  pl_type;	/* type of log entry */
147147191Sjkoshy	union { 			/* log entry data */
148174215Sjkoshy		struct pmclog_ev_callchain	pl_cc;
149147191Sjkoshy		struct pmclog_ev_closelog	pl_cl;
150147191Sjkoshy		struct pmclog_ev_dropnotify	pl_dn;
151147191Sjkoshy		struct pmclog_ev_initialize	pl_i;
152157144Sjkoshy		struct pmclog_ev_map_in		pl_mi;
153157144Sjkoshy		struct pmclog_ev_map_out	pl_mo;
154147191Sjkoshy		struct pmclog_ev_pcsample	pl_s;
155147191Sjkoshy		struct pmclog_ev_pmcallocate	pl_a;
156233628Sfabient		struct pmclog_ev_pmcallocatedyn	pl_ad;
157147191Sjkoshy		struct pmclog_ev_pmcattach	pl_t;
158147191Sjkoshy		struct pmclog_ev_pmcdetach	pl_d;
159147191Sjkoshy		struct pmclog_ev_proccsw	pl_c;
160147191Sjkoshy		struct pmclog_ev_procexec	pl_x;
161147191Sjkoshy		struct pmclog_ev_procexit	pl_e;
162147191Sjkoshy		struct pmclog_ev_procfork	pl_f;
163147191Sjkoshy		struct pmclog_ev_sysexit	pl_se;
164147191Sjkoshy		struct pmclog_ev_userdata	pl_u;
165147191Sjkoshy	} pl_u;
166147191Sjkoshy};
167147191Sjkoshy
168147191Sjkoshy#define	PMCLOG_FD_NONE				(-1)
169147191Sjkoshy
170190395Sfabient__BEGIN_DECLS
171147191Sjkoshyvoid	*pmclog_open(int _fd);
172147191Sjkoshyint	pmclog_feed(void *_cookie, char *_data, int _len);
173147191Sjkoshyint	pmclog_read(void *_cookie, struct pmclog_ev *_ev);
174147191Sjkoshyvoid	pmclog_close(void *_cookie);
175190395Sfabient__END_DECLS
176147191Sjkoshy
177147191Sjkoshy#endif
178147191Sjkoshy
179