]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - usr.sbin/pmcstat/pmcstat.h
MFC r326276:
[FreeBSD/FreeBSD.git] / usr.sbin / pmcstat / pmcstat.h
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3  *
4  * Copyright (c) 2005-2007, Joseph Koshy
5  * Copyright (c) 2007 The FreeBSD Foundation
6  * All rights reserved.
7  *
8  * Portions of this software were developed by A. Joseph Koshy under
9  * sponsorship from the FreeBSD Foundation and Google, Inc.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30  * SUCH DAMAGE.
31  *
32  * $FreeBSD$
33  */
34
35 #ifndef _PMCSTAT_H_
36 #define _PMCSTAT_H_
37
38 #include <sys/_cpuset.h>
39
40 #define FLAG_HAS_TARGET                 0x00000001      /* process target */
41 #define FLAG_HAS_WAIT_INTERVAL          0x00000002      /* -w secs */
42 #define FLAG_HAS_OUTPUT_LOGFILE         0x00000004      /* -O file or pipe */
43 #define FLAG_HAS_COMMANDLINE            0x00000008      /* command */
44 #define FLAG_HAS_SAMPLING_PMCS          0x00000010      /* -S or -P */
45 #define FLAG_HAS_COUNTING_PMCS          0x00000020      /* -s or -p */
46 #define FLAG_HAS_PROCESS_PMCS           0x00000040      /* -P or -p */
47 #define FLAG_HAS_SYSTEM_PMCS            0x00000080      /* -S or -s */
48 #define FLAG_HAS_PIPE                   0x00000100      /* implicit log */
49 #define FLAG_READ_LOGFILE               0x00000200      /* -R file */
50 #define FLAG_DO_GPROF                   0x00000400      /* -g */
51 #define FLAG_HAS_SAMPLESDIR             0x00000800      /* -D dir */
52 #define FLAG_HAS_KERNELPATH             0x00001000      /* -k kernel */
53 #define FLAG_DO_PRINT                   0x00002000      /* -o */
54 #define FLAG_DO_CALLGRAPHS              0x00004000      /* -G or -F */
55 #define FLAG_DO_ANNOTATE                0x00008000      /* -m */
56 #define FLAG_DO_TOP                     0x00010000      /* -T */
57 #define FLAG_DO_ANALYSIS                0x00020000      /* -g or -G or -m or -T */
58 #define FLAGS_HAS_CPUMASK               0x00040000      /* -c */
59 #define FLAG_HAS_DURATION               0x00080000      /* -l secs */
60 #define FLAG_DO_WIDE_GPROF_HC           0x00100000      /* -e */
61
62 #define DEFAULT_SAMPLE_COUNT            65536
63 #define DEFAULT_WAIT_INTERVAL           5.0
64 #define DEFAULT_DISPLAY_HEIGHT          256             /* file virtual height */
65 #define DEFAULT_DISPLAY_WIDTH           1024            /* file virtual width */
66 #define DEFAULT_BUFFER_SIZE             4096
67 #define DEFAULT_CALLGRAPH_DEPTH         16
68
69 #define PRINT_HEADER_PREFIX             "# "
70 #define READPIPEFD                      0
71 #define WRITEPIPEFD                     1
72 #define NPIPEFD                         2
73
74 #define NSOCKPAIRFD                     2
75 #define PARENTSOCKET                    0
76 #define CHILDSOCKET                     1
77
78 #define PMCSTAT_OPEN_FOR_READ           0
79 #define PMCSTAT_OPEN_FOR_WRITE          1
80 #define PMCSTAT_DEFAULT_NW_HOST         "localhost"
81 #define PMCSTAT_DEFAULT_NW_PORT         "9000"
82 #define PMCSTAT_NHASH                   256
83 #define PMCSTAT_HASH_MASK               0xFF
84
85 #define PMCSTAT_LDD_COMMAND             "/usr/bin/ldd"
86
87 #define PMCSTAT_PRINT_ENTRY(T,...) do {                                 \
88                 (void) fprintf(args.pa_printfile, "%-9s", T);           \
89                 (void) fprintf(args.pa_printfile, " "  __VA_ARGS__);    \
90                 (void) fprintf(args.pa_printfile, "\n");                \
91         } while (0)
92
93 #define PMCSTAT_PL_NONE         0
94 #define PMCSTAT_PL_CALLGRAPH    1
95 #define PMCSTAT_PL_GPROF        2
96 #define PMCSTAT_PL_ANNOTATE     3
97 #define PMCSTAT_PL_CALLTREE     4
98 #define PMCSTAT_PL_ANNOTATE_CG  5
99
100 #define PMCSTAT_TOP_DELTA       0
101 #define PMCSTAT_TOP_ACCUM       1
102
103 #define min(A,B)                ((A) < (B) ? (A) : (B))
104 #define max(A,B)                ((A) > (B) ? (A) : (B))
105
106 enum pmcstat_state {
107         PMCSTAT_FINISHED = 0,
108         PMCSTAT_EXITING  = 1,
109         PMCSTAT_RUNNING  = 2
110 };
111
112 struct pmcstat_ev {
113         STAILQ_ENTRY(pmcstat_ev) ev_next;
114         int             ev_count; /* associated count if in sampling mode */
115         uint32_t        ev_cpu;   /* cpus for this event */
116         int             ev_cumulative;  /* show cumulative counts */
117         int             ev_flags; /* PMC_F_* */
118         int             ev_fieldskip;   /* #leading spaces */
119         int             ev_fieldwidth;  /* print width */
120         enum pmc_mode   ev_mode;  /* desired mode */
121         char           *ev_name;  /* (derived) event name */
122         pmc_id_t        ev_pmcid; /* allocated ID */
123         pmc_value_t     ev_saved; /* for incremental counts */
124         char           *ev_spec;  /* event specification */
125 };
126
127 struct pmcstat_target {
128         SLIST_ENTRY(pmcstat_target) pt_next;
129         pid_t           pt_pid;
130 };
131
132 struct pmcstat_args {
133         int     pa_flags;               /* argument flags */
134         int     pa_required;            /* required features */
135         int     pa_pplugin;             /* pre-processing plugin */
136         int     pa_plugin;              /* analysis plugin */
137         int     pa_verbosity;           /* verbosity level */
138         FILE    *pa_printfile;          /* where to send printed output */
139         int     pa_logfd;               /* output log file */
140         char    *pa_inputpath;          /* path to input log */
141         char    *pa_outputpath;         /* path to output log */
142         void    *pa_logparser;          /* log file parser */
143         const char      *pa_fsroot;     /* FS root where executables reside */
144         char    *pa_kernel;             /* pathname of the kernel */
145         const char      *pa_samplesdir; /* directory for profile files */
146         const char      *pa_mapfilename;/* mapfile name */
147         FILE    *pa_graphfile;          /* where to send the callgraph */
148         int     pa_graphdepth;          /* print depth for callgraphs */
149         double  pa_interval;            /* printing interval in seconds */
150         cpuset_t        pa_cpumask;     /* filter for CPUs analysed */
151         int     pa_ctdumpinstr;         /* dump instructions with calltree */
152         int     pa_topmode;             /* delta or accumulative */
153         int     pa_toptty;              /* output to tty or file */
154         int     pa_topcolor;            /* terminal support color */
155         int     pa_mergepmc;            /* merge PMC with same name */
156         double  pa_duration;            /* time duration */
157         int     pa_argc;
158         char    **pa_argv;
159         STAILQ_HEAD(, pmcstat_ev) pa_events;
160         SLIST_HEAD(, pmcstat_target) pa_targets;
161 };
162
163 extern int pmcstat_displayheight;       /* current terminal height */
164 extern int pmcstat_displaywidth;        /* current terminal width */
165 extern struct pmcstat_args args;        /* command line args */
166
167 /* Function prototypes */
168 void    pmcstat_attach_pmcs(void);
169 void    pmcstat_cleanup(void);
170 int     pmcstat_close_log(void);
171 void    pmcstat_create_process(void);
172 void    pmcstat_find_targets(const char *_arg);
173 void    pmcstat_initialize_logging(void);
174 void    pmcstat_kill_process(void);
175 int     pmcstat_open_log(const char *_p, int _mode);
176 void    pmcstat_print_counters(void);
177 void    pmcstat_print_headers(void);
178 void    pmcstat_print_pmcs(void);
179 void    pmcstat_show_usage(void);
180 void    pmcstat_shutdown_logging(void);
181 void    pmcstat_start_pmcs(void);
182 void    pmcstat_start_process(void);
183 int     pmcstat_process_log(void);
184 int     pmcstat_keypress_log(void);
185 void    pmcstat_display_log(void);
186 void    pmcstat_pluginconfigure_log(char *_opt);
187 void    pmcstat_topexit(void);
188
189 #endif  /* _PMCSTAT_H_ */