profile.h

Go to the documentation of this file.
00001 
00013 #ifndef PROFILE_H
00014 #define PROFILE_H
00015 
00016 #include <string>
00017 #include <map>
00018 #include <iterator>
00019 
00020 #include "odb.h"
00021 #include "op_types.h"
00022 #include "utility.h"
00023 #include "populate_for_spu.h"
00024 
00025 class opd_header;
00026 class op_bfd;
00027 
00033 class profile_t : noncopyable {
00034 public:
00038     profile_t();
00039 
00041     bool empty() const { return !file_header.get(); }
00042  
00044     opd_header const & get_header() const {
00045         return *file_header;
00046     }
00047 
00056     static count_type sample_count(std::string const & filename);
00057 
00066     static enum profile_type is_spu_sample_file(std::string const & filename);
00067 
00076     void add_sample_file(std::string const & filename);
00077 
00079     void set_offset(op_bfd const & abfd);
00080 
00081     class const_iterator;
00082     typedef std::pair<const_iterator, const_iterator> iterator_pair;
00083 
00090     iterator_pair
00091     samples_range(odb_key_t start, odb_key_t end) const;
00092 
00094     iterator_pair samples_range() const;
00095 
00096 private:
00099     static void
00100     open_sample_file(std::string const & filename, odb_t &);
00101 
00103     scoped_ptr<opd_header> file_header;
00104 
00106     typedef std::map<odb_key_t, count_type> ordered_samples_t;
00107 
00114     ordered_samples_t ordered_samples;
00115 
00141     u64 start_offset;
00142 };
00143 
00144 
00145 // It will be easier to derive profile_t::const_iterator from
00146 // std::iterator<std::input_iterator_tag, unsigned int> but this doesn't
00147 // work for gcc <= 2.95 so we provide the neccessary typedef in the hard way.
00148 // See ISO C++ 17.4.3.1 § 1 and 14.7.3 § 9.
00149 namespace std {
00150     template <>
00151         struct iterator_traits<profile_t::const_iterator> {
00152             typedef ptrdiff_t difference_type;
00153             typedef count_type value_type;
00154             typedef count_type * pointer;
00155             typedef count_type & reference;
00156             typedef input_iterator_tag iterator_category;
00157         };
00158 }
00159 
00160 
00161 class profile_t::const_iterator
00162 {
00163     typedef ordered_samples_t::const_iterator iterator_t;
00164 public:
00165     const_iterator() : start_offset(0) {}
00166     const_iterator(iterator_t it_, u64 start_offset_)
00167         : it(it_), start_offset(start_offset_) {}
00168 
00169     count_type operator*() const { return it->second; }
00170     const_iterator & operator++() { ++it; return *this; }
00171 
00172     odb_key_t vma() const { return it->first + start_offset; }
00173     count_type count() const { return **this; }
00174 
00175     bool operator!=(const_iterator const & rhs) const {
00176         return it != rhs.it;
00177     }
00178     bool operator==(const_iterator const & rhs) const {
00179         return it == rhs.it;
00180     }
00181 
00182 private:
00183     iterator_t it;
00184     u64 start_offset;
00185 };
00186 
00187 #endif /* !PROFILE_H */

Generated on 8 Nov 2012 for Oprofile by  doxygen 1.6.1