2005-06-09 19:45:09 +00:00
|
|
|
/*-
|
2017-11-26 02:00:33 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
|
|
|
|
*
|
2007-12-03 11:15:46 +00:00
|
|
|
* Copyright (c) 2005-2007 Joseph Koshy
|
|
|
|
* Copyright (c) 2007 The FreeBSD Foundation
|
2005-06-09 19:45:09 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
2007-12-03 11:15:46 +00:00
|
|
|
* Portions of this software were developed by A. Joseph Koshy under
|
|
|
|
* sponsorship from the FreeBSD Foundation and Google, Inc.
|
|
|
|
*
|
2005-06-09 19:45:09 +00:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* $FreeBSD$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _PMCLOG_H_
|
|
|
|
#define _PMCLOG_H_
|
|
|
|
|
2009-03-24 22:35:05 +00:00
|
|
|
#include <sys/cdefs.h>
|
2005-06-09 19:45:09 +00:00
|
|
|
#include <sys/pmclog.h>
|
|
|
|
|
|
|
|
enum pmclog_state {
|
|
|
|
PMCLOG_OK,
|
|
|
|
PMCLOG_EOF,
|
|
|
|
PMCLOG_REQUIRE_DATA,
|
|
|
|
PMCLOG_ERROR
|
|
|
|
};
|
|
|
|
|
2007-12-03 11:15:46 +00:00
|
|
|
struct pmclog_ev_callchain {
|
|
|
|
uint32_t pl_pid;
|
2018-05-23 17:25:00 +00:00
|
|
|
uint32_t pl_tid;
|
2007-12-03 11:15:46 +00:00
|
|
|
uint32_t pl_pmcid;
|
|
|
|
uint32_t pl_cpuflags;
|
2018-05-23 17:25:00 +00:00
|
|
|
uint32_t pl_cpuflags2;
|
2007-12-03 11:15:46 +00:00
|
|
|
uint32_t pl_npc;
|
|
|
|
uintfptr_t pl_pc[PMC_CALLCHAIN_DEPTH_MAX];
|
|
|
|
};
|
|
|
|
|
2005-06-09 19:45:09 +00:00
|
|
|
struct pmclog_ev_dropnotify {
|
|
|
|
};
|
|
|
|
|
|
|
|
struct pmclog_ev_closelog {
|
|
|
|
};
|
|
|
|
|
|
|
|
struct pmclog_ev_initialize {
|
|
|
|
uint32_t pl_version;
|
|
|
|
uint32_t pl_arch;
|
2018-06-07 02:03:22 +00:00
|
|
|
uint64_t pl_tsc_freq;
|
|
|
|
struct timespec pl_ts;
|
2018-06-04 02:05:48 +00:00
|
|
|
char pl_cpuid[PATH_MAX];
|
2005-06-09 19:45:09 +00:00
|
|
|
};
|
|
|
|
|
2006-03-26 12:20:54 +00:00
|
|
|
struct pmclog_ev_map_in {
|
2005-06-09 19:45:09 +00:00
|
|
|
pid_t pl_pid;
|
|
|
|
uintfptr_t pl_start;
|
|
|
|
char pl_pathname[PATH_MAX];
|
|
|
|
};
|
|
|
|
|
2006-03-26 12:20:54 +00:00
|
|
|
struct pmclog_ev_map_out {
|
|
|
|
pid_t pl_pid;
|
|
|
|
uintfptr_t pl_start;
|
|
|
|
uintfptr_t pl_end;
|
|
|
|
};
|
|
|
|
|
2005-06-09 19:45:09 +00:00
|
|
|
struct pmclog_ev_pcsample {
|
|
|
|
uintfptr_t pl_pc;
|
|
|
|
pid_t pl_pid;
|
2018-05-23 17:25:00 +00:00
|
|
|
pid_t pl_tid;
|
2005-06-09 19:45:09 +00:00
|
|
|
pmc_id_t pl_pmcid;
|
2018-05-23 17:25:00 +00:00
|
|
|
uint32_t pl_flags;
|
2005-06-30 19:01:26 +00:00
|
|
|
uint32_t pl_usermode;
|
2005-06-09 19:45:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct pmclog_ev_pmcallocate {
|
|
|
|
const char * pl_evname;
|
2018-06-06 02:48:09 +00:00
|
|
|
uint64_t pl_rate;
|
|
|
|
uint32_t pl_event;
|
2005-06-09 19:45:09 +00:00
|
|
|
uint32_t pl_flags;
|
|
|
|
pmc_id_t pl_pmcid;
|
|
|
|
};
|
|
|
|
|
2012-03-28 20:58:30 +00:00
|
|
|
struct pmclog_ev_pmcallocatedyn {
|
|
|
|
char pl_evname[PMC_NAME_MAX];
|
2018-06-06 02:48:09 +00:00
|
|
|
uint32_t pl_event;
|
2012-03-28 20:58:30 +00:00
|
|
|
uint32_t pl_flags;
|
|
|
|
pmc_id_t pl_pmcid;
|
|
|
|
};
|
|
|
|
|
2005-06-09 19:45:09 +00:00
|
|
|
struct pmclog_ev_pmcattach {
|
|
|
|
pmc_id_t pl_pmcid;
|
|
|
|
pid_t pl_pid;
|
|
|
|
char pl_pathname[PATH_MAX];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct pmclog_ev_pmcdetach {
|
|
|
|
pmc_id_t pl_pmcid;
|
|
|
|
pid_t pl_pid;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct pmclog_ev_proccsw {
|
|
|
|
pid_t pl_pid;
|
2018-05-23 17:25:00 +00:00
|
|
|
pid_t pl_tid;
|
2005-06-09 19:45:09 +00:00
|
|
|
pmc_id_t pl_pmcid;
|
|
|
|
pmc_value_t pl_value;
|
|
|
|
};
|
|
|
|
|
2018-06-05 04:26:40 +00:00
|
|
|
struct pmclog_ev_proccreate {
|
|
|
|
pid_t pl_pid;
|
2018-06-06 02:48:09 +00:00
|
|
|
uint32_t pl_flags;
|
2018-06-05 04:26:40 +00:00
|
|
|
char pl_pcomm[MAXCOMLEN+1];
|
|
|
|
};
|
|
|
|
|
2005-06-09 19:45:09 +00:00
|
|
|
struct pmclog_ev_procexec {
|
|
|
|
pid_t pl_pid;
|
2005-06-30 19:01:26 +00:00
|
|
|
pmc_id_t pl_pmcid;
|
|
|
|
uintfptr_t pl_entryaddr;
|
2005-06-09 19:45:09 +00:00
|
|
|
char pl_pathname[PATH_MAX];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct pmclog_ev_procexit {
|
|
|
|
uint32_t pl_pid;
|
|
|
|
pmc_id_t pl_pmcid;
|
|
|
|
pmc_value_t pl_value;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct pmclog_ev_procfork {
|
|
|
|
pid_t pl_oldpid;
|
|
|
|
pid_t pl_newpid;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct pmclog_ev_sysexit {
|
|
|
|
pid_t pl_pid;
|
|
|
|
};
|
|
|
|
|
2018-06-05 04:26:40 +00:00
|
|
|
struct pmclog_ev_threadcreate {
|
|
|
|
pid_t pl_tid;
|
|
|
|
pid_t pl_pid;
|
2018-06-06 02:48:09 +00:00
|
|
|
uint32_t pl_flags;
|
2018-06-05 04:26:40 +00:00
|
|
|
char pl_tdname[MAXCOMLEN+1];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct pmclog_ev_threadexit {
|
|
|
|
pid_t pl_tid;
|
|
|
|
};
|
|
|
|
|
2005-06-09 19:45:09 +00:00
|
|
|
struct pmclog_ev_userdata {
|
|
|
|
uint32_t pl_userdata;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct pmclog_ev {
|
|
|
|
enum pmclog_state pl_state; /* state after 'get_event()' */
|
|
|
|
off_t pl_offset; /* byte offset in stream */
|
|
|
|
size_t pl_count; /* count of records so far */
|
|
|
|
struct timespec pl_ts; /* log entry timestamp */
|
|
|
|
enum pmclog_type pl_type; /* type of log entry */
|
2018-06-04 04:59:48 +00:00
|
|
|
void *pl_data;
|
|
|
|
int pl_len;
|
2005-06-09 19:45:09 +00:00
|
|
|
union { /* log entry data */
|
2007-12-03 11:15:46 +00:00
|
|
|
struct pmclog_ev_callchain pl_cc;
|
2005-06-09 19:45:09 +00:00
|
|
|
struct pmclog_ev_closelog pl_cl;
|
|
|
|
struct pmclog_ev_dropnotify pl_dn;
|
|
|
|
struct pmclog_ev_initialize pl_i;
|
2006-03-26 12:20:54 +00:00
|
|
|
struct pmclog_ev_map_in pl_mi;
|
|
|
|
struct pmclog_ev_map_out pl_mo;
|
2005-06-09 19:45:09 +00:00
|
|
|
struct pmclog_ev_pmcallocate pl_a;
|
2012-03-28 20:58:30 +00:00
|
|
|
struct pmclog_ev_pmcallocatedyn pl_ad;
|
2005-06-09 19:45:09 +00:00
|
|
|
struct pmclog_ev_pmcattach pl_t;
|
|
|
|
struct pmclog_ev_pmcdetach pl_d;
|
|
|
|
struct pmclog_ev_proccsw pl_c;
|
2018-06-05 04:26:40 +00:00
|
|
|
struct pmclog_ev_proccreate pl_pc;
|
2005-06-09 19:45:09 +00:00
|
|
|
struct pmclog_ev_procexec pl_x;
|
|
|
|
struct pmclog_ev_procexit pl_e;
|
|
|
|
struct pmclog_ev_procfork pl_f;
|
|
|
|
struct pmclog_ev_sysexit pl_se;
|
2018-06-05 04:26:40 +00:00
|
|
|
struct pmclog_ev_threadcreate pl_tc;
|
|
|
|
struct pmclog_ev_threadexit pl_te;
|
2005-06-09 19:45:09 +00:00
|
|
|
struct pmclog_ev_userdata pl_u;
|
|
|
|
} pl_u;
|
|
|
|
};
|
|
|
|
|
2018-06-04 04:59:48 +00:00
|
|
|
enum pmclog_parser_state {
|
|
|
|
PL_STATE_NEW_RECORD, /* in-between records */
|
|
|
|
PL_STATE_EXPECTING_HEADER, /* header being read */
|
|
|
|
PL_STATE_PARTIAL_RECORD, /* header present but not the record */
|
|
|
|
PL_STATE_ERROR /* parsing error encountered */
|
|
|
|
};
|
|
|
|
|
|
|
|
struct pmclog_parse_state {
|
|
|
|
enum pmclog_parser_state ps_state;
|
|
|
|
enum pmc_cputype ps_arch; /* log file architecture */
|
|
|
|
uint32_t ps_version; /* hwpmc version */
|
|
|
|
int ps_initialized; /* whether initialized */
|
|
|
|
int ps_count; /* count of records processed */
|
|
|
|
off_t ps_offset; /* stream byte offset */
|
|
|
|
union pmclog_entry ps_saved; /* saved partial log entry */
|
|
|
|
int ps_svcount; /* #bytes saved */
|
|
|
|
int ps_fd; /* active fd or -1 */
|
|
|
|
char *ps_buffer; /* scratch buffer if fd != -1 */
|
|
|
|
char *ps_data; /* current parse pointer */
|
2018-06-06 02:48:09 +00:00
|
|
|
char *ps_cpuid; /* log cpuid */
|
2018-06-04 04:59:48 +00:00
|
|
|
size_t ps_len; /* length of buffered data */
|
|
|
|
};
|
|
|
|
|
2005-06-09 19:45:09 +00:00
|
|
|
#define PMCLOG_FD_NONE (-1)
|
|
|
|
|
2009-03-24 22:35:05 +00:00
|
|
|
__BEGIN_DECLS
|
2005-06-09 19:45:09 +00:00
|
|
|
void *pmclog_open(int _fd);
|
|
|
|
int pmclog_feed(void *_cookie, char *_data, int _len);
|
|
|
|
int pmclog_read(void *_cookie, struct pmclog_ev *_ev);
|
|
|
|
void pmclog_close(void *_cookie);
|
2009-03-24 22:35:05 +00:00
|
|
|
__END_DECLS
|
2005-06-09 19:45:09 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|