xref: /freebsd/lib/libpmc/pmclog.h (revision db612abe8df3355d1eb23bb3b50fdd97bc21e979)
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/pmclog.h>
37 
38 enum pmclog_state {
39 	PMCLOG_OK,
40 	PMCLOG_EOF,
41 	PMCLOG_REQUIRE_DATA,
42 	PMCLOG_ERROR
43 };
44 
45 struct pmclog_ev_callchain {
46 	uint32_t	pl_pid;
47 	uint32_t	pl_pmcid;
48 	uint32_t	pl_cpuflags;
49 	uint32_t	pl_npc;
50 	uintfptr_t	pl_pc[PMC_CALLCHAIN_DEPTH_MAX];
51 };
52 
53 struct pmclog_ev_dropnotify {
54 };
55 
56 struct pmclog_ev_closelog {
57 };
58 
59 struct pmclog_ev_initialize {
60 	uint32_t	pl_version;
61 	uint32_t	pl_arch;
62 };
63 
64 struct pmclog_ev_map_in {
65 	pid_t		pl_pid;
66 	uintfptr_t	pl_start;
67 	char		pl_pathname[PATH_MAX];
68 };
69 
70 struct pmclog_ev_map_out {
71 	pid_t		pl_pid;
72 	uintfptr_t	pl_start;
73 	uintfptr_t	pl_end;
74 };
75 
76 struct pmclog_ev_pcsample {
77 	uintfptr_t	pl_pc;
78 	pid_t		pl_pid;
79 	pmc_id_t	pl_pmcid;
80 	uint32_t	pl_usermode;
81 };
82 
83 struct pmclog_ev_pmcallocate {
84 	uint32_t	pl_event;
85 	const char *	pl_evname;
86 	uint32_t	pl_flags;
87 	pmc_id_t	pl_pmcid;
88 };
89 
90 struct pmclog_ev_pmcattach {
91 	pmc_id_t	pl_pmcid;
92 	pid_t		pl_pid;
93 	char		pl_pathname[PATH_MAX];
94 };
95 
96 struct pmclog_ev_pmcdetach {
97 	pmc_id_t	pl_pmcid;
98 	pid_t		pl_pid;
99 };
100 
101 struct pmclog_ev_proccsw {
102 	pid_t		pl_pid;
103 	pmc_id_t	pl_pmcid;
104 	pmc_value_t	pl_value;
105 };
106 
107 struct pmclog_ev_procexec {
108 	pid_t		pl_pid;
109 	pmc_id_t	pl_pmcid;
110 	uintfptr_t	pl_entryaddr;
111 	char		pl_pathname[PATH_MAX];
112 };
113 
114 struct pmclog_ev_procexit {
115 	uint32_t	pl_pid;
116 	pmc_id_t	pl_pmcid;
117 	pmc_value_t	pl_value;
118 };
119 
120 struct pmclog_ev_procfork {
121 	pid_t		pl_oldpid;
122 	pid_t		pl_newpid;
123 };
124 
125 struct pmclog_ev_sysexit {
126 	pid_t		pl_pid;
127 };
128 
129 struct pmclog_ev_userdata {
130 	uint32_t	pl_userdata;
131 };
132 
133 struct pmclog_ev {
134 	enum pmclog_state pl_state;	/* state after 'get_event()' */
135 	off_t		  pl_offset;	/* byte offset in stream */
136 	size_t		  pl_count;	/* count of records so far */
137 	struct timespec   pl_ts;	/* log entry timestamp */
138 	enum pmclog_type  pl_type;	/* type of log entry */
139 	union { 			/* log entry data */
140 		struct pmclog_ev_callchain	pl_cc;
141 		struct pmclog_ev_closelog	pl_cl;
142 		struct pmclog_ev_dropnotify	pl_dn;
143 		struct pmclog_ev_initialize	pl_i;
144 		struct pmclog_ev_map_in		pl_mi;
145 		struct pmclog_ev_map_out	pl_mo;
146 		struct pmclog_ev_pcsample	pl_s;
147 		struct pmclog_ev_pmcallocate	pl_a;
148 		struct pmclog_ev_pmcattach	pl_t;
149 		struct pmclog_ev_pmcdetach	pl_d;
150 		struct pmclog_ev_proccsw	pl_c;
151 		struct pmclog_ev_procexec	pl_x;
152 		struct pmclog_ev_procexit	pl_e;
153 		struct pmclog_ev_procfork	pl_f;
154 		struct pmclog_ev_sysexit	pl_se;
155 		struct pmclog_ev_userdata	pl_u;
156 	} pl_u;
157 };
158 
159 #define	PMCLOG_FD_NONE				(-1)
160 
161 void	*pmclog_open(int _fd);
162 int	pmclog_feed(void *_cookie, char *_data, int _len);
163 int	pmclog_read(void *_cookie, struct pmclog_ev *_ev);
164 void	pmclog_close(void *_cookie);
165 
166 #endif
167 
168