xref: /freebsd/lib/libpmc/pmclog.h (revision aa0a1e58)
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_pmcattach {
92 	pmc_id_t	pl_pmcid;
93 	pid_t		pl_pid;
94 	char		pl_pathname[PATH_MAX];
95 };
96 
97 struct pmclog_ev_pmcdetach {
98 	pmc_id_t	pl_pmcid;
99 	pid_t		pl_pid;
100 };
101 
102 struct pmclog_ev_proccsw {
103 	pid_t		pl_pid;
104 	pmc_id_t	pl_pmcid;
105 	pmc_value_t	pl_value;
106 };
107 
108 struct pmclog_ev_procexec {
109 	pid_t		pl_pid;
110 	pmc_id_t	pl_pmcid;
111 	uintfptr_t	pl_entryaddr;
112 	char		pl_pathname[PATH_MAX];
113 };
114 
115 struct pmclog_ev_procexit {
116 	uint32_t	pl_pid;
117 	pmc_id_t	pl_pmcid;
118 	pmc_value_t	pl_value;
119 };
120 
121 struct pmclog_ev_procfork {
122 	pid_t		pl_oldpid;
123 	pid_t		pl_newpid;
124 };
125 
126 struct pmclog_ev_sysexit {
127 	pid_t		pl_pid;
128 };
129 
130 struct pmclog_ev_userdata {
131 	uint32_t	pl_userdata;
132 };
133 
134 struct pmclog_ev {
135 	enum pmclog_state pl_state;	/* state after 'get_event()' */
136 	off_t		  pl_offset;	/* byte offset in stream */
137 	size_t		  pl_count;	/* count of records so far */
138 	struct timespec   pl_ts;	/* log entry timestamp */
139 	enum pmclog_type  pl_type;	/* type of log entry */
140 	union { 			/* log entry data */
141 		struct pmclog_ev_callchain	pl_cc;
142 		struct pmclog_ev_closelog	pl_cl;
143 		struct pmclog_ev_dropnotify	pl_dn;
144 		struct pmclog_ev_initialize	pl_i;
145 		struct pmclog_ev_map_in		pl_mi;
146 		struct pmclog_ev_map_out	pl_mo;
147 		struct pmclog_ev_pcsample	pl_s;
148 		struct pmclog_ev_pmcallocate	pl_a;
149 		struct pmclog_ev_pmcattach	pl_t;
150 		struct pmclog_ev_pmcdetach	pl_d;
151 		struct pmclog_ev_proccsw	pl_c;
152 		struct pmclog_ev_procexec	pl_x;
153 		struct pmclog_ev_procexit	pl_e;
154 		struct pmclog_ev_procfork	pl_f;
155 		struct pmclog_ev_sysexit	pl_se;
156 		struct pmclog_ev_userdata	pl_u;
157 	} pl_u;
158 };
159 
160 #define	PMCLOG_FD_NONE				(-1)
161 
162 __BEGIN_DECLS
163 void	*pmclog_open(int _fd);
164 int	pmclog_feed(void *_cookie, char *_data, int _len);
165 int	pmclog_read(void *_cookie, struct pmclog_ev *_ev);
166 void	pmclog_close(void *_cookie);
167 __END_DECLS
168 
169 #endif
170 
171