xref: /freebsd/lib/libpmc/pmclog.h (revision 0b3105a37d7adcadcb720112fed4dc4e8040be99)
1 /*-
2  * Copyright (c) 2005-2007 Joseph Koshy
3  * Copyright (c) 2007 The FreeBSD Foundation
4  * All rights reserved.
5  *
6  * Portions of this software were developed by A. Joseph Koshy under
7  * sponsorship from the FreeBSD Foundation and Google, Inc.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28  * SUCH DAMAGE.
29  *
30  * $FreeBSD$
31  */
32 
33 #ifndef	_PMCLOG_H_
34 #define	_PMCLOG_H_
35 
36 #include <sys/cdefs.h>
37 #include <sys/pmclog.h>
38 
39 enum pmclog_state {
40 	PMCLOG_OK,
41 	PMCLOG_EOF,
42 	PMCLOG_REQUIRE_DATA,
43 	PMCLOG_ERROR
44 };
45 
46 struct pmclog_ev_callchain {
47 	uint32_t	pl_pid;
48 	uint32_t	pl_pmcid;
49 	uint32_t	pl_cpuflags;
50 	uint32_t	pl_npc;
51 	uintfptr_t	pl_pc[PMC_CALLCHAIN_DEPTH_MAX];
52 };
53 
54 struct pmclog_ev_dropnotify {
55 };
56 
57 struct pmclog_ev_closelog {
58 };
59 
60 struct pmclog_ev_initialize {
61 	uint32_t	pl_version;
62 	uint32_t	pl_arch;
63 };
64 
65 struct pmclog_ev_map_in {
66 	pid_t		pl_pid;
67 	uintfptr_t	pl_start;
68 	char		pl_pathname[PATH_MAX];
69 };
70 
71 struct pmclog_ev_map_out {
72 	pid_t		pl_pid;
73 	uintfptr_t	pl_start;
74 	uintfptr_t	pl_end;
75 };
76 
77 struct pmclog_ev_pcsample {
78 	uintfptr_t	pl_pc;
79 	pid_t		pl_pid;
80 	pmc_id_t	pl_pmcid;
81 	uint32_t	pl_usermode;
82 };
83 
84 struct pmclog_ev_pmcallocate {
85 	uint32_t	pl_event;
86 	const char *	pl_evname;
87 	uint32_t	pl_flags;
88 	pmc_id_t	pl_pmcid;
89 };
90 
91 struct pmclog_ev_pmcallocatedyn {
92 	uint32_t	pl_event;
93 	char 		pl_evname[PMC_NAME_MAX];
94 	uint32_t	pl_flags;
95 	pmc_id_t	pl_pmcid;
96 };
97 
98 struct pmclog_ev_pmcattach {
99 	pmc_id_t	pl_pmcid;
100 	pid_t		pl_pid;
101 	char		pl_pathname[PATH_MAX];
102 };
103 
104 struct pmclog_ev_pmcdetach {
105 	pmc_id_t	pl_pmcid;
106 	pid_t		pl_pid;
107 };
108 
109 struct pmclog_ev_proccsw {
110 	pid_t		pl_pid;
111 	pmc_id_t	pl_pmcid;
112 	pmc_value_t	pl_value;
113 };
114 
115 struct pmclog_ev_procexec {
116 	pid_t		pl_pid;
117 	pmc_id_t	pl_pmcid;
118 	uintfptr_t	pl_entryaddr;
119 	char		pl_pathname[PATH_MAX];
120 };
121 
122 struct pmclog_ev_procexit {
123 	uint32_t	pl_pid;
124 	pmc_id_t	pl_pmcid;
125 	pmc_value_t	pl_value;
126 };
127 
128 struct pmclog_ev_procfork {
129 	pid_t		pl_oldpid;
130 	pid_t		pl_newpid;
131 };
132 
133 struct pmclog_ev_sysexit {
134 	pid_t		pl_pid;
135 };
136 
137 struct pmclog_ev_userdata {
138 	uint32_t	pl_userdata;
139 };
140 
141 struct pmclog_ev {
142 	enum pmclog_state pl_state;	/* state after 'get_event()' */
143 	off_t		  pl_offset;	/* byte offset in stream */
144 	size_t		  pl_count;	/* count of records so far */
145 	struct timespec   pl_ts;	/* log entry timestamp */
146 	enum pmclog_type  pl_type;	/* type of log entry */
147 	union { 			/* log entry data */
148 		struct pmclog_ev_callchain	pl_cc;
149 		struct pmclog_ev_closelog	pl_cl;
150 		struct pmclog_ev_dropnotify	pl_dn;
151 		struct pmclog_ev_initialize	pl_i;
152 		struct pmclog_ev_map_in		pl_mi;
153 		struct pmclog_ev_map_out	pl_mo;
154 		struct pmclog_ev_pcsample	pl_s;
155 		struct pmclog_ev_pmcallocate	pl_a;
156 		struct pmclog_ev_pmcallocatedyn	pl_ad;
157 		struct pmclog_ev_pmcattach	pl_t;
158 		struct pmclog_ev_pmcdetach	pl_d;
159 		struct pmclog_ev_proccsw	pl_c;
160 		struct pmclog_ev_procexec	pl_x;
161 		struct pmclog_ev_procexit	pl_e;
162 		struct pmclog_ev_procfork	pl_f;
163 		struct pmclog_ev_sysexit	pl_se;
164 		struct pmclog_ev_userdata	pl_u;
165 	} pl_u;
166 };
167 
168 #define	PMCLOG_FD_NONE				(-1)
169 
170 __BEGIN_DECLS
171 void	*pmclog_open(int _fd);
172 int	pmclog_feed(void *_cookie, char *_data, int _len);
173 int	pmclog_read(void *_cookie, struct pmclog_ev *_ev);
174 void	pmclog_close(void *_cookie);
175 __END_DECLS
176 
177 #endif
178 
179