]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - usr.sbin/pmcstat/pmcstat.h
This commit was generated by cvs2svn to compensate for changes in r165254,
[FreeBSD/FreeBSD.git] / usr.sbin / pmcstat / pmcstat.h
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$
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 PMCSTAT_OPEN_FOR_READ           0
58 #define PMCSTAT_OPEN_FOR_WRITE          1
59 #define PMCSTAT_DEFAULT_NW_HOST         "localhost"
60 #define PMCSTAT_DEFAULT_NW_PORT         "9000"
61 #define PMCSTAT_NHASH                   256
62 #define PMCSTAT_HASH_MASK               0xFF
63
64 #define PMCSTAT_LDD_COMMAND             "/usr/bin/ldd"
65
66 #define PMCSTAT_PRINT_ENTRY(A,T,...) do {                               \
67                 fprintf((A)->pa_printfile, "%-8s", T);                  \
68                 fprintf((A)->pa_printfile, " "  __VA_ARGS__);           \
69                 fprintf((A)->pa_printfile, "\n");                       \
70         } while (0)
71
72 enum pmcstat_state {
73         PMCSTAT_FINISHED = 0,
74         PMCSTAT_EXITING  = 1,
75         PMCSTAT_RUNNING  = 2
76 };
77
78 struct pmcstat_ev {
79         STAILQ_ENTRY(pmcstat_ev) ev_next;
80         char           *ev_spec;  /* event specification */
81         char           *ev_name;  /* (derived) event name */
82         enum pmc_mode   ev_mode;  /* desired mode */
83         int             ev_count; /* associated count if in sampling mode */
84         int             ev_cpu;   /* specific cpu if requested */
85         int             ev_flags; /* PMC_F_* */
86         int             ev_cumulative;  /* show cumulative counts */
87         int             ev_fieldwidth;  /* print width */
88         int             ev_fieldskip;   /* #leading spaces */
89         pmc_value_t     ev_saved; /* saved value for incremental counts */
90         pmc_id_t        ev_pmcid; /* allocated ID */
91 };
92
93 struct pmcstat_args {
94         int     pa_flags;               /* argument flags */
95         int     pa_required;            /* required features */
96         int     pa_verbosity;           /* verbosity level */
97         pid_t   pa_pid;                 /* attached to pid */
98         FILE    *pa_printfile;          /* where to send printed output */
99         int     pa_logfd;               /* output log file */
100         char    *pa_inputpath;          /* path to input log */
101         char    *pa_outputpath;         /* path to output log */
102         void    *pa_logparser;          /* log file parser */
103         const char      *pa_fsroot;     /* FS root where executables reside */
104         char    *pa_kernel;             /* pathname of the kernel */
105         const char      *pa_samplesdir; /* directory for profile files */
106         const char      *pa_mapfilename;/* mapfile name */
107         double  pa_interval;            /* printing interval in seconds */
108         int     pa_argc;
109         char    **pa_argv;
110         STAILQ_HEAD(, pmcstat_ev) pa_head;
111 } args;
112
113 /* Function prototypes */
114 void    pmcstat_cleanup(struct pmcstat_args *_a);
115 int     pmcstat_close_log(struct pmcstat_args *_a);
116 void    pmcstat_initialize_logging(struct pmcstat_args *_a);
117 int     pmcstat_open_log(const char *_p, int _mode);
118 void    pmcstat_print_counters(struct pmcstat_args *_a);
119 void    pmcstat_print_headers(struct pmcstat_args *_a);
120 void    pmcstat_print_pmcs(struct pmcstat_args *_a);
121 void    pmcstat_setup_process(struct pmcstat_args *_a);
122 void    pmcstat_show_usage(void);
123 void    pmcstat_shutdown_logging(struct pmcstat_args *_a);
124 void    pmcstat_start_pmcs(struct pmcstat_args *_a);
125 void    pmcstat_start_process(struct pmcstat_args *_a);
126 int     pmcstat_process_log(struct pmcstat_args *_a);
127
128 #endif  /* _PMCSTAT_H_ */