pmcstat.h revision 168949
1/*-
2 * Copyright (c) 2005-2006, 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: head/usr.sbin/pmcstat/pmcstat.h 168949 2007-04-22 15:00:39Z jkoshy $
27 */
28
29#ifndef	_PMCSTAT_H_
30#define	_PMCSTAT_H_
31
32#define	FLAG_HAS_PID			0x00000001	/* explicit pid */
33#define	FLAG_HAS_WAIT_INTERVAL		0x00000002	/* -w secs */
34#define	FLAG_HAS_OUTPUT_LOGFILE		0x00000004	/* -O file or pipe */
35#define	FLAG_HAS_COMMANDLINE		0x00000008	/* command */
36#define	FLAG_HAS_SAMPLING_PMCS		0x00000010	/* -S or -P */
37#define	FLAG_HAS_COUNTING_PMCS		0x00000020	/* -s or -p */
38#define	FLAG_HAS_PROCESS_PMCS		0x00000040	/* -P or -p */
39#define	FLAG_HAS_SYSTEM_PMCS		0x00000080	/* -S or -s */
40#define	FLAG_HAS_PIPE			0x00000100	/* implicit log */
41#define	FLAG_READ_LOGFILE		0x00000200	/* -R file */
42#define	FLAG_DO_GPROF			0x00000400	/* -g */
43#define	FLAG_HAS_SAMPLESDIR		0x00000800	/* -D dir */
44#define	FLAG_HAS_KERNELPATH		0x00001000	/* -k kernel */
45#define	FLAG_DO_PRINT			0x00002000	/* -o */
46
47#define	DEFAULT_SAMPLE_COUNT		65536
48#define	DEFAULT_WAIT_INTERVAL		5.0
49#define	DEFAULT_DISPLAY_HEIGHT		23
50#define	DEFAULT_BUFFER_SIZE		4096
51
52#define	PRINT_HEADER_PREFIX		"# "
53#define	READPIPEFD			0
54#define	WRITEPIPEFD			1
55#define	NPIPEFD				2
56
57#define	NSOCKPAIRFD			2
58#define	PARENTSOCKET			0
59#define	CHILDSOCKET			1
60
61#define	PMCSTAT_OPEN_FOR_READ		0
62#define	PMCSTAT_OPEN_FOR_WRITE		1
63#define	PMCSTAT_DEFAULT_NW_HOST		"localhost"
64#define	PMCSTAT_DEFAULT_NW_PORT		"9000"
65#define	PMCSTAT_NHASH			256
66#define	PMCSTAT_HASH_MASK		0xFF
67
68#define	PMCSTAT_LDD_COMMAND		"/usr/bin/ldd"
69
70#define	PMCSTAT_PRINT_ENTRY(A,T,...) do {				\
71		fprintf((A)->pa_printfile, "%-8s", T);			\
72		fprintf((A)->pa_printfile, " "  __VA_ARGS__);		\
73		fprintf((A)->pa_printfile, "\n");			\
74	} while (0)
75
76enum pmcstat_state {
77	PMCSTAT_FINISHED = 0,
78	PMCSTAT_EXITING  = 1,
79	PMCSTAT_RUNNING  = 2
80};
81
82struct pmcstat_ev {
83	STAILQ_ENTRY(pmcstat_ev) ev_next;
84	int		ev_count; /* associated count if in sampling mode */
85	uint32_t	ev_cpu;	  /* cpus for this event */
86	int		ev_cumulative;  /* show cumulative counts */
87	int		ev_flags; /* PMC_F_* */
88	int		ev_fieldskip;   /* #leading spaces */
89	int		ev_fieldwidth;  /* print width */
90	enum pmc_mode	ev_mode;  /* desired mode */
91	char	       *ev_name;  /* (derived) event name */
92	pmc_id_t	ev_pmcid; /* allocated ID */
93	pmc_value_t	ev_saved; /* for incremental counts */
94	char	       *ev_spec;  /* event specification */
95};
96
97struct pmcstat_args {
98	int	pa_flags;		/* argument flags */
99	int	pa_required;		/* required features */
100	int	pa_verbosity;		/* verbosity level */
101	pid_t	pa_pid;			/* attached to pid */
102	FILE	*pa_printfile;		/* where to send printed output */
103	int	pa_logfd;		/* output log file */
104	char	*pa_inputpath;		/* path to input log */
105	char	*pa_outputpath;		/* path to output log */
106	void	*pa_logparser;		/* log file parser */
107	const char	*pa_fsroot;	/* FS root where executables reside */
108	char	*pa_kernel;		/* pathname of the kernel */
109	const char	*pa_samplesdir;	/* directory for profile files */
110	const char	*pa_mapfilename;/* mapfile name */
111	double	pa_interval;		/* printing interval in seconds */
112	int	pa_argc;
113	char	**pa_argv;
114	STAILQ_HEAD(, pmcstat_ev) pa_head;
115} args;
116
117/* Function prototypes */
118void	pmcstat_attach_pmcs(struct pmcstat_args *_a);
119void	pmcstat_cleanup(struct pmcstat_args *_a);
120void	pmcstat_clone_event_descriptor(struct pmcstat_args *_a,
121    struct pmcstat_ev *_ev, uint32_t _cpumask);
122int	pmcstat_close_log(struct pmcstat_args *_a);
123void	pmcstat_create_process(struct pmcstat_args *_a);
124void	pmcstat_initialize_logging(struct pmcstat_args *_a);
125int	pmcstat_open_log(const char *_p, int _mode);
126void	pmcstat_print_counters(struct pmcstat_args *_a);
127void	pmcstat_print_headers(struct pmcstat_args *_a);
128void	pmcstat_print_pmcs(struct pmcstat_args *_a);
129void	pmcstat_show_usage(void);
130void	pmcstat_shutdown_logging(struct pmcstat_args *_a);
131void	pmcstat_start_pmcs(struct pmcstat_args *_a);
132void	pmcstat_start_process(void);
133int	pmcstat_process_log(struct pmcstat_args *_a);
134uint32_t pmcstat_get_cpumask(const char *_a);
135
136#endif	/* _PMCSTAT_H_ */
137