00001 /** 00002 * @file profile_container.h 00003 * Container associating symbols and samples 00004 * 00005 * @remark Copyright 2002, 2003 OProfile authors 00006 * @remark Read the file COPYING 00007 * 00008 * @author Philippe Elie 00009 * @author John Levon 00010 */ 00011 00012 #ifndef PROFILE_CONTAINER_H 00013 #define PROFILE_CONTAINER_H 00014 00015 #include <string> 00016 #include <vector> 00017 00018 #include "profile.h" 00019 #include "utility.h" 00020 #include "op_bfd.h" 00021 #include "sample_container.h" 00022 #include "symbol_container.h" 00023 #include "format_flags.h" 00024 #include "locate_images.h" 00025 00026 class string_filter; 00027 class symbol_entry; 00028 class sample_entry; 00029 00030 /** 00031 * Store multiple samples files belonging to the same profiling session. 00032 * This is the main container capable of holding the profiles for arbitrary 00033 * binary images and arbitrary profile classes. 00034 */ 00035 class profile_container : noncopyable { 00036 public: 00037 /** 00038 * Build an object to store information on samples. All parameters 00039 * acts as hint for what you will request after recording samples and 00040 * so allow optimizations during recording the information. 00041 * 00042 * @param debug_info If true line numbers and source files are 00043 * recorded. 00044 * @param need_details If true if we need to record all samples or to 00045 * to record them at symbol level. 00046 * @param extra extra images location 00047 */ 00048 profile_container(bool debug_info, bool need_details, 00049 extra_images const & extra); 00050 00051 ~profile_container(); 00052 00053 /** 00054 * add() - record symbols/samples in the underlying container 00055 * 00056 * @param profile the samples files container 00057 * @param abfd the associated bfd object 00058 * @param app_name the owning application name of sample 00059 * @param pclass the profile class to add results for 00060 * 00061 * add() is an helper for delayed ctor. Take care you can't safely 00062 * make any call to add after any other member function call. 00063 * Obviously you can add only samples files which are coherent (same 00064 * sampling rate, same events etc.) 00065 */ 00066 void add(profile_t const & profile, op_bfd const & abfd, 00067 std::string const & app_name, size_t pclass); 00068 00069 /// Find a symbol from its image_name, vma, return zero if no symbol 00070 /// for this image at this vma 00071 symbol_entry const * find_symbol(std::string const & image_name, 00072 bfd_vma vma) const; 00073 00074 /// Find the symbols from its filename, linenr, return an empty 00075 /// symbol_collection if no symbol at this location 00076 symbol_collection const find_symbol(debug_name_id filename, 00077 size_t linenr) const; 00078 00079 /// Find a sample by its symbol, vma, return zero if there is no sample 00080 /// at this vma 00081 sample_entry const * find_sample(symbol_entry const * symbol, 00082 bfd_vma vma) const; 00083 00084 /// Find a symbol. Return NULL if not found. 00085 symbol_entry const * find(symbol_entry const & symbol) const; 00086 00087 /// used for select_symbols() 00088 struct symbol_choice { 00089 symbol_choice() 00090 : hints(cf_none), threshold(0.0), match_image(false) {} 00091 00092 /// hints filled in 00093 column_flags hints; 00094 /// percentage threshold 00095 double threshold; 00096 /// match the image name only 00097 bool match_image; 00098 /// owning image name 00099 std::string image_name; 00100 }; 00101 00102 /** 00103 * select_symbols - create a set of symbols sorted by sample count 00104 * @param choice parameters to use/fill in when selecting 00105 */ 00106 symbol_collection const select_symbols(symbol_choice & choice) const; 00107 00108 /** 00109 * select_symbols - create a set of symbols belonging to a given source 00110 * @param filename source file where are defined the returned symbols 00111 */ 00112 symbol_collection const select_symbols(debug_name_id filename) const; 00113 00114 /// Like select_symbols for filename without allowing sort by vma. 00115 std::vector<debug_name_id> const select_filename(double threshold) const; 00116 00117 /// return the total number of samples 00118 count_array_t samples_count() const; 00119 00120 /// Get the samples count which belongs to filename. Return 0 if 00121 /// no samples found. 00122 count_array_t samples_count(debug_name_id filename_id) const; 00123 /// Get the samples count which belongs to filename, linenr. Return 00124 /// 0 if no samples found. 00125 count_array_t samples_count(debug_name_id filename, 00126 size_t linenr) const; 00127 00128 /// return an iterator to the first symbol 00129 symbol_container::symbols_t::iterator begin_symbol() const; 00130 /// return an iterator to the last symbol 00131 symbol_container::symbols_t::iterator end_symbol() const; 00132 00133 /// return iterator to the first samples 00134 sample_container::samples_iterator begin() const; 00135 /// return iterator to the last samples 00136 sample_container::samples_iterator end() const; 00137 00138 /// return iterator to the first samples for this symbol 00139 sample_container::samples_iterator begin(symbol_entry const *) const; 00140 /// return iterator to the last samples for this symbol 00141 sample_container::samples_iterator end(symbol_entry const *) const; 00142 00143 private: 00144 /// helper for add() 00145 void add_samples(op_bfd const & abfd, symbol_index_t sym_index, 00146 profile_t::iterator_pair const &, 00147 symbol_entry const * symbol, size_t pclass, 00148 unsigned long start); 00149 00150 /** 00151 * create an unique artificial symbol for an offset range. The range 00152 * is only a hint of the maximum size of the created symbol. We 00153 * give to the symbol an unique name as ?image_file_name#order and 00154 * a range up to the nearest of syms or for the whole range if no 00155 * syms exist after the start offset. the end parameter is updated 00156 * to reflect the symbol range. 00157 * 00158 * The rationale here is to try to create symbols for alignment between 00159 * function as little as possible and to create meaningfull symbols 00160 * for special case such image w/o symbol. 00161 */ 00162 std::string create_artificial_symbol(op_bfd const & abfd, u32 start, 00163 u32 & end, size_t & order); 00164 00165 /// The symbols collected by pp tools sorted by increased vma, provide 00166 /// also a sort order on samples count for each profile class 00167 scoped_ptr<symbol_container> symbols; 00168 /// The samples count collected by pp tools sorted by increased vma, 00169 /// provide also a sort order on (filename, linenr) 00170 scoped_ptr<sample_container> samples; 00171 /// build() must count samples count for each profile class so cache it 00172 /// here since user of profile_container often need it later. 00173 count_array_t total_count; 00174 00175 /** 00176 * Optimization hints for what information we are going to need, 00177 * see the explanation in profile_container() 00178 */ 00179 //@{ 00180 bool debug_info; 00181 bool need_details; 00182 //@} 00183 00184 public: // FIXME 00185 extra_images extra_found_images; 00186 }; 00187 00188 #endif /* !PROFILE_CONTAINER_H */
1.6.1