00001 /** 00002 * @file symbol.h 00003 * Symbol containers 00004 * 00005 * @remark Copyright 2002, 2004 OProfile authors 00006 * @remark Read the file COPYING 00007 * 00008 * @author Philippe Elie 00009 * @author John Levon 00010 */ 00011 00012 #ifndef SYMBOL_H 00013 #define SYMBOL_H 00014 00015 #include "config.h" 00016 #include "name_storage.h" 00017 #include "growable_vector.h" 00018 #include "sparse_array.h" 00019 #include "format_flags.h" 00020 #include "op_types.h" 00021 00022 #include <bfd.h> 00023 #include <stdint.h> 00024 00025 #include <list> 00026 00027 class extra_images; 00028 00029 00030 /// for storing sample counts 00031 typedef sparse_array<u32, count_type> count_array_t; 00032 00033 00034 /// A simple container for a fileno:linenr location. 00035 struct file_location { 00036 file_location() : linenr(0) {} 00037 /// empty if not valid. 00038 debug_name_id filename; 00039 /// 0 means invalid or code is generated internally by the compiler 00040 unsigned int linenr; 00041 00042 bool operator<(file_location const & rhs) const { 00043 // Note we sort on filename id not on string 00044 return filename < rhs.filename || 00045 (filename == rhs.filename && linenr < rhs.linenr); 00046 } 00047 }; 00048 00049 00050 /// associate vma address with a file location and a samples count 00051 struct sample_entry { 00052 sample_entry() : vma(0) {} 00053 /// From where file location comes the samples 00054 file_location file_loc; 00055 /// From where virtual memory address comes the samples 00056 bfd_vma vma; 00057 /// the samples count 00058 count_array_t counts; 00059 }; 00060 00061 00062 /// associate a symbol with a file location, samples count and vma address 00063 class symbol_entry { 00064 public: 00065 symbol_entry() : size(0) {} 00066 virtual ~symbol_entry() {} 00067 00068 /// which image this symbol belongs to 00069 image_name_id image_name; 00070 /// owning application name: identical to image name if profiling 00071 /// session did not separate samples for shared libs or if image_name 00072 /// is not a shared lib 00073 image_name_id app_name; 00074 // index into the op_bfd symbol table 00075 size_t sym_index; 00076 /// file location, vma and cumulated samples count for this symbol 00077 sample_entry sample; 00078 /// name of symbol 00079 symbol_name_id name; 00080 /// symbol size as calculated by op_bfd, start of symbol is sample.vma 00081 size_t size; 00082 00083 /** 00084 * @param fl input hint 00085 * 00086 * combine fl with the calculated hint. It's theoretically possible 00087 * that we get a symbol where its samples pass the border line, but 00088 * the start is below it, but the the hint is only used for formatting 00089 */ 00090 column_flags output_hint(column_flags fl) const; 00091 uint64_t spu_offset; 00092 image_name_id embedding_filename; 00093 00094 /** 00095 * The vma_adj is set according to the corresponding op_bfd::vma_adj. 00096 * See the documentation for vma_adj in op_bfd.h for why we need this. 00097 * This piece of information is needed in the bowels of opannotate 00098 * with the --assembly option. At that point, there is no means of 00099 * obtaining the op_bfd for the given image being processed, but we 00100 * do have access to symbol_entry's. Yes, it's way overkill to add 00101 * this to every symbol_entry, but there isn't a better option. 00102 */ 00103 bfd_vma vma_adj; 00104 }; 00105 00106 00107 /// a collection of sorted symbols 00108 typedef std::vector<symbol_entry const *> symbol_collection; 00109 00110 00111 /** 00112 * The public data for call-graph symbols. Each caller/callee has 00113 * the sample counts replaced with the relevant arc counts, whilst 00114 * the cg_symbol retains its self count. 00115 */ 00116 class cg_symbol : public symbol_entry { 00117 public: 00118 cg_symbol(symbol_entry const & sym) : symbol_entry(sym) {} 00119 00120 typedef std::vector<symbol_entry> children; 00121 00122 /// all callers of this symbol 00123 children callers; 00124 /// total count of callers 00125 count_array_t total_caller_count; 00126 00127 /// all symbols called by this symbol 00128 children callees; 00129 /// total count of callees 00130 count_array_t total_callee_count; 00131 }; 00132 00133 /// a collection of sorted callgraph symbol objects 00134 typedef std::list<cg_symbol> cg_collection_objs; 00135 00136 /// for storing diff %ages 00137 typedef growable_vector<double> diff_array_t; 00138 00139 00140 /** 00141 * Data for a diffed symbol. 00142 */ 00143 struct diff_symbol : public symbol_entry { 00144 diff_symbol(symbol_entry const & sym) : symbol_entry(sym) {} 00145 00146 /// diff %age values for each profile class 00147 diff_array_t diffs; 00148 }; 00149 00150 00151 /// a collection of diffed symbols 00152 typedef std::vector<diff_symbol> diff_collection; 00153 00154 bool has_sample_counts(count_array_t const & counts, size_t lo, size_t hi); 00155 std::string const & get_image_name(image_name_id id, 00156 image_name_storage::image_name_type type, 00157 extra_images const & extra); 00158 00159 00160 #endif /* !SYMBOL_H */
1.6.1