11553Srgrimes/*-
21553Srgrimes * Copyright (c) 2005-2007 Joseph Koshy
31553Srgrimes * Copyright (c) 2007 The FreeBSD Foundation
41553Srgrimes * All rights reserved.
51553Srgrimes *
61553Srgrimes * Portions of this software were developed by A. Joseph Koshy under
71553Srgrimes * sponsorship from the FreeBSD Foundation and Google, Inc.
81553Srgrimes *
91553Srgrimes * Redistribution and use in source and binary forms, with or without
101553Srgrimes * modification, are permitted provided that the following conditions
111553Srgrimes * are met:
121553Srgrimes * 1. Redistributions of source code must retain the above copyright
131553Srgrimes *    notice, this list of conditions and the following disclaimer.
141553Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
151553Srgrimes *    notice, this list of conditions and the following disclaimer in the
161553Srgrimes *    documentation and/or other materials provided with the distribution.
171553Srgrimes *
181553Srgrimes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
191553Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
201553Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
211553Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
221553Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
231553Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
241553Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
251553Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
261553Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
271553Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
281553Srgrimes * SUCH DAMAGE.
291553Srgrimes *
301553Srgrimes * $FreeBSD$
311553Srgrimes */
321553Srgrimes
331553Srgrimes#ifndef	_PMCLOG_H_
3490039Sobrien#define	_PMCLOG_H_
351553Srgrimes
3690039Sobrien#include <sys/cdefs.h>
3790039Sobrien#include <sys/pmclog.h>
3890039Sobrien
391553Srgrimesenum pmclog_state {
401553Srgrimes	PMCLOG_OK,
411553Srgrimes	PMCLOG_EOF,
421553Srgrimes	PMCLOG_REQUIRE_DATA,
431553Srgrimes	PMCLOG_ERROR
441553Srgrimes};
451553Srgrimes
461553Srgrimesstruct pmclog_ev_callchain {
471553Srgrimes	uint32_t	pl_pid;
4857868Spaul	uint32_t	pl_pmcid;
491553Srgrimes	uint32_t	pl_cpuflags;
501553Srgrimes	uint32_t	pl_npc;
511553Srgrimes	uintfptr_t	pl_pc[PMC_CALLCHAIN_DEPTH_MAX];
521553Srgrimes};
531553Srgrimes
541553Srgrimesstruct pmclog_ev_dropnotify {
551553Srgrimes};
561553Srgrimes
571553Srgrimesstruct pmclog_ev_closelog {
5853183Ssheldonh};
5953183Ssheldonh
6091925Sddstruct pmclog_ev_initialize {
6153183Ssheldonh	uint32_t	pl_version;
6254034Ssheldonh	uint32_t	pl_arch;
6391925Sdd};
6491925Sdd
6553183Ssheldonhstruct pmclog_ev_map_in {
6665532Snectar	pid_t		pl_pid;
6753183Ssheldonh	uintfptr_t	pl_start;
681553Srgrimes	char		pl_pathname[PATH_MAX];
6965532Snectar};
701553Srgrimes
7157868Spaulstruct pmclog_ev_map_out {
721553Srgrimes	pid_t		pl_pid;
73103958Smaxim	uintfptr_t	pl_start;
741553Srgrimes	uintfptr_t	pl_end;
7554034Ssheldonh};
7654034Ssheldonh
7754034Ssheldonhstruct pmclog_ev_pcsample {
782916Swollman	uintfptr_t	pl_pc;
791553Srgrimes	pid_t		pl_pid;
801553Srgrimes	pmc_id_t	pl_pmcid;
811553Srgrimes	uint32_t	pl_usermode;
8287348Sdes};
832916Swollman
841553Srgrimesstruct pmclog_ev_pmcallocate {
851553Srgrimes	uint32_t	pl_event;
861553Srgrimes	const char *	pl_evname;
8787348Sdes	uint32_t	pl_flags;
8887348Sdes	pmc_id_t	pl_pmcid;
891553Srgrimes};
901553Srgrimes
911553Srgrimesstruct pmclog_ev_pmcallocatedyn {
9252921Seivind	uint32_t	pl_event;
9352921Seivind	char 		pl_evname[PMC_NAME_MAX];
9452921Seivind	uint32_t	pl_flags;
9553581Seivind	pmc_id_t	pl_pmcid;
9665532Snectar};
9765532Snectar
9853581Seivindstruct pmclog_ev_pmcattach {
9953581Seivind	pmc_id_t	pl_pmcid;
10052921Seivind	pid_t		pl_pid;
101103958Smaxim	char		pl_pathname[PATH_MAX];
10257868Spaul};
10365532Snectar
10473725Sdwmalonestruct pmclog_ev_pmcdetach {
10557868Spaul	pmc_id_t	pl_pmcid;
10657868Spaul	pid_t		pl_pid;
107104348Smaxim};
108103958Smaxim
109103958Smaximstruct pmclog_ev_proccsw {
110103958Smaxim	pid_t		pl_pid;
111103958Smaxim	pmc_id_t	pl_pmcid;
1121553Srgrimes	pmc_value_t	pl_value;
11365532Snectar};
11465532Snectar
1151553Srgrimesstruct pmclog_ev_procexec {
1161553Srgrimes	pid_t		pl_pid;
11765532Snectar	pmc_id_t	pl_pmcid;
11857868Spaul	uintfptr_t	pl_entryaddr;
11950700Ssheldonh	char		pl_pathname[PATH_MAX];
1201553Srgrimes};
1211553Srgrimes
1221553Srgrimesstruct pmclog_ev_procexit {
1231553Srgrimes	uint32_t	pl_pid;
1241553Srgrimes	pmc_id_t	pl_pmcid;
12587348Sdes	pmc_value_t	pl_value;
12687348Sdes};
127103958Smaxim
12857868Spaulstruct pmclog_ev_procfork {
12965532Snectar	pid_t		pl_oldpid;
13073725Sdwmalone	pid_t		pl_newpid;
13157868Spaul};
13257868Spaul
133104348Smaximstruct pmclog_ev_sysexit {
134103958Smaxim	pid_t		pl_pid;
135103958Smaxim};
136103958Smaxim
137103958Smaximstruct pmclog_ev_userdata {
13865532Snectar	uint32_t	pl_userdata;
13957868Spaul};
14050700Ssheldonh
1411553Srgrimesstruct pmclog_ev {
1421553Srgrimes	enum pmclog_state pl_state;	/* state after 'get_event()' */
1431553Srgrimes	off_t		  pl_offset;	/* byte offset in stream */
14465532Snectar	size_t		  pl_count;	/* count of records so far */
14587348Sdes	struct timespec   pl_ts;	/* log entry timestamp */
14687347Sdes	enum pmclog_type  pl_type;	/* type of log entry */
14787348Sdes	union { 			/* log entry data */
14887348Sdes		struct pmclog_ev_callchain	pl_cc;
14965532Snectar		struct pmclog_ev_closelog	pl_cl;
15087348Sdes		struct pmclog_ev_dropnotify	pl_dn;
15165532Snectar		struct pmclog_ev_initialize	pl_i;
15287348Sdes		struct pmclog_ev_map_in		pl_mi;
15387348Sdes		struct pmclog_ev_map_out	pl_mo;
15465532Snectar		struct pmclog_ev_pcsample	pl_s;
15565532Snectar		struct pmclog_ev_pmcallocate	pl_a;
15687348Sdes		struct pmclog_ev_pmcallocatedyn	pl_ad;
15765532Snectar		struct pmclog_ev_pmcattach	pl_t;
15887348Sdes		struct pmclog_ev_pmcdetach	pl_d;
15987348Sdes		struct pmclog_ev_proccsw	pl_c;
16065532Snectar		struct pmclog_ev_procexec	pl_x;
16165532Snectar		struct pmclog_ev_procexit	pl_e;
1625964Sdg		struct pmclog_ev_procfork	pl_f;
1635964Sdg		struct pmclog_ev_sysexit	pl_se;
16487348Sdes		struct pmclog_ev_userdata	pl_u;
16587348Sdes	} pl_u;
1662916Swollman};
16787348Sdes
1685964Sdg#define	PMCLOG_FD_NONE				(-1)
16987348Sdes
17087348Sdes__BEGIN_DECLS
1712916Swollmanvoid	*pmclog_open(int _fd);
1721553Srgrimesint	pmclog_feed(void *_cookie, char *_data, int _len);
1731553Srgrimesint	pmclog_read(void *_cookie, struct pmclog_ev *_ev);
1741553Srgrimesvoid	pmclog_close(void *_cookie);
1751553Srgrimes__END_DECLS
1761553Srgrimes
1771553Srgrimes#endif
1781553Srgrimes
17965532Snectar