Upstream | cc2ee17 | 1970-01-12 13:46:40 +0000 | [diff] [blame^] | 1 | /** |
| 2 | * @file symbol.h |
| 3 | * Symbol containers |
| 4 | * |
| 5 | * @remark Copyright 2002, 2004 OProfile authors |
| 6 | * @remark Read the file COPYING |
| 7 | * |
| 8 | * @author Philippe Elie |
| 9 | * @author John Levon |
| 10 | */ |
| 11 | |
| 12 | #ifndef SYMBOL_H |
| 13 | #define SYMBOL_H |
| 14 | |
| 15 | #include "name_storage.h" |
| 16 | #include "growable_vector.h" |
| 17 | #include "format_flags.h" |
| 18 | #include "op_types.h" |
| 19 | |
| 20 | #include <bfd.h> |
| 21 | |
| 22 | #include <list> |
| 23 | |
| 24 | |
| 25 | /// for storing sample counts |
| 26 | typedef growable_vector<u32> count_array_t; |
| 27 | |
| 28 | |
| 29 | /// A simple container for a fileno:linenr location. |
| 30 | struct file_location { |
| 31 | file_location() : linenr(0) {} |
| 32 | /// empty if not valid. |
| 33 | debug_name_id filename; |
| 34 | /// 0 means invalid or code is generated internally by the compiler |
| 35 | unsigned int linenr; |
| 36 | |
| 37 | bool operator<(file_location const & rhs) const { |
| 38 | // Note we sort on filename id not on string |
| 39 | return filename < rhs.filename || |
| 40 | (filename == rhs.filename && linenr < rhs.linenr); |
| 41 | } |
| 42 | }; |
| 43 | |
| 44 | |
| 45 | /// associate vma address with a file location and a samples count |
| 46 | struct sample_entry { |
| 47 | sample_entry() : vma(0) {} |
| 48 | /// From where file location comes the samples |
| 49 | file_location file_loc; |
| 50 | /// From where virtual memory address comes the samples |
| 51 | bfd_vma vma; |
| 52 | /// the samples count |
| 53 | count_array_t counts; |
| 54 | }; |
| 55 | |
| 56 | |
| 57 | /// associate a symbol with a file location, samples count and vma address |
| 58 | struct symbol_entry { |
| 59 | symbol_entry() : size(0) {} |
| 60 | /// which image this symbol belongs to |
| 61 | image_name_id image_name; |
| 62 | /// owning application name: identical to image name if profiling |
| 63 | /// session did not separate samples for shared libs or if image_name |
| 64 | /// is not a shared lib |
| 65 | image_name_id app_name; |
| 66 | /// file location, vma and cumulated samples count for this symbol |
| 67 | sample_entry sample; |
| 68 | /// name of symbol |
| 69 | symbol_name_id name; |
| 70 | /// symbol size as calculated by op_bfd, start of symbol is sample.vma |
| 71 | size_t size; |
| 72 | |
| 73 | /** |
| 74 | * @param fl input hint |
| 75 | * |
| 76 | * combine fl with the calculated hint. It's theoretically possible |
| 77 | * that we get a symbol where its samples pass the border line, but |
| 78 | * the start is below it, but the the hint is only used for formatting |
| 79 | */ |
| 80 | column_flags output_hint(column_flags fl) const; |
| 81 | }; |
| 82 | |
| 83 | |
| 84 | /// a collection of sorted symbols |
| 85 | typedef std::vector<symbol_entry const *> symbol_collection; |
| 86 | |
| 87 | |
| 88 | /** |
| 89 | * The public data for call-graph symbols. Each caller/callee has |
| 90 | * the sample counts replaced with the relevant arc counts, whilst |
| 91 | * the cg_symbol retains its self count. |
| 92 | */ |
| 93 | struct cg_symbol : public symbol_entry { |
| 94 | cg_symbol(symbol_entry const & sym) : symbol_entry(sym) {} |
| 95 | |
| 96 | typedef std::vector<symbol_entry> children; |
| 97 | |
| 98 | /// all callers of this symbol |
| 99 | children callers; |
| 100 | /// total count of callers |
| 101 | count_array_t total_caller_count; |
| 102 | |
| 103 | /// all symbols called by this symbol |
| 104 | children callees; |
| 105 | /// total count of callees |
| 106 | count_array_t total_callee_count; |
| 107 | }; |
| 108 | |
| 109 | |
| 110 | /// a collection of sorted callgraph symbols |
| 111 | typedef std::vector<cg_symbol> cg_collection; |
| 112 | |
| 113 | |
| 114 | /// for storing diff %ages |
| 115 | typedef growable_vector<double> diff_array_t; |
| 116 | |
| 117 | |
| 118 | /** |
| 119 | * Data for a diffed symbol. |
| 120 | */ |
| 121 | struct diff_symbol : public symbol_entry { |
| 122 | diff_symbol(symbol_entry const & sym) : symbol_entry(sym) {} |
| 123 | |
| 124 | /// diff %age values for each profile class |
| 125 | diff_array_t diffs; |
| 126 | }; |
| 127 | |
| 128 | |
| 129 | /// a collection of diffed symbols |
| 130 | typedef std::vector<diff_symbol> diff_collection; |
| 131 | |
| 132 | |
| 133 | #endif /* !SYMBOL_H */ |