1147708Sjkoshy/*- 2169069Sjkoshy * Copyright (c) 2005-2007, Joseph Koshy 3174396Sjkoshy * Copyright (c) 2007 The FreeBSD Foundation 4147708Sjkoshy * All rights reserved. 5147708Sjkoshy * 6174396Sjkoshy * Portions of this software were developed by A. Joseph Koshy under 7174396Sjkoshy * sponsorship from the FreeBSD Foundation and Google, Inc. 8174396Sjkoshy * 9147708Sjkoshy * Redistribution and use in source and binary forms, with or without 10147708Sjkoshy * modification, are permitted provided that the following conditions 11147708Sjkoshy * are met: 12147708Sjkoshy * 1. Redistributions of source code must retain the above copyright 13147708Sjkoshy * notice, this list of conditions and the following disclaimer. 14147708Sjkoshy * 2. Redistributions in binary form must reproduce the above copyright 15147708Sjkoshy * notice, this list of conditions and the following disclaimer in the 16147708Sjkoshy * documentation and/or other materials provided with the distribution. 17147708Sjkoshy * 18147708Sjkoshy * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 19147708Sjkoshy * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20147708Sjkoshy * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21147708Sjkoshy * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 22147708Sjkoshy * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23147708Sjkoshy * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24147708Sjkoshy * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25147708Sjkoshy * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26147708Sjkoshy * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27147708Sjkoshy * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28147708Sjkoshy * SUCH DAMAGE. 29147708Sjkoshy * 30147708Sjkoshy * $FreeBSD: releng/10.2/usr.sbin/pmcstat/pmcstat.h 267143 2014-06-06 01:35:52Z emaste $ 31147708Sjkoshy */ 32147708Sjkoshy 33147708Sjkoshy#ifndef _PMCSTAT_H_ 34147708Sjkoshy#define _PMCSTAT_H_ 35147708Sjkoshy 36224698Sattilio#include <sys/_cpuset.h> 37224698Sattilio 38169069Sjkoshy#define FLAG_HAS_TARGET 0x00000001 /* process target */ 39147708Sjkoshy#define FLAG_HAS_WAIT_INTERVAL 0x00000002 /* -w secs */ 40147708Sjkoshy#define FLAG_HAS_OUTPUT_LOGFILE 0x00000004 /* -O file or pipe */ 41147708Sjkoshy#define FLAG_HAS_COMMANDLINE 0x00000008 /* command */ 42147708Sjkoshy#define FLAG_HAS_SAMPLING_PMCS 0x00000010 /* -S or -P */ 43147708Sjkoshy#define FLAG_HAS_COUNTING_PMCS 0x00000020 /* -s or -p */ 44147708Sjkoshy#define FLAG_HAS_PROCESS_PMCS 0x00000040 /* -P or -p */ 45147708Sjkoshy#define FLAG_HAS_SYSTEM_PMCS 0x00000080 /* -S or -s */ 46147708Sjkoshy#define FLAG_HAS_PIPE 0x00000100 /* implicit log */ 47147708Sjkoshy#define FLAG_READ_LOGFILE 0x00000200 /* -R file */ 48147708Sjkoshy#define FLAG_DO_GPROF 0x00000400 /* -g */ 49147708Sjkoshy#define FLAG_HAS_SAMPLESDIR 0x00000800 /* -D dir */ 50147708Sjkoshy#define FLAG_HAS_KERNELPATH 0x00001000 /* -k kernel */ 51147708Sjkoshy#define FLAG_DO_PRINT 0x00002000 /* -o */ 52203790Sfabient#define FLAG_DO_CALLGRAPHS 0x00004000 /* -G or -F */ 53203790Sfabient#define FLAG_DO_ANNOTATE 0x00008000 /* -m */ 54203790Sfabient#define FLAG_DO_TOP 0x00010000 /* -T */ 55203790Sfabient#define FLAG_DO_ANALYSIS 0x00020000 /* -g or -G or -m or -T */ 56210797Sfabient#define FLAGS_HAS_CPUMASK 0x00040000 /* -c */ 57266890Sgnn#define FLAG_HAS_DURATION 0x00080000 /* -l secs */ 58147708Sjkoshy 59147708Sjkoshy#define DEFAULT_SAMPLE_COUNT 65536 60147708Sjkoshy#define DEFAULT_WAIT_INTERVAL 5.0 61203790Sfabient#define DEFAULT_DISPLAY_HEIGHT 256 /* file virtual height */ 62203790Sfabient#define DEFAULT_DISPLAY_WIDTH 1024 /* file virtual width */ 63147708Sjkoshy#define DEFAULT_BUFFER_SIZE 4096 64267143Semaste#define DEFAULT_CALLGRAPH_DEPTH 16 65147708Sjkoshy 66147708Sjkoshy#define PRINT_HEADER_PREFIX "# " 67147708Sjkoshy#define READPIPEFD 0 68147708Sjkoshy#define WRITEPIPEFD 1 69147708Sjkoshy#define NPIPEFD 2 70147708Sjkoshy 71168949Sjkoshy#define NSOCKPAIRFD 2 72168949Sjkoshy#define PARENTSOCKET 0 73168949Sjkoshy#define CHILDSOCKET 1 74168949Sjkoshy 75147708Sjkoshy#define PMCSTAT_OPEN_FOR_READ 0 76147708Sjkoshy#define PMCSTAT_OPEN_FOR_WRITE 1 77147708Sjkoshy#define PMCSTAT_DEFAULT_NW_HOST "localhost" 78147708Sjkoshy#define PMCSTAT_DEFAULT_NW_PORT "9000" 79147708Sjkoshy#define PMCSTAT_NHASH 256 80147708Sjkoshy#define PMCSTAT_HASH_MASK 0xFF 81147708Sjkoshy 82147708Sjkoshy#define PMCSTAT_LDD_COMMAND "/usr/bin/ldd" 83147708Sjkoshy 84203790Sfabient#define PMCSTAT_PRINT_ENTRY(T,...) do { \ 85203790Sfabient (void) fprintf(args.pa_printfile, "%-9s", T); \ 86203790Sfabient (void) fprintf(args.pa_printfile, " " __VA_ARGS__); \ 87203790Sfabient (void) fprintf(args.pa_printfile, "\n"); \ 88147708Sjkoshy } while (0) 89147708Sjkoshy 90203790Sfabient#define PMCSTAT_PL_NONE 0 91203790Sfabient#define PMCSTAT_PL_CALLGRAPH 1 92203790Sfabient#define PMCSTAT_PL_GPROF 2 93203790Sfabient#define PMCSTAT_PL_ANNOTATE 3 94203790Sfabient#define PMCSTAT_PL_CALLTREE 4 95265604Sscottl#define PMCSTAT_PL_ANNOTATE_CG 5 96203790Sfabient 97203790Sfabient#define PMCSTAT_TOP_DELTA 0 98203790Sfabient#define PMCSTAT_TOP_ACCUM 1 99203790Sfabient 100203790Sfabient#define min(A,B) ((A) < (B) ? (A) : (B)) 101203790Sfabient#define max(A,B) ((A) > (B) ? (A) : (B)) 102203790Sfabient 103147708Sjkoshyenum pmcstat_state { 104147708Sjkoshy PMCSTAT_FINISHED = 0, 105147708Sjkoshy PMCSTAT_EXITING = 1, 106147708Sjkoshy PMCSTAT_RUNNING = 2 107147708Sjkoshy}; 108147708Sjkoshy 109147708Sjkoshystruct pmcstat_ev { 110147708Sjkoshy STAILQ_ENTRY(pmcstat_ev) ev_next; 111147708Sjkoshy int ev_count; /* associated count if in sampling mode */ 112168949Sjkoshy uint32_t ev_cpu; /* cpus for this event */ 113168949Sjkoshy int ev_cumulative; /* show cumulative counts */ 114147708Sjkoshy int ev_flags; /* PMC_F_* */ 115168949Sjkoshy int ev_fieldskip; /* #leading spaces */ 116147708Sjkoshy int ev_fieldwidth; /* print width */ 117168949Sjkoshy enum pmc_mode ev_mode; /* desired mode */ 118168949Sjkoshy char *ev_name; /* (derived) event name */ 119147708Sjkoshy pmc_id_t ev_pmcid; /* allocated ID */ 120168949Sjkoshy pmc_value_t ev_saved; /* for incremental counts */ 121168949Sjkoshy char *ev_spec; /* event specification */ 122147708Sjkoshy}; 123147708Sjkoshy 124169069Sjkoshystruct pmcstat_target { 125169069Sjkoshy SLIST_ENTRY(pmcstat_target) pt_next; 126169069Sjkoshy pid_t pt_pid; 127169069Sjkoshy}; 128169069Sjkoshy 129147708Sjkoshystruct pmcstat_args { 130147708Sjkoshy int pa_flags; /* argument flags */ 131147708Sjkoshy int pa_required; /* required features */ 132203790Sfabient int pa_pplugin; /* pre-processing plugin */ 133203790Sfabient int pa_plugin; /* analysis plugin */ 134157144Sjkoshy int pa_verbosity; /* verbosity level */ 135147708Sjkoshy FILE *pa_printfile; /* where to send printed output */ 136147708Sjkoshy int pa_logfd; /* output log file */ 137147708Sjkoshy char *pa_inputpath; /* path to input log */ 138147708Sjkoshy char *pa_outputpath; /* path to output log */ 139147708Sjkoshy void *pa_logparser; /* log file parser */ 140157144Sjkoshy const char *pa_fsroot; /* FS root where executables reside */ 141157144Sjkoshy char *pa_kernel; /* pathname of the kernel */ 142147708Sjkoshy const char *pa_samplesdir; /* directory for profile files */ 143157144Sjkoshy const char *pa_mapfilename;/* mapfile name */ 144174396Sjkoshy FILE *pa_graphfile; /* where to send the callgraph */ 145174396Sjkoshy int pa_graphdepth; /* print depth for callgraphs */ 146147708Sjkoshy double pa_interval; /* printing interval in seconds */ 147224698Sattilio cpuset_t pa_cpumask; /* filter for CPUs analysed */ 148203790Sfabient int pa_ctdumpinstr; /* dump instructions with calltree */ 149203790Sfabient int pa_topmode; /* delta or accumulative */ 150203790Sfabient int pa_toptty; /* output to tty or file */ 151203790Sfabient int pa_topcolor; /* terminal support color */ 152203790Sfabient int pa_mergepmc; /* merge PMC with same name */ 153266890Sgnn double pa_duration; /* time duration */ 154147708Sjkoshy int pa_argc; 155147708Sjkoshy char **pa_argv; 156169069Sjkoshy STAILQ_HEAD(, pmcstat_ev) pa_events; 157169069Sjkoshy SLIST_HEAD(, pmcstat_target) pa_targets; 158203790Sfabient}; 159147708Sjkoshy 160203790Sfabientextern int pmcstat_displayheight; /* current terminal height */ 161203790Sfabientextern int pmcstat_displaywidth; /* current terminal width */ 162203790Sfabientextern struct pmcstat_args args; /* command line args */ 163203790Sfabient 164147708Sjkoshy/* Function prototypes */ 165203790Sfabientvoid pmcstat_attach_pmcs(void); 166203790Sfabientvoid pmcstat_cleanup(void); 167203790Sfabientint pmcstat_close_log(void); 168203790Sfabientvoid pmcstat_create_process(void); 169203790Sfabientvoid pmcstat_find_targets(const char *_arg); 170203790Sfabientvoid pmcstat_initialize_logging(void); 171203790Sfabientvoid pmcstat_kill_process(void); 172157144Sjkoshyint pmcstat_open_log(const char *_p, int _mode); 173203790Sfabientvoid pmcstat_print_counters(void); 174203790Sfabientvoid pmcstat_print_headers(void); 175203790Sfabientvoid pmcstat_print_pmcs(void); 176147708Sjkoshyvoid pmcstat_show_usage(void); 177203790Sfabientvoid pmcstat_shutdown_logging(void); 178203790Sfabientvoid pmcstat_start_pmcs(void); 179168949Sjkoshyvoid pmcstat_start_process(void); 180203790Sfabientint pmcstat_process_log(void); 181203790Sfabientint pmcstat_keypress_log(void); 182203790Sfabientvoid pmcstat_display_log(void); 183203790Sfabientvoid pmcstat_pluginconfigure_log(char *_opt); 184203790Sfabientvoid pmcstat_topexit(void); 185147708Sjkoshy 186147708Sjkoshy#endif /* _PMCSTAT_H_ */ 187