Home | History | Annotate | Download | only in libpp
      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 "sparse_array.h"
     18 #include "format_flags.h"
     19 #include "op_types.h"
     20 
     21 #include <bfd.h>
     22 #include <stdint.h>
     23 
     24 #include <list>
     25 
     26 class extra_images;
     27 
     28 
     29 /// for storing sample counts
     30 typedef sparse_array<u32, count_type> count_array_t;
     31 
     32 
     33 /// A simple container for a fileno:linenr location.
     34 struct file_location {
     35 	file_location() : linenr(0) {}
     36 	/// empty if not valid.
     37 	debug_name_id filename;
     38 	/// 0 means invalid or code is generated internally by the compiler
     39 	unsigned int linenr;
     40 
     41 	bool operator<(file_location const & rhs) const {
     42 		// Note we sort on filename id not on string
     43 		return filename < rhs.filename ||
     44 		  (filename == rhs.filename && linenr < rhs.linenr);
     45 	}
     46 };
     47 
     48 
     49 /// associate vma address with a file location and a samples count
     50 struct sample_entry {
     51 	sample_entry() : vma(0) {}
     52 	/// From where file location comes the samples
     53 	file_location file_loc;
     54 	/// From where virtual memory address comes the samples
     55 	bfd_vma vma;
     56 	/// the samples count
     57 	count_array_t counts;
     58 };
     59 
     60 
     61 /// associate a symbol with a file location, samples count and vma address
     62 class symbol_entry {
     63 public:
     64 	symbol_entry() : size(0) {}
     65 	virtual ~symbol_entry() {}
     66 
     67 	/// which image this symbol belongs to
     68 	image_name_id image_name;
     69 	/// owning application name: identical to image name if profiling
     70 	/// session did not separate samples for shared libs or if image_name
     71 	/// is not a shared lib
     72 	image_name_id app_name;
     73 	// index into the op_bfd symbol table
     74 	size_t sym_index;
     75 	/// file location, vma and cumulated samples count for this symbol
     76 	sample_entry sample;
     77 	/// name of symbol
     78 	symbol_name_id name;
     79 	/// symbol size as calculated by op_bfd, start of symbol is sample.vma
     80 	size_t size;
     81 
     82 	/**
     83 	 * @param fl  input hint
     84 	 *
     85 	 * combine fl with the calculated hint. It's theoretically possible
     86 	 * that we get a symbol where its samples pass the border line, but
     87 	 * the start is below it, but the the hint is only used for formatting
     88 	 */
     89 	column_flags output_hint(column_flags fl) const;
     90 	uint64_t spu_offset;
     91 	image_name_id embedding_filename;
     92 };
     93 
     94 
     95 /// a collection of sorted symbols
     96 typedef std::vector<symbol_entry const *> symbol_collection;
     97 
     98 
     99 /**
    100  * The public data for call-graph symbols. Each caller/callee has
    101  * the sample counts replaced with the relevant arc counts, whilst
    102  * the cg_symbol retains its self count.
    103  */
    104 class cg_symbol : public symbol_entry {
    105 public:
    106 	cg_symbol(symbol_entry const & sym) : symbol_entry(sym) {}
    107 
    108 	typedef std::vector<symbol_entry> children;
    109 
    110 	/// all callers of this symbol
    111 	children callers;
    112 	/// total count of callers
    113 	count_array_t total_caller_count;
    114 
    115 	/// all symbols called by this symbol
    116 	children callees;
    117 	/// total count of callees
    118 	count_array_t total_callee_count;
    119 };
    120 
    121 /// a collection of sorted callgraph symbol objects
    122 typedef std::list<cg_symbol> cg_collection_objs;
    123 
    124 /// for storing diff %ages
    125 typedef growable_vector<double> diff_array_t;
    126 
    127 
    128 /**
    129  * Data for a diffed symbol.
    130  */
    131 struct diff_symbol : public symbol_entry  {
    132 	diff_symbol(symbol_entry const & sym) : symbol_entry(sym) {}
    133 
    134 	/// diff %age values for each profile class
    135 	diff_array_t diffs;
    136 };
    137 
    138 
    139 /// a collection of diffed symbols
    140 typedef std::vector<diff_symbol> diff_collection;
    141 
    142 bool has_sample_counts(count_array_t const & counts, size_t lo, size_t hi);
    143 std::string const & get_image_name(image_name_id id,
    144 				   image_name_storage::image_name_type type,
    145 				   extra_images const & extra);
    146 
    147 
    148 #endif /* !SYMBOL_H */
    149