pmcstat.h revision 157144
1147708Sjkoshy/*- 2157144Sjkoshy * Copyright (c) 2005-2006, Joseph Koshy 3147708Sjkoshy * All rights reserved. 4147708Sjkoshy * 5147708Sjkoshy * Redistribution and use in source and binary forms, with or without 6147708Sjkoshy * modification, are permitted provided that the following conditions 7147708Sjkoshy * are met: 8147708Sjkoshy * 1. Redistributions of source code must retain the above copyright 9147708Sjkoshy * notice, this list of conditions and the following disclaimer. 10147708Sjkoshy * 2. Redistributions in binary form must reproduce the above copyright 11147708Sjkoshy * notice, this list of conditions and the following disclaimer in the 12147708Sjkoshy * documentation and/or other materials provided with the distribution. 13147708Sjkoshy * 14147708Sjkoshy * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15147708Sjkoshy * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16147708Sjkoshy * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17147708Sjkoshy * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18147708Sjkoshy * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19147708Sjkoshy * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20147708Sjkoshy * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21147708Sjkoshy * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22147708Sjkoshy * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23147708Sjkoshy * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24147708Sjkoshy * SUCH DAMAGE. 25147708Sjkoshy * 26147708Sjkoshy * $FreeBSD: head/usr.sbin/pmcstat/pmcstat.h 157144 2006-03-26 12:20:54Z jkoshy $ 27147708Sjkoshy */ 28147708Sjkoshy 29147708Sjkoshy#ifndef _PMCSTAT_H_ 30147708Sjkoshy#define _PMCSTAT_H_ 31147708Sjkoshy 32147708Sjkoshy#define FLAG_HAS_PID 0x00000001 /* explicit pid */ 33147708Sjkoshy#define FLAG_HAS_WAIT_INTERVAL 0x00000002 /* -w secs */ 34147708Sjkoshy#define FLAG_HAS_OUTPUT_LOGFILE 0x00000004 /* -O file or pipe */ 35147708Sjkoshy#define FLAG_HAS_COMMANDLINE 0x00000008 /* command */ 36147708Sjkoshy#define FLAG_HAS_SAMPLING_PMCS 0x00000010 /* -S or -P */ 37147708Sjkoshy#define FLAG_HAS_COUNTING_PMCS 0x00000020 /* -s or -p */ 38147708Sjkoshy#define FLAG_HAS_PROCESS_PMCS 0x00000040 /* -P or -p */ 39147708Sjkoshy#define FLAG_HAS_SYSTEM_PMCS 0x00000080 /* -S or -s */ 40147708Sjkoshy#define FLAG_HAS_PIPE 0x00000100 /* implicit log */ 41147708Sjkoshy#define FLAG_READ_LOGFILE 0x00000200 /* -R file */ 42147708Sjkoshy#define FLAG_DO_GPROF 0x00000400 /* -g */ 43147708Sjkoshy#define FLAG_HAS_SAMPLESDIR 0x00000800 /* -D dir */ 44147708Sjkoshy#define FLAG_HAS_KERNELPATH 0x00001000 /* -k kernel */ 45147708Sjkoshy#define FLAG_DO_PRINT 0x00002000 /* -o */ 46147708Sjkoshy 47147708Sjkoshy#define DEFAULT_SAMPLE_COUNT 65536 48147708Sjkoshy#define DEFAULT_WAIT_INTERVAL 5.0 49147708Sjkoshy#define DEFAULT_DISPLAY_HEIGHT 23 50147708Sjkoshy#define DEFAULT_BUFFER_SIZE 4096 51147708Sjkoshy 52147708Sjkoshy#define PRINT_HEADER_PREFIX "# " 53147708Sjkoshy#define READPIPEFD 0 54147708Sjkoshy#define WRITEPIPEFD 1 55147708Sjkoshy#define NPIPEFD 2 56147708Sjkoshy 57147708Sjkoshy#define PMCSTAT_OPEN_FOR_READ 0 58147708Sjkoshy#define PMCSTAT_OPEN_FOR_WRITE 1 59147708Sjkoshy#define PMCSTAT_DEFAULT_NW_HOST "localhost" 60147708Sjkoshy#define PMCSTAT_DEFAULT_NW_PORT "9000" 61147708Sjkoshy#define PMCSTAT_NHASH 256 62147708Sjkoshy#define PMCSTAT_HASH_MASK 0xFF 63147708Sjkoshy 64147708Sjkoshy#define PMCSTAT_LDD_COMMAND "/usr/bin/ldd" 65147708Sjkoshy 66147708Sjkoshy#define PMCSTAT_PRINT_ENTRY(A,T,...) do { \ 67147708Sjkoshy fprintf((A)->pa_printfile, "%-8s", T); \ 68147708Sjkoshy fprintf((A)->pa_printfile, " " __VA_ARGS__); \ 69147708Sjkoshy fprintf((A)->pa_printfile, "\n"); \ 70147708Sjkoshy } while (0) 71147708Sjkoshy 72147708Sjkoshyenum pmcstat_state { 73147708Sjkoshy PMCSTAT_FINISHED = 0, 74147708Sjkoshy PMCSTAT_EXITING = 1, 75147708Sjkoshy PMCSTAT_RUNNING = 2 76147708Sjkoshy}; 77147708Sjkoshy 78147708Sjkoshystruct pmcstat_ev { 79147708Sjkoshy STAILQ_ENTRY(pmcstat_ev) ev_next; 80147708Sjkoshy char *ev_spec; /* event specification */ 81147708Sjkoshy char *ev_name; /* (derived) event name */ 82147708Sjkoshy enum pmc_mode ev_mode; /* desired mode */ 83147708Sjkoshy int ev_count; /* associated count if in sampling mode */ 84147708Sjkoshy int ev_cpu; /* specific cpu if requested */ 85147708Sjkoshy int ev_flags; /* PMC_F_* */ 86147708Sjkoshy int ev_cumulative; /* show cumulative counts */ 87147708Sjkoshy int ev_fieldwidth; /* print width */ 88147708Sjkoshy int ev_fieldskip; /* #leading spaces */ 89147708Sjkoshy pmc_value_t ev_saved; /* saved value for incremental counts */ 90147708Sjkoshy pmc_id_t ev_pmcid; /* allocated ID */ 91147708Sjkoshy}; 92147708Sjkoshy 93147708Sjkoshystruct pmcstat_args { 94147708Sjkoshy int pa_flags; /* argument flags */ 95147708Sjkoshy int pa_required; /* required features */ 96157144Sjkoshy int pa_verbosity; /* verbosity level */ 97147708Sjkoshy pid_t pa_pid; /* attached to pid */ 98147708Sjkoshy FILE *pa_printfile; /* where to send printed output */ 99147708Sjkoshy int pa_logfd; /* output log file */ 100147708Sjkoshy char *pa_inputpath; /* path to input log */ 101147708Sjkoshy char *pa_outputpath; /* path to output log */ 102147708Sjkoshy void *pa_logparser; /* log file parser */ 103157144Sjkoshy const char *pa_fsroot; /* FS root where executables reside */ 104157144Sjkoshy char *pa_kernel; /* pathname of the kernel */ 105147708Sjkoshy const char *pa_samplesdir; /* directory for profile files */ 106157144Sjkoshy const char *pa_mapfilename;/* mapfile name */ 107147708Sjkoshy double pa_interval; /* printing interval in seconds */ 108147708Sjkoshy int pa_argc; 109147708Sjkoshy char **pa_argv; 110147708Sjkoshy STAILQ_HEAD(, pmcstat_ev) pa_head; 111147708Sjkoshy} args; 112147708Sjkoshy 113147708Sjkoshy/* Function prototypes */ 114147708Sjkoshyvoid pmcstat_cleanup(struct pmcstat_args *_a); 115147708Sjkoshyint pmcstat_close_log(struct pmcstat_args *_a); 116147708Sjkoshyvoid pmcstat_initialize_logging(struct pmcstat_args *_a); 117157144Sjkoshyint pmcstat_open_log(const char *_p, int _mode); 118147708Sjkoshyvoid pmcstat_print_counters(struct pmcstat_args *_a); 119147708Sjkoshyvoid pmcstat_print_headers(struct pmcstat_args *_a); 120147708Sjkoshyvoid pmcstat_print_pmcs(struct pmcstat_args *_a); 121147708Sjkoshyvoid pmcstat_setup_process(struct pmcstat_args *_a); 122147708Sjkoshyvoid pmcstat_show_usage(void); 123157144Sjkoshyvoid pmcstat_shutdown_logging(struct pmcstat_args *_a); 124147708Sjkoshyvoid pmcstat_start_pmcs(struct pmcstat_args *_a); 125147708Sjkoshyvoid pmcstat_start_process(struct pmcstat_args *_a); 126147863Sjkoshyint pmcstat_process_log(struct pmcstat_args *_a); 127147708Sjkoshy 128147708Sjkoshy#endif /* _PMCSTAT_H_ */ 129