~arosales/test/oprofile

« back to all changes in this revision

Viewing changes to libpp/symbol.h

  • Committer: Antonio Rosales
  • Date: 2013-03-28 08:40:26 UTC
  • Revision ID: antonio.rosales@canonical.com-20130328084026-gpqns1mkqd7cnr05
Move files up one directory.

Show diffs side-by-side

added added

removed removed

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