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