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