From: Philippe E. <ph...@us...> - 2003-04-25 17:32:03
|
Update of /cvsroot/oprofile/oprofile/pp In directory sc8-pr-cvs1:/tmp/cvs-serv23689/pp Modified Files: Tag: pp-interface-branch opreport.cpp opreport_options.h Log Message: finish to implement op_time like behavior. Remains to implement op_time -l regards, Phil Index: opreport.cpp =================================================================== RCS file: /cvsroot/oprofile/oprofile/pp/Attic/opreport.cpp,v retrieving revision 1.1.2.6 retrieving revision 1.1.2.7 diff -u -d -r1.1.2.6 -r1.1.2.7 --- opreport.cpp 25 Apr 2003 03:50:14 -0000 1.1.2.6 +++ opreport.cpp 25 Apr 2003 17:31:58 -0000 1.1.2.7 @@ -14,6 +14,7 @@ #include <vector> #include <algorithm> +#include "string_manip.h" #include "split_sample_filename.h" #include "opreport_options.h" #include "profile.h" @@ -23,12 +24,19 @@ namespace { +const int percent_width = 7; + struct merged_file_count { merged_file_count() : count(0) {} size_t count; string filename; }; +struct compare_merged_file_count { + bool operator()(merged_file_count const & lhs, + merged_file_count const & rhs) const; +}; + struct files_count { files_count() : count(0) {} size_t count; @@ -41,6 +49,16 @@ bool operator()(files_count const & lhs, files_count const & rhs) const; }; + +bool compare_merged_file_count::operator()(merged_file_count const & lhs, + merged_file_count const & rhs) const +{ + return options::reverse_sort + ? lhs.count < rhs.count + : rhs.count < lhs.count; +} + + bool compare_files_count::operator()(files_count const & lhs, files_count const & rhs) const { @@ -49,6 +67,7 @@ : rhs.count < lhs.count; } + files_count counts(partition_files::filename_set const & files) { files_count count; @@ -69,17 +88,56 @@ count.files.push_back(sub_count); } + sort(count.files.begin(), count.files.end(), + compare_merged_file_count()); + return count; } + +void output_counter(double total_count, size_t count) +{ + // left io manipulator doesn't exist in 2.95 + cout.setf(ios::left, ios::adjustfield); + cout << setw(9) << count << " "; + // FIXME: decimal point mis-aligned + // FIXME: with fixed size colummed output showing % is not good + double ratio = op_ratio(count, total_count); + cout << format_percent(ratio * 100, percent_width) << " "; +} + + +void output_sub_count(files_count const & files, double total_count) +{ + for (size_t i = 0; i < files.files.size(); ++i) { + merged_file_count const & count = files.files[i]; + + cout << "\t"; + double tot_count = options::global_percent + ? total_count : files.count; + output_counter(tot_count, count.count); + + split_sample_filename sp = split_sample_file(count.filename); + if (sp.lib_image.empty()) + cout << " " << sp.image; + else + cout << " " << sp.lib_image; + cout << endl; + } +} + + void output_files_count(partition_files const & files) { vector<files_count> set_file_count; + double total_count = 0; for (size_t i = 0 ; i < files.nr_set(); ++i) { partition_files::filename_set const & file_set = files.set(i); set_file_count.push_back(counts(file_set)); + + total_count += set_file_count.back().count; } sort(set_file_count.begin(), set_file_count.end(), @@ -87,7 +145,7 @@ vector<files_count>::const_iterator it; for (it = set_file_count.begin(); it != set_file_count.end(); ++it) { - cout << setw(6) << it->count << " "; + output_counter(total_count, it->count); if (!options::merge_by.merge_lib) { cout << it->image_name; } else { @@ -100,17 +158,7 @@ } cout << endl; if (!options::hide_dependent && !options::merge_by.merge_lib) { - for (size_t i = 0; i < it->files.size(); ++i) { - merged_file_count const & count = it->files[i]; - split_sample_filename sp = - split_sample_file(count.filename); - cout << "\t" << setw(6) << count.count << " "; - if (sp.lib_image.empty()) - cout << " " << sp.image; - else - cout << " " << sp.lib_image; - cout << endl; - } + output_sub_count(*it, total_count); } } } Index: opreport_options.h =================================================================== RCS file: /cvsroot/oprofile/oprofile/pp/Attic/opreport_options.h,v retrieving revision 1.1.2.4 retrieving revision 1.1.2.5 diff -u -d -r1.1.2.4 -r1.1.2.5 --- opreport_options.h 25 Apr 2003 03:50:14 -0000 1.1.2.4 +++ opreport_options.h 25 Apr 2003 17:31:58 -0000 1.1.2.5 @@ -25,6 +25,7 @@ extern bool hide_dependent; extern bool include_dependent; extern merge_option merge_by; + extern bool global_percent; } /** |