1 /*- 2 * Copyright (c) 2005 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_mappingchange { 53 uint32_t pl_type; 54 pid_t pl_pid; 55 uintfptr_t pl_start; 56 uintfptr_t pl_end; 57 char pl_pathname[PATH_MAX]; 58 }; 59 60 struct pmclog_ev_pcsample { 61 uintfptr_t pl_pc; 62 pid_t pl_pid; 63 pmc_id_t pl_pmcid; 64 uint32_t pl_usermode; 65 }; 66 67 struct pmclog_ev_pmcallocate { 68 uint32_t pl_event; 69 const char * pl_evname; 70 uint32_t pl_flags; 71 pmc_id_t pl_pmcid; 72 }; 73 74 struct pmclog_ev_pmcattach { 75 pmc_id_t pl_pmcid; 76 pid_t pl_pid; 77 char pl_pathname[PATH_MAX]; 78 }; 79 80 struct pmclog_ev_pmcdetach { 81 pmc_id_t pl_pmcid; 82 pid_t pl_pid; 83 }; 84 85 struct pmclog_ev_proccsw { 86 pid_t pl_pid; 87 pmc_id_t pl_pmcid; 88 pmc_value_t pl_value; 89 }; 90 91 struct pmclog_ev_procexec { 92 pid_t pl_pid; 93 pmc_id_t pl_pmcid; 94 uintfptr_t pl_entryaddr; 95 char pl_pathname[PATH_MAX]; 96 }; 97 98 struct pmclog_ev_procexit { 99 uint32_t pl_pid; 100 pmc_id_t pl_pmcid; 101 pmc_value_t pl_value; 102 }; 103 104 struct pmclog_ev_procfork { 105 pid_t pl_oldpid; 106 pid_t pl_newpid; 107 }; 108 109 struct pmclog_ev_sysexit { 110 pid_t pl_pid; 111 }; 112 113 struct pmclog_ev_userdata { 114 uint32_t pl_userdata; 115 }; 116 117 struct pmclog_ev { 118 enum pmclog_state pl_state; /* state after 'get_event()' */ 119 off_t pl_offset; /* byte offset in stream */ 120 size_t pl_count; /* count of records so far */ 121 struct timespec pl_ts; /* log entry timestamp */ 122 enum pmclog_type pl_type; /* type of log entry */ 123 union { /* log entry data */ 124 struct pmclog_ev_closelog pl_cl; 125 struct pmclog_ev_dropnotify pl_dn; 126 struct pmclog_ev_initialize pl_i; 127 struct pmclog_ev_mappingchange pl_m; 128 struct pmclog_ev_pcsample pl_s; 129 struct pmclog_ev_pmcallocate pl_a; 130 struct pmclog_ev_pmcattach pl_t; 131 struct pmclog_ev_pmcdetach pl_d; 132 struct pmclog_ev_proccsw pl_c; 133 struct pmclog_ev_procexec pl_x; 134 struct pmclog_ev_procexit pl_e; 135 struct pmclog_ev_procfork pl_f; 136 struct pmclog_ev_sysexit pl_se; 137 struct pmclog_ev_userdata pl_u; 138 } pl_u; 139 }; 140 141 #define PMCLOG_FD_NONE (-1) 142 143 void *pmclog_open(int _fd); 144 int pmclog_feed(void *_cookie, char *_data, int _len); 145 int pmclog_read(void *_cookie, struct pmclog_ev *_ev); 146 void pmclog_close(void *_cookie); 147 148 #endif 149 150