Mike Dodd | 8cfa702 | 2010-11-17 11:12:26 -0800 | [diff] [blame] | 1 | /** |
| 2 | * @file callgraph_container.h |
| 3 | * Container associating symbols and caller/caller symbols |
| 4 | * |
| 5 | * @remark Copyright 2004 OProfile authors |
| 6 | * @remark Read the file COPYING |
| 7 | * |
| 8 | * @author Philippe Elie |
| 9 | * @author John Levon |
| 10 | */ |
| 11 | |
| 12 | #ifndef CALLGRAPH_CONTAINER_H |
| 13 | #define CALLGRAPH_CONTAINER_H |
| 14 | |
| 15 | #include <set> |
| 16 | #include <vector> |
| 17 | #include <string> |
| 18 | |
| 19 | #include "symbol.h" |
| 20 | #include "symbol_functors.h" |
| 21 | #include "string_filter.h" |
| 22 | #include "locate_images.h" |
| 23 | |
| 24 | class profile_container; |
| 25 | class inverted_profile; |
| 26 | class profile_t; |
| 27 | class image_set; |
| 28 | class op_bfd; |
| 29 | |
| 30 | |
| 31 | /** |
| 32 | * During building a callgraph_container we store all caller/callee |
| 33 | * relationship in this container. |
| 34 | * |
| 35 | * An "arc" is simply a description of a call from one function to |
| 36 | * another. |
| 37 | */ |
| 38 | class arc_recorder { |
| 39 | public: |
| 40 | ~arc_recorder() {} |
| 41 | |
| 42 | /** |
| 43 | * Add a symbol arc. |
| 44 | * @param caller The calling symbol |
| 45 | * @param callee The called symbol |
| 46 | * @param arc_count profile data for the arcs |
| 47 | * |
| 48 | * If the callee is NULL, only the caller is added to the main |
| 49 | * list. This is used to initially populate the recorder with |
| 50 | * the symbols. |
| 51 | */ |
| 52 | void add(symbol_entry const & caller, symbol_entry const * callee, |
| 53 | count_array_t const & arc_count); |
| 54 | |
| 55 | /// return all the cg symbols |
| 56 | symbol_collection const & get_symbols() const; |
| 57 | |
| 58 | /** |
| 59 | * After population, build the final output, and do |
| 60 | * thresholding. |
| 61 | */ |
| 62 | void process(count_array_t total, double threshold, |
| 63 | string_filter const & filter); |
| 64 | |
| 65 | private: |
| 66 | /** |
| 67 | * Internal structure used during collation. We use a map to |
| 68 | * allow quick lookup of children (we'll do this several times |
| 69 | * if we have more than one profile class). Each child maps from |
| 70 | * the symbol to the relevant arc data. |
| 71 | */ |
| 72 | struct cg_data { |
| 73 | cg_data() {} |
| 74 | |
| 75 | typedef std::map<symbol_entry, count_array_t, less_symbol> children; |
| 76 | |
| 77 | /// callers of this symbol |
| 78 | children callers; |
| 79 | /// callees of this symbol |
| 80 | children callees; |
| 81 | }; |
| 82 | |
| 83 | /** |
| 84 | * Sort and threshold callers and callees. |
| 85 | */ |
| 86 | void process_children(cg_symbol & sym, double threshold); |
| 87 | |
| 88 | typedef std::map<symbol_entry, cg_data, less_symbol> map_t; |
| 89 | |
| 90 | /// all the symbols (used during processing) |
| 91 | map_t sym_map; |
| 92 | |
| 93 | /// symbol objects pointed to by pointers in vector cg_syms |
| 94 | cg_collection_objs cg_syms_objs; |
| 95 | |
| 96 | /// final output data |
| 97 | symbol_collection cg_syms; |
| 98 | }; |
| 99 | |
| 100 | |
| 101 | /** |
| 102 | * Store all callgraph information for the given profiles |
| 103 | */ |
| 104 | class callgraph_container { |
| 105 | public: |
| 106 | /** |
| 107 | * Populate the container, must be called once only. |
| 108 | * @param iprofiles sample file list including callgraph files. |
| 109 | * @param extra extra image list to fixup binary name. |
| 110 | * @param debug_info true if we must record linenr information |
| 111 | * @param threshold ignore sample percent below this threshold |
| 112 | * @param merge_lib merge library samples |
| 113 | * @param sym_filter symbol filter |
| 114 | * |
| 115 | * Currently all errors core dump. |
| 116 | * FIXME: consider if this should be a ctor |
| 117 | */ |
| 118 | void populate(std::list<inverted_profile> const & iprofiles, |
| 119 | extra_images const & extra, bool debug_info, |
| 120 | double threshold, bool merge_lib, |
| 121 | string_filter const & sym_filter); |
| 122 | |
| 123 | /// return hint on how data must be displayed. |
| 124 | column_flags output_hint() const; |
| 125 | |
| 126 | /// return the total number of samples. |
| 127 | count_array_t samples_count() const; |
| 128 | |
| 129 | // return all the cg symbols |
| 130 | symbol_collection const & get_symbols() const; |
| 131 | |
| 132 | private: |
| 133 | /** |
| 134 | * Record caller/callee for one cg file |
| 135 | * @param profile one callgraph file stored in a profile_t |
| 136 | * @param caller_bfd the caller bfd |
| 137 | * @param bfd_caller_ok true if we succefully open the binary |
| 138 | * @param callee_bfd the callee bfd |
| 139 | * @param app_name the owning application |
| 140 | * @param pc the profile_container holding all non cg samples. |
| 141 | * @param debug_info record linenr debug information |
| 142 | * @param pclass profile class nr |
| 143 | */ |
| 144 | void add(profile_t const & profile, op_bfd const & caller_bfd, |
| 145 | bool bfd_caller_ok, op_bfd const & callee_bfd, |
| 146 | std::string const & app_name, profile_container const & pc, |
| 147 | bool debug_info, size_t pclass); |
| 148 | |
| 149 | void populate(std::list<image_set> const & lset, |
| 150 | std::string const & app_image, |
| 151 | size_t pclass, profile_container const & pc, |
| 152 | bool debug_info, bool merge_lib); |
| 153 | void populate(std::list<std::string> const & cg_files, |
| 154 | std::string const & app_image, |
| 155 | size_t pclass, profile_container const & pc, |
| 156 | bool debug_info, bool merge_lib); |
| 157 | |
| 158 | /// record all main symbols |
| 159 | void add_symbols(profile_container const & pc); |
| 160 | |
| 161 | /// Cached value of samples count. |
| 162 | count_array_t total_count; |
| 163 | |
| 164 | /// A structured representation of the callgraph. |
| 165 | arc_recorder recorder; |
| 166 | |
| 167 | public: // FIXME |
| 168 | extra_images extra_found_images; |
| 169 | }; |
| 170 | |
| 171 | #endif /* !CALLGRAPH_CONTAINER_H */ |