blob: b7a6d3e102194c2a38d2b518c661db6836e84c9e [file] [log] [blame]
Upstreamcc2ee171970-01-12 13:46:40 +00001/**
2 * @file symbol_container.cpp
3 * Internal container for symbols
4 *
5 * @remark Copyright 2002 OProfile authors
6 * @remark Read the file COPYING
7 *
8 * @author Philippe Elie
9 * @author John Levon
10 */
11
12#include <string>
13#include <algorithm>
14#include <set>
15#include <vector>
16
17#include "symbol_container.h"
18
19using namespace std;
20
21symbol_container::size_type symbol_container::size() const
22{
23 return symbols.size();
24}
25
26
27symbol_entry const * symbol_container::insert(symbol_entry const & symb)
28{
29 pair<symbols_t::iterator, bool> p = symbols.insert(symb);
30 if (!p.second) {
31 // safe: count is not used by sorting criteria
32 symbol_entry * symbol = const_cast<symbol_entry*>(&*p.first);
33 symbol->sample.counts += symb.sample.counts;
34 }
35
36 return &*p.first;
37}
38
39
40symbol_entry const *
41symbol_container::find(debug_name_id filename, size_t linenr) const
42{
43 build_by_loc();
44
45 symbol_entry symbol;
46 symbol.sample.file_loc.filename = filename;
47 symbol.sample.file_loc.linenr = linenr;
48
49 symbols_by_loc_t::const_iterator it = symbols_by_loc.find(&symbol);
50
51 if (it != symbols_by_loc.end())
52 return *it;
53
54 return 0;
55}
56
57
58void symbol_container::build_by_loc() const
59{
60 if (!symbols_by_loc.empty())
61 return;
62
63 symbols_t::const_iterator cit = symbols.begin();
64 symbols_t::const_iterator end = symbols.end();
65 for (; cit != end; ++cit)
66 symbols_by_loc.insert(&*cit);
67}
68
69
70symbol_entry const * symbol_container::find_by_vma(string const & image_name,
71 bfd_vma vma) const
72{
73 // FIXME: this is too inefficient probably
74 symbols_t::const_iterator it;
75 for (it = symbols.begin(); it != symbols.end(); ++it) {
76 if (it->sample.vma == vma &&
77 image_names.name(it->image_name) == image_name)
78 return &*it;
79 }
80
81 return 0;
82}
83
84
85symbol_container::symbols_t::iterator symbol_container::begin()
86{
87 return symbols.begin();
88}
89
90
91symbol_container::symbols_t::iterator symbol_container::end()
92{
93 return symbols.end();
94}
95
96symbol_entry const * symbol_container::find(symbol_entry const & symbol) const
97{
98 symbols_t::const_iterator it = symbols.find(symbol);
99 return it == symbols.end() ? 0 : &*it;
100}