2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2005-2007, Joseph Koshy
5 * Copyright (c) 2007 The FreeBSD Foundation
6 * Copyright (c) 2009, Fabien Thomas
9 * Portions of this software were developed by A. Joseph Koshy under
10 * sponsorship from the FreeBSD Foundation and Google, Inc.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 #ifndef _PMCSTAT_LOG_H_
37 #define _PMCSTAT_LOG_H_
39 typedef const void *pmcstat_interned_string;
42 * A 'pmcstat_process' structure models processes. Each process is
43 * associated with a set of pmcstat_pcmap structures that map
44 * addresses inside it to executable objects. This set is implemented
45 * as a list, kept sorted in ascending order of mapped addresses.
47 * 'pp_pid' holds the pid of the process. When a process exits, the
48 * 'pp_isactive' field is set to zero, but the process structure is
49 * not immediately reclaimed because there may still be samples in the
50 * log for this process.
53 struct pmcstat_process {
54 LIST_ENTRY(pmcstat_process) pp_next; /* hash-next */
55 pid_t pp_pid; /* associated pid */
56 int pp_isactive; /* whether active */
57 uintfptr_t pp_entryaddr; /* entry address */
58 TAILQ_HEAD(,pmcstat_pcmap) pp_map; /* address range map */
60 extern LIST_HEAD(pmcstat_process_hash_list, pmcstat_process) pmcstat_process_hash[PMCSTAT_NHASH];
63 * A 'pmcstat_image' structure describes an executable program on
64 * disk. 'pi_execpath' is a cookie representing the pathname of
65 * the executable. 'pi_start' and 'pi_end' are the least and greatest
66 * virtual addresses for the text segments in the executable.
67 * 'pi_gmonlist' contains a linked list of gmon.out files associated
71 enum pmcstat_image_type {
72 PMCSTAT_IMAGE_UNKNOWN = 0, /* never looked at the image */
73 PMCSTAT_IMAGE_INDETERMINABLE, /* can't tell what the image is */
74 PMCSTAT_IMAGE_ELF32, /* ELF 32 bit object */
75 PMCSTAT_IMAGE_ELF64, /* ELF 64 bit object */
76 PMCSTAT_IMAGE_AOUT /* AOUT object */
79 struct pmcstat_image {
80 LIST_ENTRY(pmcstat_image) pi_next; /* hash link */
81 pmcstat_interned_string pi_execpath; /* cookie */
82 pmcstat_interned_string pi_samplename; /* sample path name */
83 pmcstat_interned_string pi_fullpath; /* path to FS object */
84 pmcstat_interned_string pi_name; /* display name */
86 enum pmcstat_image_type pi_type; /* executable type */
89 * Executables have pi_start and pi_end; these are zero
90 * for shared libraries.
92 uintfptr_t pi_start; /* start address (inclusive) */
93 uintfptr_t pi_end; /* end address (exclusive) */
94 uintfptr_t pi_entry; /* entry address */
95 uintfptr_t pi_vaddr; /* virtual address where loaded */
96 int pi_isdynamic; /* whether a dynamic object */
97 int pi_iskernelmodule;
98 pmcstat_interned_string pi_dynlinkerpath; /* path in .interp */
100 /* All symbols associated with this object. */
101 struct pmcstat_symbol *pi_symbols;
104 /* Handle to addr2line for this image. */
108 * Plugins private data
112 * An image can be associated with one or more gmon.out files;
115 LIST_HEAD(,pmcstat_gmonfile) pi_gmlist;
117 extern LIST_HEAD(pmcstat_image_hash_list, pmcstat_image) pmcstat_image_hash[PMCSTAT_NHASH];
120 * A 'pmcstat_pcmap' structure maps a virtual address range to an
121 * underlying 'pmcstat_image' descriptor.
123 struct pmcstat_pcmap {
124 TAILQ_ENTRY(pmcstat_pcmap) ppm_next;
125 uintfptr_t ppm_lowpc;
126 uintfptr_t ppm_highpc;
127 struct pmcstat_image *ppm_image;
131 * Each function symbol tracked by pmcstat(8).
134 struct pmcstat_symbol {
135 pmcstat_interned_string ps_name;
141 * 'pmcstat_pmcrecord' is a mapping from PMC ids to human-readable
145 struct pmcstat_pmcrecord {
146 LIST_ENTRY(pmcstat_pmcrecord) pr_next;
149 pmcstat_interned_string pr_pmcname;
151 int pr_dubious_frames;
152 struct pmcstat_pmcrecord *pr_merge;
154 extern LIST_HEAD(pmcstat_pmcs, pmcstat_pmcrecord) pmcstat_pmcs; /* PMC list */
159 struct pmcstat_stats {
160 int ps_exec_aout; /* # a.out executables seen */
161 int ps_exec_elf; /* # elf executables seen */
162 int ps_exec_errors; /* # errors processing executables */
163 int ps_exec_indeterminable; /* # unknown executables seen */
164 int ps_samples_total; /* total number of samples processed */
165 int ps_samples_skipped; /* #samples filtered out for any reason */
166 int ps_samples_unknown_offset; /* #samples of rank 0 not in a map */
167 int ps_samples_indeterminable; /* #samples in indeterminable images */
168 int ps_samples_unknown_function;/* #samples with unknown function at offset */
169 int ps_callchain_dubious_frames;/* #dubious frame pointers seen */
171 extern struct pmcstat_stats pmcstat_stats; /* statistics */
173 extern struct pmcstat_process *pmcstat_kernproc; /* kernel 'process' */
175 extern int pmcstat_npmcs; /* PMC count. */
178 * Top mode global options.
180 extern float pmcstat_threshold; /* Threshold to filter node. */
181 extern int pmcstat_pmcinfilter; /* PMC index displayed. */
183 /* Function prototypes */
184 const char *pmcstat_pmcid_to_name(pmc_id_t _pmcid);
185 const char *pmcstat_pmcindex_to_name(int pmcin);
186 struct pmcstat_pmcrecord *pmcstat_pmcindex_to_pmcr(int pmcin);
187 struct pmcstat_pcmap *pmcstat_process_find_map(struct pmcstat_process *_p,
189 struct pmcstat_symbol *pmcstat_symbol_search(struct pmcstat_image *image,
191 const char *pmcstat_string_unintern(pmcstat_interned_string _is);
192 pmcstat_interned_string pmcstat_string_intern(const char *_s);
193 void pmcstat_image_determine_type(struct pmcstat_image *_image);
194 pmcstat_interned_string pmcstat_string_lookup(const char *_s);
195 int pmcstat_image_addr2line(struct pmcstat_image *image, uintfptr_t addr,
196 char *sourcefile, size_t sourcefile_len, unsigned *sourceline,
197 char *funcname, size_t funcname_len);
199 #endif /* _PMCSTAT_LOG_H_ */