From: Richard P. <ri...@op...> - 2007-05-09 16:42:48
|
Replace cg_collection with an improved symbol_collection and use dynamic casting allowing more code reuse for callgraphs. ChangeLog | 12 ++++++++++++ libpp/callgraph_container.cpp | 21 +++++++++++++-------- libpp/callgraph_container.h | 7 ++++--- libpp/format_output.cpp | 22 +++++++++++----------- libpp/format_output.h | 2 +- libpp/symbol.h | 14 ++++++++------ libpp/symbol_sort.cpp | 17 ----------------- libpp/symbol_sort.h | 6 ------ pp/opreport.cpp | 3 ++- 9 files changed, 51 insertions(+), 53 deletions(-) Index: oprofile/libpp/callgraph_container.cpp =================================================================== --- oprofile.orig/libpp/callgraph_container.cpp +++ oprofile/libpp/callgraph_container.cpp @@ -379,12 +379,15 @@ process(count_array_t total, double thre process_children(sym, threshold); - cg_syms.push_back(sym); + cg_syms_objs.push_back(sym); } + + for (unsigned int i = 0; i < cg_syms_objs.size(); i++) + cg_syms.push_back(&cg_syms_objs[i]); } -cg_collection arc_recorder::get_symbols() const +symbol_collection arc_recorder::get_symbols() const { return cg_syms; } @@ -580,12 +583,14 @@ column_flags callgraph_container::output column_flags output_hints = cf_none; // FIXME: costly: must we access directly recorder map ? - cg_collection syms = recorder.get_symbols(); + symbol_collection syms = recorder.get_symbols(); - cg_collection::const_iterator it; - cg_collection::const_iterator const end = syms.end(); - for (it = syms.begin(); it != end; ++it) - output_hints = it->output_hint(output_hints); + symbol_collection::iterator it; + symbol_collection::iterator const end = syms.end(); + for (it = syms.begin(); it != end; ++it) { + cg_symbol const *cg_symb = dynamic_cast<const cg_symbol *>(*it); + output_hints = cg_symb->output_hint(output_hints); + } return output_hints; } @@ -597,7 +602,7 @@ count_array_t callgraph_container::sampl } -cg_collection callgraph_container::get_symbols() const +symbol_collection callgraph_container::get_symbols() const { return recorder.get_symbols(); } Index: oprofile/libpp/callgraph_container.h =================================================================== --- oprofile.orig/libpp/callgraph_container.h +++ oprofile/libpp/callgraph_container.h @@ -53,7 +53,7 @@ public: count_array_t const & arc_count); /// return all the cg symbols - cg_collection get_symbols() const; + symbol_collection get_symbols() const; /** * After population, build the final output, and do @@ -91,7 +91,8 @@ private: map_t sym_map; /// final output data - cg_collection cg_syms; + symbol_collection cg_syms; + cg_collection_objs cg_syms_objs; }; @@ -126,7 +127,7 @@ public: count_array_t samples_count() const; // return all the cg symbols - cg_collection get_symbols() const; + symbol_collection get_symbols() const; private: /** Index: oprofile/libpp/format_output.cpp =================================================================== --- oprofile.orig/libpp/format_output.cpp +++ oprofile/libpp/format_output.cpp @@ -489,7 +489,7 @@ cg_formatter::cg_formatter(callgraph_con } -void cg_formatter::output(ostream & out, cg_collection const & syms) +void cg_formatter::output(ostream & out, symbol_collection const & syms) { // amount of spacing prefixing child and parent lines string const child_parent_prefix(" "); @@ -498,37 +498,37 @@ void cg_formatter::output(ostream & out, out << string(79, '-') << endl; - cg_collection::const_iterator it; - cg_collection::const_iterator end = syms.end(); + symbol_collection::const_iterator it; + symbol_collection::const_iterator end = syms.end(); for (it = syms.begin(); it < end; ++it) { - cg_symbol const & sym = *it; + cg_symbol const *sym = dynamic_cast<const cg_symbol *>(*it); cg_symbol::children::const_iterator cit; - cg_symbol::children::const_iterator cend = sym.callers.end(); + cg_symbol::children::const_iterator cend = sym->callers.end(); counts_t c; if (global_percent) c.total = counts.total; else - c.total = sym.total_caller_count; + c.total = sym->total_caller_count; - for (cit = sym.callers.begin(); cit != cend; ++cit) { + for (cit = sym->callers.begin(); cit != cend; ++cit) { out << child_parent_prefix; do_output(out, *cit, cit->sample, c); } - do_output(out, sym, sym.sample, counts); + do_output(out, *sym, sym->sample, counts); c = counts_t(); if (global_percent) c.total = counts.total; else - c.total = sym.total_callee_count; + c.total = sym->total_callee_count; - cend = sym.callees.end(); + cend = sym->callees.end(); - for (cit = sym.callees.begin(); cit != cend; ++cit) { + for (cit = sym->callees.begin(); cit != cend; ++cit) { out << child_parent_prefix; do_output(out, *cit, cit->sample, c); } Index: oprofile/libpp/symbol.h =================================================================== --- oprofile.orig/libpp/symbol.h +++ oprofile/libpp/symbol.h @@ -56,8 +56,11 @@ struct sample_entry { /// associate a symbol with a file location, samples count and vma address -struct symbol_entry { +class symbol_entry { +public: symbol_entry() : size(0) {} + virtual ~symbol_entry() {} + /// which image this symbol belongs to image_name_id image_name; /// owning application name: identical to image name if profiling @@ -93,7 +96,8 @@ typedef std::vector<symbol_entry const * * the sample counts replaced with the relevant arc counts, whilst * the cg_symbol retains its self count. */ -struct cg_symbol : public symbol_entry { +class cg_symbol : public symbol_entry { +public: cg_symbol(symbol_entry const & sym) : symbol_entry(sym) {} typedef std::vector<symbol_entry> children; @@ -109,10 +113,8 @@ struct cg_symbol : public symbol_entry { count_array_t total_callee_count; }; - -/// a collection of sorted callgraph symbols -typedef std::vector<cg_symbol> cg_collection; - +/// a collection of sorted callgraph symbol objects +typedef std::vector<cg_symbol> cg_collection_objs; /// for storing diff %ages typedef growable_vector<double> diff_array_t; Index: oprofile/libpp/symbol_sort.cpp =================================================================== --- oprofile.orig/libpp/symbol_sort.cpp +++ oprofile/libpp/symbol_sort.cpp @@ -146,23 +146,6 @@ sort(symbol_collection & syms, bool reve void sort_options:: -sort(cg_collection & syms, bool reverse_sort, bool lf) const -{ - long_filenames = lf; - - vector<sort_order> sort_option(options); - for (sort_order cur = first; cur != last; cur = sort_order(cur + 1)) { - if (find(sort_option.begin(), sort_option.end(), cur) == - sort_option.end()) - sort_option.push_back(cur); - } - - stable_sort(syms.begin(), syms.end(), - symbol_compare(sort_option, reverse_sort)); -} - - -void sort_options:: sort(diff_collection & syms, bool reverse_sort, bool lf) const { long_filenames = lf; Index: oprofile/libpp/symbol_sort.h =================================================================== --- oprofile.orig/libpp/symbol_sort.h +++ oprofile/libpp/symbol_sort.h @@ -44,12 +44,6 @@ struct sort_options { /** * Sort the given container by the given criteria. */ - void sort(cg_collection & syms, bool reverse_sort, - bool long_filenames) const; - - /** - * Sort the given container by the given criteria. - */ void sort(diff_collection & syms, bool reverse_sort, bool long_filenames) const; Index: oprofile/pp/opreport.cpp =================================================================== --- oprofile.orig/pp/opreport.cpp +++ oprofile/pp/opreport.cpp @@ -445,7 +445,8 @@ void output_cg_symbols(callgraph_contain { column_flags output_hints = cg.output_hint(); - cg_collection symbols = cg.get_symbols(); + symbol_collection symbols = cg.get_symbols(); + options::sort_by.sort(symbols, options::reverse_sort, options::long_filenames); Index: oprofile/ChangeLog =================================================================== --- oprofile.orig/ChangeLog +++ oprofile/ChangeLog @@ -1,5 +1,17 @@ 2007-05-09 Richard Purdie <rp...@op...> + * libpp/callgraph_container.cpp: + * libpp/callgraph_container.h: + * libpp/format_output.cpp: + * libpp/format_output.h: + * libpp/symbol.h: + * libpp/symbol_sort.cpp: + * libpp/symbol_sort.h: + * pp/opreport.cpp: Convert cg_collection to symbol_collection and use + dynamic casting allowing more code reuse for callgraphs + +2007-05-09 Richard Purdie <rp...@op...> + * oparchive.cpp: * oparchive_options.cpp: * oparchive_options.h: Add --list-files option to list all files that Index: oprofile/libpp/format_output.h =================================================================== --- oprofile.orig/libpp/format_output.h +++ oprofile/libpp/format_output.h @@ -201,7 +201,7 @@ public: /** output callgraph information according to the previously format * specifier set by call(s) to add_format() */ - void output(std::ostream & out, cg_collection const & syms); + void output(std::ostream & out, symbol_collection const & syms); }; /// class to output a columned format symbols plus diff values |