2 * Copyright (c) 2005-2007, Joseph Koshy
3 * Copyright (c) 2007 The FreeBSD Foundation
6 * Portions of this software were developed by A. Joseph Koshy under
7 * sponsorship from the FreeBSD Foundation and Google, Inc.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 #define FLAG_HAS_TARGET 0x00000001 /* process target */
37 #define FLAG_HAS_WAIT_INTERVAL 0x00000002 /* -w secs */
38 #define FLAG_HAS_OUTPUT_LOGFILE 0x00000004 /* -O file or pipe */
39 #define FLAG_HAS_COMMANDLINE 0x00000008 /* command */
40 #define FLAG_HAS_SAMPLING_PMCS 0x00000010 /* -S or -P */
41 #define FLAG_HAS_COUNTING_PMCS 0x00000020 /* -s or -p */
42 #define FLAG_HAS_PROCESS_PMCS 0x00000040 /* -P or -p */
43 #define FLAG_HAS_SYSTEM_PMCS 0x00000080 /* -S or -s */
44 #define FLAG_HAS_PIPE 0x00000100 /* implicit log */
45 #define FLAG_READ_LOGFILE 0x00000200 /* -R file */
46 #define FLAG_DO_GPROF 0x00000400 /* -g */
47 #define FLAG_HAS_SAMPLESDIR 0x00000800 /* -D dir */
48 #define FLAG_HAS_KERNELPATH 0x00001000 /* -k kernel */
49 #define FLAG_DO_PRINT 0x00002000 /* -o */
50 #define FLAG_DO_CALLGRAPHS 0x00004000 /* -G */
51 #define FLAG_DO_ANALYSIS 0x00008000 /* -g or -G */
53 #define DEFAULT_SAMPLE_COUNT 65536
54 #define DEFAULT_WAIT_INTERVAL 5.0
55 #define DEFAULT_DISPLAY_HEIGHT 23
56 #define DEFAULT_BUFFER_SIZE 4096
57 #define DEFAULT_CALLGRAPH_DEPTH 4
59 #define PRINT_HEADER_PREFIX "# "
65 #define PARENTSOCKET 0
68 #define PMCSTAT_OPEN_FOR_READ 0
69 #define PMCSTAT_OPEN_FOR_WRITE 1
70 #define PMCSTAT_DEFAULT_NW_HOST "localhost"
71 #define PMCSTAT_DEFAULT_NW_PORT "9000"
72 #define PMCSTAT_NHASH 256
73 #define PMCSTAT_HASH_MASK 0xFF
75 #define PMCSTAT_LDD_COMMAND "/usr/bin/ldd"
77 #define PMCSTAT_PRINT_ENTRY(A,T,...) do { \
78 (void) fprintf((A)->pa_printfile, "%-9s", T); \
79 (void) fprintf((A)->pa_printfile, " " __VA_ARGS__); \
80 (void) fprintf((A)->pa_printfile, "\n"); \
90 STAILQ_ENTRY(pmcstat_ev) ev_next;
91 int ev_count; /* associated count if in sampling mode */
92 uint32_t ev_cpu; /* cpus for this event */
93 int ev_cumulative; /* show cumulative counts */
94 int ev_flags; /* PMC_F_* */
95 int ev_fieldskip; /* #leading spaces */
96 int ev_fieldwidth; /* print width */
97 enum pmc_mode ev_mode; /* desired mode */
98 char *ev_name; /* (derived) event name */
99 pmc_id_t ev_pmcid; /* allocated ID */
100 pmc_value_t ev_saved; /* for incremental counts */
101 char *ev_spec; /* event specification */
104 struct pmcstat_target {
105 SLIST_ENTRY(pmcstat_target) pt_next;
109 struct pmcstat_args {
110 int pa_flags; /* argument flags */
111 int pa_required; /* required features */
112 int pa_verbosity; /* verbosity level */
113 FILE *pa_printfile; /* where to send printed output */
114 int pa_logfd; /* output log file */
115 char *pa_inputpath; /* path to input log */
116 char *pa_outputpath; /* path to output log */
117 void *pa_logparser; /* log file parser */
118 const char *pa_fsroot; /* FS root where executables reside */
119 char *pa_kernel; /* pathname of the kernel */
120 const char *pa_samplesdir; /* directory for profile files */
121 const char *pa_mapfilename;/* mapfile name */
122 FILE *pa_graphfile; /* where to send the callgraph */
123 int pa_graphdepth; /* print depth for callgraphs */
124 double pa_interval; /* printing interval in seconds */
125 uint32_t pa_cpumask; /* filter for CPUs analysed */
128 STAILQ_HEAD(, pmcstat_ev) pa_events;
129 SLIST_HEAD(, pmcstat_target) pa_targets;
132 /* Function prototypes */
133 void pmcstat_attach_pmcs(struct pmcstat_args *_a);
134 void pmcstat_cleanup(struct pmcstat_args *_a);
135 void pmcstat_clone_event_descriptor(struct pmcstat_args *_a,
136 struct pmcstat_ev *_ev, uint32_t _cpumask);
137 int pmcstat_close_log(struct pmcstat_args *_a);
138 void pmcstat_create_process(struct pmcstat_args *_a);
139 void pmcstat_find_targets(struct pmcstat_args *_a, const char *_arg);
140 void pmcstat_initialize_logging(struct pmcstat_args *_a);
141 void pmcstat_kill_process(struct pmcstat_args *_a);
142 int pmcstat_open_log(const char *_p, int _mode);
143 void pmcstat_print_counters(struct pmcstat_args *_a);
144 void pmcstat_print_headers(struct pmcstat_args *_a);
145 void pmcstat_print_pmcs(struct pmcstat_args *_a);
146 void pmcstat_show_usage(void);
147 void pmcstat_shutdown_logging(struct pmcstat_args *_a);
148 void pmcstat_start_pmcs(struct pmcstat_args *_a);
149 void pmcstat_start_process(void);
150 int pmcstat_process_log(struct pmcstat_args *_a);
151 uint32_t pmcstat_get_cpumask(const char *_a);
153 #endif /* _PMCSTAT_H_ */