pmcstat.h revision 210797
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: head/usr.sbin/pmcstat/pmcstat.h 210797 2010-08-03 13:46:25Z fabient $ 31147708Sjkoshy */ 32147708Sjkoshy 33147708Sjkoshy#ifndef _PMCSTAT_H_ 34147708Sjkoshy#define _PMCSTAT_H_ 35147708Sjkoshy 36169069Sjkoshy#define FLAG_HAS_TARGET 0x00000001 /* process target */ 37147708Sjkoshy#define FLAG_HAS_WAIT_INTERVAL 0x00000002 /* -w secs */ 38147708Sjkoshy#define FLAG_HAS_OUTPUT_LOGFILE 0x00000004 /* -O file or pipe */ 39147708Sjkoshy#define FLAG_HAS_COMMANDLINE 0x00000008 /* command */ 40147708Sjkoshy#define FLAG_HAS_SAMPLING_PMCS 0x00000010 /* -S or -P */ 41147708Sjkoshy#define FLAG_HAS_COUNTING_PMCS 0x00000020 /* -s or -p */ 42147708Sjkoshy#define FLAG_HAS_PROCESS_PMCS 0x00000040 /* -P or -p */ 43147708Sjkoshy#define FLAG_HAS_SYSTEM_PMCS 0x00000080 /* -S or -s */ 44147708Sjkoshy#define FLAG_HAS_PIPE 0x00000100 /* implicit log */ 45147708Sjkoshy#define FLAG_READ_LOGFILE 0x00000200 /* -R file */ 46147708Sjkoshy#define FLAG_DO_GPROF 0x00000400 /* -g */ 47147708Sjkoshy#define FLAG_HAS_SAMPLESDIR 0x00000800 /* -D dir */ 48147708Sjkoshy#define FLAG_HAS_KERNELPATH 0x00001000 /* -k kernel */ 49147708Sjkoshy#define FLAG_DO_PRINT 0x00002000 /* -o */ 50203790Sfabient#define FLAG_DO_CALLGRAPHS 0x00004000 /* -G or -F */ 51203790Sfabient#define FLAG_DO_ANNOTATE 0x00008000 /* -m */ 52203790Sfabient#define FLAG_DO_TOP 0x00010000 /* -T */ 53203790Sfabient#define FLAG_DO_ANALYSIS 0x00020000 /* -g or -G or -m or -T */ 54210797Sfabient#define FLAGS_HAS_CPUMASK 0x00040000 /* -c */ 55147708Sjkoshy 56147708Sjkoshy#define DEFAULT_SAMPLE_COUNT 65536 57147708Sjkoshy#define DEFAULT_WAIT_INTERVAL 5.0 58203790Sfabient#define DEFAULT_DISPLAY_HEIGHT 256 /* file virtual height */ 59203790Sfabient#define DEFAULT_DISPLAY_WIDTH 1024 /* file virtual width */ 60147708Sjkoshy#define DEFAULT_BUFFER_SIZE 4096 61174396Sjkoshy#define DEFAULT_CALLGRAPH_DEPTH 4 62147708Sjkoshy 63147708Sjkoshy#define PRINT_HEADER_PREFIX "# " 64147708Sjkoshy#define READPIPEFD 0 65147708Sjkoshy#define WRITEPIPEFD 1 66147708Sjkoshy#define NPIPEFD 2 67147708Sjkoshy 68168949Sjkoshy#define NSOCKPAIRFD 2 69168949Sjkoshy#define PARENTSOCKET 0 70168949Sjkoshy#define CHILDSOCKET 1 71168949Sjkoshy 72147708Sjkoshy#define PMCSTAT_OPEN_FOR_READ 0 73147708Sjkoshy#define PMCSTAT_OPEN_FOR_WRITE 1 74147708Sjkoshy#define PMCSTAT_DEFAULT_NW_HOST "localhost" 75147708Sjkoshy#define PMCSTAT_DEFAULT_NW_PORT "9000" 76147708Sjkoshy#define PMCSTAT_NHASH 256 77147708Sjkoshy#define PMCSTAT_HASH_MASK 0xFF 78147708Sjkoshy 79147708Sjkoshy#define PMCSTAT_LDD_COMMAND "/usr/bin/ldd" 80147708Sjkoshy 81203790Sfabient#define PMCSTAT_PRINT_ENTRY(T,...) do { \ 82203790Sfabient (void) fprintf(args.pa_printfile, "%-9s", T); \ 83203790Sfabient (void) fprintf(args.pa_printfile, " " __VA_ARGS__); \ 84203790Sfabient (void) fprintf(args.pa_printfile, "\n"); \ 85147708Sjkoshy } while (0) 86147708Sjkoshy 87203790Sfabient#define PMCSTAT_PL_NONE 0 88203790Sfabient#define PMCSTAT_PL_CALLGRAPH 1 89203790Sfabient#define PMCSTAT_PL_GPROF 2 90203790Sfabient#define PMCSTAT_PL_ANNOTATE 3 91203790Sfabient#define PMCSTAT_PL_CALLTREE 4 92203790Sfabient 93203790Sfabient#define PMCSTAT_TOP_DELTA 0 94203790Sfabient#define PMCSTAT_TOP_ACCUM 1 95203790Sfabient 96203790Sfabient#define min(A,B) ((A) < (B) ? (A) : (B)) 97203790Sfabient#define max(A,B) ((A) > (B) ? (A) : (B)) 98203790Sfabient 99147708Sjkoshyenum pmcstat_state { 100147708Sjkoshy PMCSTAT_FINISHED = 0, 101147708Sjkoshy PMCSTAT_EXITING = 1, 102147708Sjkoshy PMCSTAT_RUNNING = 2 103147708Sjkoshy}; 104147708Sjkoshy 105147708Sjkoshystruct pmcstat_ev { 106147708Sjkoshy STAILQ_ENTRY(pmcstat_ev) ev_next; 107147708Sjkoshy int ev_count; /* associated count if in sampling mode */ 108168949Sjkoshy uint32_t ev_cpu; /* cpus for this event */ 109168949Sjkoshy int ev_cumulative; /* show cumulative counts */ 110147708Sjkoshy int ev_flags; /* PMC_F_* */ 111168949Sjkoshy int ev_fieldskip; /* #leading spaces */ 112147708Sjkoshy int ev_fieldwidth; /* print width */ 113168949Sjkoshy enum pmc_mode ev_mode; /* desired mode */ 114168949Sjkoshy char *ev_name; /* (derived) event name */ 115147708Sjkoshy pmc_id_t ev_pmcid; /* allocated ID */ 116168949Sjkoshy pmc_value_t ev_saved; /* for incremental counts */ 117168949Sjkoshy char *ev_spec; /* event specification */ 118147708Sjkoshy}; 119147708Sjkoshy 120169069Sjkoshystruct pmcstat_target { 121169069Sjkoshy SLIST_ENTRY(pmcstat_target) pt_next; 122169069Sjkoshy pid_t pt_pid; 123169069Sjkoshy}; 124169069Sjkoshy 125147708Sjkoshystruct pmcstat_args { 126147708Sjkoshy int pa_flags; /* argument flags */ 127147708Sjkoshy int pa_required; /* required features */ 128203790Sfabient int pa_pplugin; /* pre-processing plugin */ 129203790Sfabient int pa_plugin; /* analysis plugin */ 130157144Sjkoshy int pa_verbosity; /* verbosity level */ 131147708Sjkoshy FILE *pa_printfile; /* where to send printed output */ 132147708Sjkoshy int pa_logfd; /* output log file */ 133147708Sjkoshy char *pa_inputpath; /* path to input log */ 134147708Sjkoshy char *pa_outputpath; /* path to output log */ 135147708Sjkoshy void *pa_logparser; /* log file parser */ 136157144Sjkoshy const char *pa_fsroot; /* FS root where executables reside */ 137157144Sjkoshy char *pa_kernel; /* pathname of the kernel */ 138147708Sjkoshy const char *pa_samplesdir; /* directory for profile files */ 139157144Sjkoshy const char *pa_mapfilename;/* mapfile name */ 140174396Sjkoshy FILE *pa_graphfile; /* where to send the callgraph */ 141174396Sjkoshy int pa_graphdepth; /* print depth for callgraphs */ 142147708Sjkoshy double pa_interval; /* printing interval in seconds */ 143174396Sjkoshy uint32_t pa_cpumask; /* filter for CPUs analysed */ 144203790Sfabient int pa_ctdumpinstr; /* dump instructions with calltree */ 145203790Sfabient int pa_topmode; /* delta or accumulative */ 146203790Sfabient int pa_toptty; /* output to tty or file */ 147203790Sfabient int pa_topcolor; /* terminal support color */ 148203790Sfabient int pa_mergepmc; /* merge PMC with same name */ 149147708Sjkoshy int pa_argc; 150147708Sjkoshy char **pa_argv; 151169069Sjkoshy STAILQ_HEAD(, pmcstat_ev) pa_events; 152169069Sjkoshy SLIST_HEAD(, pmcstat_target) pa_targets; 153203790Sfabient}; 154147708Sjkoshy 155203790Sfabientextern int pmcstat_displayheight; /* current terminal height */ 156203790Sfabientextern int pmcstat_displaywidth; /* current terminal width */ 157203790Sfabientextern struct pmcstat_args args; /* command line args */ 158203790Sfabient 159147708Sjkoshy/* Function prototypes */ 160203790Sfabientvoid pmcstat_attach_pmcs(void); 161203790Sfabientvoid pmcstat_cleanup(void); 162203790Sfabientvoid pmcstat_clone_event_descriptor( 163168949Sjkoshy struct pmcstat_ev *_ev, uint32_t _cpumask); 164203790Sfabientint pmcstat_close_log(void); 165203790Sfabientvoid pmcstat_create_process(void); 166203790Sfabientvoid pmcstat_find_targets(const char *_arg); 167203790Sfabientvoid pmcstat_initialize_logging(void); 168203790Sfabientvoid pmcstat_kill_process(void); 169157144Sjkoshyint pmcstat_open_log(const char *_p, int _mode); 170203790Sfabientvoid pmcstat_print_counters(void); 171203790Sfabientvoid pmcstat_print_headers(void); 172203790Sfabientvoid pmcstat_print_pmcs(void); 173147708Sjkoshyvoid pmcstat_show_usage(void); 174203790Sfabientvoid pmcstat_shutdown_logging(void); 175203790Sfabientvoid pmcstat_start_pmcs(void); 176168949Sjkoshyvoid pmcstat_start_process(void); 177203790Sfabientint pmcstat_process_log(void); 178203790Sfabientint pmcstat_keypress_log(void); 179203790Sfabientvoid pmcstat_display_log(void); 180203790Sfabientvoid pmcstat_pluginconfigure_log(char *_opt); 181168949Sjkoshyuint32_t pmcstat_get_cpumask(const char *_a); 182203790Sfabientvoid pmcstat_topexit(void); 183147708Sjkoshy 184147708Sjkoshy#endif /* _PMCSTAT_H_ */ 185