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