From: Philippe E. <ph...@us...> - 2001-10-01 02:07:45
|
Update of /cvsroot/oprofile/oprofile/pp In directory usw-pr-cvs1:/tmp/cvs-serv5415/oprofile/pp Modified Files: opf_container.cpp opf_filter.cpp opf_filter.h Log Message: pp: speed-up opf_filter + comment Index: opf_container.cpp =================================================================== RCS file: /cvsroot/oprofile/oprofile/pp/opf_container.cpp,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- opf_container.cpp 2001/09/30 13:57:05 1.11 +++ opf_container.cpp 2001/10/01 02:07:41 1.12 @@ -94,8 +94,7 @@ //--------------------------------------------------------------------------- -// Implementation. - +/// implementation of symbol_container_t class symbol_container_impl { public: symbol_container_impl(); @@ -104,7 +103,7 @@ const symbol_entry & operator[](size_t index) const; void push_back(const symbol_entry &); const symbol_entry * find(string filename, size_t linenr) const; - const symbol_entry * find_by_vma(unsigned long vma) const; + const symbol_entry * find_by_vma(bfd_vma vma) const; // get a vector of symbols sorted by increased count. void get_symbols_by_count(size_t counter, vector<const symbol_entry*>& v) const; @@ -206,7 +205,7 @@ } } -const symbol_entry * symbol_container_impl::find_by_vma(unsigned long vma) const +const symbol_entry * symbol_container_impl::find_by_vma(bfd_vma vma) const { symbol_entry value; @@ -276,7 +275,7 @@ return impl->find(filename, linenr); } -const symbol_entry * symbol_container_t::find_by_vma(unsigned long vma) const +const symbol_entry * symbol_container_t::find_by_vma(bfd_vma vma) const { return impl->find_by_vma(vma); } @@ -288,7 +287,7 @@ } //--------------------------------------------------------------------------- -// Implementation. +/// implementation of sample_container_t class sample_container_impl { public: @@ -298,7 +297,7 @@ bool accumulate_samples_for_file(counter_array_t & counter, const string & filename) const; - const sample_entry * find_by_vma(unsigned long vma) const; + const sample_entry * find_by_vma(bfd_vma vma) const; bool accumulate_samples(counter_array_t &, const string & filename, size_t linenr) const; void push_back(const sample_entry &); private: @@ -326,7 +325,8 @@ return v.size(); } -inline void sample_container_impl::push_back(const sample_entry & sample) { +inline void sample_container_impl::push_back(const sample_entry & sample) +{ v.push_back(sample); } @@ -364,7 +364,7 @@ return false; } -const sample_entry * sample_container_impl::find_by_vma(unsigned long vma) const +const sample_entry * sample_container_impl::find_by_vma(bfd_vma vma) const { sample_entry value; @@ -448,7 +448,8 @@ return impl->accumulate_samples_for_file(counter, filename); } -const sample_entry * sample_container_t::find_by_vma(unsigned long vma) const { +const sample_entry * sample_container_t::find_by_vma(bfd_vma vma) const +{ return impl->find_by_vma(vma); } Index: opf_filter.cpp =================================================================== RCS file: /cvsroot/oprofile/oprofile/pp/opf_filter.cpp,v retrieving revision 1.21 retrieving revision 1.22 diff -u -d -r1.21 -r1.22 --- opf_filter.cpp 2001/09/30 13:57:05 1.21 +++ opf_filter.cpp 2001/10/01 02:07:41 1.22 @@ -77,7 +77,7 @@ }; //--------------------------------------------------------------------------- -// To hold the setup of the profiler for one counter. +/// Store the configuration of one counter. Construct from an opd_header struct counter_setup { counter_setup() : enabled(false), event_count_sample(0) {} @@ -452,9 +452,7 @@ // Complexity: log(container.size()) void output::find_and_output_symbol(const string& str, const char * blank) const { - unsigned long vma; - - sscanf(str.c_str(), "%lx", &vma); + bfd_vma vma = strtoul(str.c_str(), NULL, 16); const symbol_entry* symbol = symbols.find_by_vma(vma); @@ -466,10 +464,9 @@ } // Complexity: log(samples.size()) -void output::find_and_output_counter(const string& str, const char * blank) const { - unsigned long vma; - - sscanf(str.c_str(), "%lx", &vma); +void output::find_and_output_counter(const string& str, const char * blank) const +{ + bfd_vma vma = strtoul(str.c_str(), NULL, 16); const sample_entry * sample = samples.find_by_vma(vma); if (sample) { @@ -552,17 +549,15 @@ } if (str[pos] != ':') { // is the line contain a symbol - unsigned long vma; + bfd_vma vma = strtoul(str.c_str(), NULL, 16); - sscanf(str.c_str(), "%lx", &vma); + const symbol_entry* symbol = symbols.find_by_vma(vma); // ! complexity: linear in number of symbol // must use sorted by address vector and // lower_bound ? - const symbol_entry* symbol = symbols.find_by_vma(vma); - // Note this use a pointer comparison. It work - // because symbols symbol pointer are unique + // because symbols pointer are unique if (find(output_symbols.begin(), output_symbols.end(), symbol) != output_symbols.end()) { // probably an error due to ambiguity Index: opf_filter.h =================================================================== RCS file: /cvsroot/oprofile/oprofile/pp/opf_filter.h,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- opf_filter.h 2001/09/21 06:33:17 1.9 +++ opf_filter.h 2001/10/01 02:07:41 1.10 @@ -11,29 +11,39 @@ static const bool sanity_check = true; //--------------------------------------------------------------------------- -// A simple container for a fileno:linr location +/// A simple container for a fileno:linr location struct file_location { // This rely on a ref counted string implementation for efficiency. - string filename; // string() if not valid. - int linenr; // 0 means internally generated by the compiler + // TODO: after 0.0.5 release check this (comment is currently + // false) need to test if memory sharing is really a win + + /// empty if not valid. + string filename; + /// 0 means invalid or code is generated internally by the compiler + int linenr; }; //--------------------------------------------------------------------------- -// associate vma address with (filename linenr counter[]) +/// associate vma address with a file location and a samples count struct sample_entry { + /// From where file location comes the samples file_location file_loc; - unsigned long vma; // would be bfd_vma but avoid depend on bfd.h + /// From where virtual memory address comes the samples + bfd_vma vma; + /// the samples count counter_array_t counter; void debug_dump(ostream & out) const; }; //--------------------------------------------------------------------------- -// stored as a vector<symbol_entry> sorted by increased vma. +/// associate a symbol with a file location, samples count and vma address struct symbol_entry { + /// file location, vma and cumulated samples count for this symbol sample_entry sample; + /// name of symbol string name; - // [first, last[ gives the range of symbol_entry. + /// [first, last[ gives the range of sample_entry. size_t first; size_t last; @@ -41,26 +51,33 @@ }; //--------------------------------------------------------------------------- - class symbol_container_impl; +/// a container of symbols: member function dispatch to symbol_container_impl class symbol_container_t { public: symbol_container_t(); ~symbol_container_t(); + /// add a symbol to the underlined container. No attempt to detect + /// duplicate symbol is made void push_back(const symbol_entry &); + /// return the number of symbols in the underlined container size_t size() const; + /// return the symbol at index. Index range checking is not performed const symbol_entry & operator[](size_t index) const; + /// find the symbol at filename / linenr location const symbol_entry * find(string filename, size_t linenr) const; - const symbol_entry * find_by_vma(unsigned long vma) const; + /// find the symbol at vma + const symbol_entry * find_by_vma(bfd_vma vma) const; - /// get a vector of symbol_entry sorted by increased count. + /// get a vector of symbol_entry sorted by increased count of samples void get_symbols_by_count(size_t counter, vector<const symbol_entry*>& v) const; private: + /// member function of this class are delegated to this implementation symbol_container_impl * impl; }; @@ -68,22 +85,34 @@ class sample_container_impl; +/// a container of samples: member function dispatch to sample_container_impl class sample_container_t { public: sample_container_t(); ~sample_container_t(); + /// add a sample to the underlined container. No attempt to detect + /// duplicate sample is made void push_back(const sample_entry &); + /// return the number of samples in the underlined container size_t size() const; + /// return the sample at index. Index range checking is not performed const sample_entry & operator[](size_t index) const; + /// calculate the total number of samples for a file. Return false + /// if there is no sample for this file bool accumulate_samples_for_file(counter_array_t & counter, const string & filename) const; + /// calculate the total number of samples for a file/linenr. Return + /// false if there is no sample for this file bool accumulate_samples(counter_array_t &, const string & filename, size_t linenr) const; - const sample_entry * find_by_vma(unsigned long vma) const; + /// find a sample from a vma. Return NULL if no samples are available + /// at this vma. + const sample_entry * find_by_vma(bfd_vma vma) const; private: + /// member function of this class are delegated to this implementation sample_container_impl * impl; }; |