00001 /** 00002 * @file pe_profiling/operf_sfile.h 00003 * Management of sample files generated from operf 00004 * This file is modeled after daemon/opd_sfile.c 00005 * 00006 * @remark Copyright 2011 OProfile authors 00007 * @remark Read the file COPYING 00008 * 00009 * @author Maynard Johnson 00010 * (C) Copyright IBM Corporation 2011 00011 */ 00012 00013 #ifndef OPD_SFILE_H 00014 #define OPD_SFILE_H 00015 00016 #include "operf_utils.h" 00017 #include "odb.h" 00018 #include "op_hw_config.h" 00019 #include "op_types.h" 00020 #include "op_list.h" 00021 #include "operf_process_info.h" 00022 00023 #include <sys/types.h> 00024 00025 struct operf_transient; 00026 struct operf_kernel_image; 00027 00028 #define CG_HASH_SIZE 16 00029 #define INVALID_IMAGE "INVALID IMAGE" 00030 00031 #define VMA_SHIFT 13 00032 /** 00033 * Each set of sample files (where a set is over the physical counter 00034 * types) will have one of these for it. We match against the 00035 * descriptions here to find which sample DB file we need to modify. 00036 * 00037 * cg files are stored in the hash. 00038 */ 00039 struct operf_sfile { 00040 /** hash value for this sfile */ 00041 unsigned long hashval; 00042 const char * image_name; 00043 const char * app_filename; 00044 size_t image_len, app_len; 00045 /** thread ID, -1 if not set */ 00046 pid_t tid; 00047 /** thread group ID, -1 if not set */ 00048 pid_t tgid; 00049 /** CPU number */ 00050 unsigned int cpu; 00051 /** kernel image if applicable */ 00052 struct operf_kernel_image * kernel; 00053 bool is_anon; 00054 vma_t start_addr; 00055 vma_t end_addr; 00056 00057 /** hash table link */ 00058 struct list_head hash; 00059 /** lru list */ 00060 struct list_head lru; 00061 /** true if this file should be ignored in profiles */ 00062 int ignored; 00063 /** opened sample files */ 00064 odb_t files[OP_MAX_COUNTERS]; 00065 /** extended sample files */ 00066 odb_t * ext_files; 00067 /** hash table of opened cg sample files */ 00068 struct list_head cg_hash[CG_HASH_SIZE]; 00069 }; 00070 00071 /** a call-graph entry */ 00072 struct operf_cg_entry { 00073 /** where arc is to */ 00074 struct operf_sfile to; 00075 /** next in the hash slot */ 00076 struct list_head hash; 00077 }; 00078 00079 /** 00080 * Transient values used for parsing the event buffer. 00081 * Note that these are reset for each buffer read, but 00082 * that should be ok as in the kernel, cpu_buffer_reset() 00083 * ensures that a correct context starts off the buffer. 00084 */ 00085 struct operf_transient { 00086 struct operf_sfile * current; 00087 struct operf_sfile * last; 00088 bool is_anon; 00089 operf_process_info * cur_procinfo; 00090 vma_t pc; 00091 const char * image_name; 00092 const char * app_filename; 00093 size_t image_len, app_len; 00094 vma_t last_pc; 00095 int event; 00096 u64 sample_id; 00097 int in_kernel; 00098 unsigned long cpu; 00099 u32 tid; 00100 u32 tgid; 00101 vma_t start_addr; 00102 vma_t end_addr; 00103 bool cg; 00104 // TODO: handle extended 00105 //void * ext; 00106 }; 00107 00108 00109 /** clear any sfiles that are for the kernel */ 00110 void operf_sfile_clear_kernel(void); 00111 00112 /** sync sample files */ 00113 void operf_sfile_sync_files(void); 00114 00115 /** close sample files */ 00116 void operf_sfile_close_files(void); 00117 00118 /** clear out a certain amount of LRU entries 00119 * return non-zero if the lru is already empty */ 00120 int operf_sfile_lru_clear(void); 00121 00122 /** remove a sfile from the lru list, protecting it from operf_sfile_lru_clear() */ 00123 void operf_sfile_get(struct operf_sfile * sf); 00124 00125 /** add this sfile to lru list */ 00126 void operf_sfile_put(struct operf_sfile * sf); 00127 00128 /** 00129 * Find the sfile for the current parameters. Note that is required 00130 * that the PC value be set appropriately (needed for kernel images) 00131 */ 00132 struct operf_sfile * operf_sfile_find(struct operf_transient const * trans); 00133 00134 /** Log the sample in a previously located sfile. */ 00135 void operf_sfile_log_sample(struct operf_transient const * trans); 00136 00137 /** Log the event/cycle count in a previously located sfile */ 00138 void operf_sfile_log_sample_count(struct operf_transient const * trans, 00139 unsigned long int count); 00140 00141 /** Log a callgraph arc. */ 00142 void operf_sfile_log_arc(struct operf_transient const * trans); 00143 00144 /** initialise hashes */ 00145 void operf_sfile_init(void); 00146 00147 #endif /* OPD_SFILE_H */
1.6.1