• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * @file sample_container.h
3  * Internal implementation of sample container
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 #ifndef SAMPLE_CONTAINER_H
13 #define SAMPLE_CONTAINER_H
14 
15 #include <map>
16 #include <set>
17 #include <string>
18 
19 #include "symbol.h"
20 #include "symbol_functors.h"
21 
22 /**
23  * Arbitrary container of sample entries. Can return
24  * number of samples for a file or line number and
25  * return the particular sample information for a VMA.
26  */
27 class sample_container {
28 	typedef std::pair<symbol_entry const *, bfd_vma> sample_index_t;
29 public:
30 	typedef std::map<sample_index_t, sample_entry> samples_storage;
31 	typedef samples_storage::const_iterator samples_iterator;
32 
33 	/// return iterator to the first samples for this symbol
34 	samples_iterator begin(symbol_entry const *) const;
35 	/// return iterator to the last samples for this symbol
36 	samples_iterator end(symbol_entry const *) const;
37 
38 	/// return iterator to the first samples
39 	samples_iterator begin() const;
40 	/// return iterator to the last samples
41 	samples_iterator end() const;
42 
43 	/// insert a sample entry by creating a new entry or by cumulating
44 	/// samples into an existing one. Can only be done before any lookups
45 	void insert(symbol_entry const * symbol, sample_entry const &);
46 
47 	/// return nr of samples in the given filename
48 	count_array_t accumulate_samples(debug_name_id filename_id) const;
49 
50 	/// return nr of samples at the given line nr in the given file
51 	count_array_t accumulate_samples(debug_name_id, size_t linenr) const;
52 
53 	/// return the sample entry for the given image_name and vma if any
54 	sample_entry const * find_by_vma(symbol_entry const * symbol,
55 					 bfd_vma vma) const;
56 
57 private:
58 	/// build the symbol by file-location cache
59 	void build_by_loc() const;
60 
61 	/// main sample entry container
62 	samples_storage samples;
63 
64 	typedef std::multiset<sample_entry const *, less_by_file_loc>
65 		samples_by_loc_t;
66 
67 	// must be declared after the samples_storage to ensure a
68 	// correct life-time.
69 
70 	/**
71 	 * Sample entries by file location. Lazily built when necessary,
72 	 * so mutable.
73 	 */
74 	mutable samples_by_loc_t samples_by_loc;
75 };
76 
77 #endif /* SAMPLE_CONTAINER_H */
78