pmcstat_log.h revision 203790
1261991Sdim/*-
2218885Sdim * Copyright (c) 2005-2007, Joseph Koshy
3218885Sdim * Copyright (c) 2007 The FreeBSD Foundation
4218885Sdim * Copyright (c) 2009, Fabien Thomas
5218885Sdim * All rights reserved.
6218885Sdim *
7218885Sdim * Portions of this software were developed by A. Joseph Koshy under
8218885Sdim * sponsorship from the FreeBSD Foundation and Google, Inc.
9218885Sdim *
10261991Sdim * Redistribution and use in source and binary forms, with or without
11218885Sdim * modification, are permitted provided that the following conditions
12218885Sdim * are met:
13218885Sdim * 1. Redistributions of source code must retain the above copyright
14218885Sdim *    notice, this list of conditions and the following disclaimer.
15261991Sdim * 2. Redistributions in binary form must reproduce the above copyright
16261991Sdim *    notice, this list of conditions and the following disclaimer in the
17218885Sdim *    documentation and/or other materials provided with the distribution.
18218885Sdim *
19261991Sdim * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20276479Sdim * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21261991Sdim * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22261991Sdim * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23261991Sdim * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24261991Sdim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25218885Sdim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26276479Sdim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27276479Sdim * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28276479Sdim * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29276479Sdim * SUCH DAMAGE.
30276479Sdim *
31261991Sdim * $FreeBSD: head/usr.sbin/pmcstat/pmcstat_log.h 203790 2010-02-11 22:51:44Z fabient $
32218885Sdim */
33261991Sdim
34261991Sdim#ifndef	_PMCSTAT_LOG_H_
35261991Sdim#define	_PMCSTAT_LOG_H_
36261991Sdim
37261991Sdimtypedef const void *pmcstat_interned_string;
38218885Sdim
39261991Sdim/*
40261991Sdim * A 'pmcstat_process' structure models processes.  Each process is
41261991Sdim * associated with a set of pmcstat_pcmap structures that map
42218885Sdim * addresses inside it to executable objects.  This set is implemented
43261991Sdim * as a list, kept sorted in ascending order of mapped addresses.
44218885Sdim *
45261991Sdim * 'pp_pid' holds the pid of the process.  When a process exits, the
46261991Sdim * 'pp_isactive' field is set to zero, but the process structure is
47280031Sdim * not immediately reclaimed because there may still be samples in the
48218885Sdim * log for this process.
49276479Sdim */
50276479Sdim
51261991Sdimstruct pmcstat_process {
52218885Sdim	LIST_ENTRY(pmcstat_process) pp_next;	/* hash-next */
53276479Sdim	pid_t			pp_pid;		/* associated pid */
54276479Sdim	int			pp_isactive;	/* whether active */
55276479Sdim	uintfptr_t		pp_entryaddr;	/* entry address */
56276479Sdim	TAILQ_HEAD(,pmcstat_pcmap) pp_map;	/* address range map */
57276479Sdim};
58276479Sdimextern LIST_HEAD(pmcstat_process_hash_list, pmcstat_process) pmcstat_process_hash[PMCSTAT_NHASH];
59276479Sdim
60218885Sdim/*
61218885Sdim * A 'pmcstat_image' structure describes an executable program on
62218885Sdim * disk.  'pi_execpath' is a cookie representing the pathname of
63261991Sdim * the executable.  'pi_start' and 'pi_end' are the least and greatest
64261991Sdim * virtual addresses for the text segments in the executable.
65280031Sdim * 'pi_gmonlist' contains a linked list of gmon.out files associated
66280031Sdim * with this image.
67280031Sdim */
68280031Sdim
69280031Sdimenum pmcstat_image_type {
70280031Sdim	PMCSTAT_IMAGE_UNKNOWN = 0,	/* never looked at the image */
71280031Sdim	PMCSTAT_IMAGE_INDETERMINABLE,	/* can't tell what the image is */
72280031Sdim	PMCSTAT_IMAGE_ELF32,		/* ELF 32 bit object */
73280031Sdim	PMCSTAT_IMAGE_ELF64,		/* ELF 64 bit object */
74280031Sdim	PMCSTAT_IMAGE_AOUT		/* AOUT object */
75280031Sdim};
76280031Sdim
77280031Sdimstruct pmcstat_image {
78280031Sdim	LIST_ENTRY(pmcstat_image) pi_next;	/* hash link */
79280031Sdim	TAILQ_ENTRY(pmcstat_image) pi_lru;	/* LRU list */
80280031Sdim	pmcstat_interned_string	pi_execpath;    /* cookie */
81280031Sdim	pmcstat_interned_string pi_samplename;  /* sample path name */
82280031Sdim	pmcstat_interned_string pi_fullpath;    /* path to FS object */
83280031Sdim	pmcstat_interned_string pi_name;	/* display name */
84280031Sdim
85280031Sdim	enum pmcstat_image_type pi_type;	/* executable type */
86280031Sdim
87280031Sdim	/*
88280031Sdim	 * Executables have pi_start and pi_end; these are zero
89280031Sdim	 * for shared libraries.
90280031Sdim	 */
91280031Sdim	uintfptr_t	pi_start;	/* start address (inclusive) */
92280031Sdim	uintfptr_t	pi_end;		/* end address (exclusive) */
93280031Sdim	uintfptr_t	pi_entry;	/* entry address */
94280031Sdim	uintfptr_t	pi_vaddr;	/* virtual address where loaded */
95280031Sdim	int		pi_isdynamic;	/* whether a dynamic object */
96280031Sdim	int		pi_iskernelmodule;
97280031Sdim	pmcstat_interned_string pi_dynlinkerpath; /* path in .interp */
98280031Sdim
99280031Sdim	/* All symbols associated with this object. */
100280031Sdim	struct pmcstat_symbol *pi_symbols;
101280031Sdim	size_t		pi_symcount;
102280031Sdim
103280031Sdim	/* Handle to addr2line for this image. */
104280031Sdim	FILE *pi_addr2line;
105280031Sdim
106280031Sdim	/*
107280031Sdim	 * Plugins private data
108280031Sdim	 */
109280031Sdim
110280031Sdim	/* gprof:
111280031Sdim	 * An image can be associated with one or more gmon.out files;
112280031Sdim	 * one per PMC.
113280031Sdim	 */
114280031Sdim	LIST_HEAD(,pmcstat_gmonfile) pi_gmlist;
115280031Sdim};
116280031Sdimextern LIST_HEAD(pmcstat_image_hash_list, pmcstat_image) pmcstat_image_hash[PMCSTAT_NHASH];
117280031Sdim
118280031Sdim/*
119280031Sdim * A 'pmcstat_pcmap' structure maps a virtual address range to an
120280031Sdim * underlying 'pmcstat_image' descriptor.
121261991Sdim */
122218885Sdimstruct pmcstat_pcmap {
123261991Sdim	TAILQ_ENTRY(pmcstat_pcmap) ppm_next;
124261991Sdim	uintfptr_t	ppm_lowpc;
125261991Sdim	uintfptr_t	ppm_highpc;
126218885Sdim	struct pmcstat_image *ppm_image;
127261991Sdim};
128261991Sdim
129261991Sdim/*
130218885Sdim * Each function symbol tracked by pmcstat(8).
131261991Sdim */
132261991Sdim
133261991Sdimstruct pmcstat_symbol {
134261991Sdim	pmcstat_interned_string ps_name;
135218885Sdim	uint64_t	ps_start;
136261991Sdim	uint64_t	ps_end;
137261991Sdim};
138261991Sdim
139218885Sdim/*
140261991Sdim * 'pmcstat_pmcrecord' is a mapping from PMC ids to human-readable
141261991Sdim * names.
142261991Sdim */
143261991Sdim
144218885Sdimstruct pmcstat_pmcrecord {
145261991Sdim	LIST_ENTRY(pmcstat_pmcrecord)	pr_next;
146218885Sdim	pmc_id_t			pr_pmcid;
147218885Sdim	int				pr_pmcin;
148261991Sdim	pmcstat_interned_string		pr_pmcname;
149261991Sdim	struct pmcstat_pmcrecord	*pr_merge;
150261991Sdim};
151261991Sdimextern LIST_HEAD(pmcstat_pmcs, pmcstat_pmcrecord) pmcstat_pmcs; /* PMC list */
152261991Sdim
153261991Sdim/*
154261991Sdim * Misc. statistics
155218885Sdim */
156218885Sdimstruct pmcstat_stats {
157261991Sdim	int ps_exec_aout;	/* # a.out executables seen */
158261991Sdim	int ps_exec_elf;	/* # elf executables seen */
159261991Sdim	int ps_exec_errors;	/* # errors processing executables */
160261991Sdim	int ps_exec_indeterminable; /* # unknown executables seen */
161218885Sdim	int ps_samples_total;	/* total number of samples processed */
162261991Sdim	int ps_samples_skipped; /* #samples filtered out for any reason */
163261991Sdim	int ps_samples_unknown_offset;	/* #samples of rank 0 not in a map */
164261991Sdim	int ps_samples_indeterminable;	/* #samples in indeterminable images */
165218885Sdim	int ps_callchain_dubious_frames;/* #dubious frame pointers seen */
166218885Sdim};
167276479Sdimextern struct pmcstat_stats pmcstat_stats; /* statistics */
168261991Sdim
169261991Sdimextern struct pmcstat_process *pmcstat_kernproc; /* kernel 'process' */
170218885Sdim
171261991Sdimextern int pmcstat_npmcs; /* PMC count. */
172261991Sdim
173261991Sdim/*
174218885Sdim * Top mode global options.
175261991Sdim */
176261991Sdimfloat pmcstat_threshold; /* Threshold to filter node. */
177261991Sdimint pmcstat_pmcinfilter; /* PMC index displayed. */
178218885Sdim
179261991Sdim/* Function prototypes */
180261991Sdimconst char *pmcstat_pmcid_to_name(pmc_id_t _pmcid);
181261991Sdimconst char *pmcstat_pmcindex_to_name(int pmcin);
182261991Sdimstruct pmcstat_pmcrecord *pmcstat_pmcindex_to_pmcr(int pmcin);
183261991Sdimstruct pmcstat_pcmap *pmcstat_process_find_map(struct pmcstat_process *_p,
184261991Sdim	uintfptr_t _pc);
185261991Sdimstruct pmcstat_symbol *pmcstat_symbol_search(struct pmcstat_image *image,
186261991Sdim	uintfptr_t addr);
187218885Sdimconst char *pmcstat_string_unintern(pmcstat_interned_string _is);
188218885Sdimpmcstat_interned_string pmcstat_string_intern(const char *_s);
189276479Sdimvoid pmcstat_image_determine_type(struct pmcstat_image *_image);
190261991Sdimpmcstat_interned_string pmcstat_string_lookup(const char *_s);
191218885Sdimint pmcstat_image_addr2line(struct pmcstat_image *image, uintfptr_t addr,
192280031Sdim    char *sourcefile, size_t sourcefile_len, unsigned *sourceline,
193261991Sdim    char *funcname, size_t funcname_len);
194218885Sdim
195261991Sdim#endif	/* _PMCSTAT_LOG_H_ */
196276479Sdim
197276479Sdim