From: John L. <mov...@us...> - 2003-05-08 08:38:32
|
Update of /cvsroot/oprofile/oprofile/pp In directory sc8-pr-cvs1:/tmp/cvs-serv31907/pp Modified Files: Tag: pp-interface-branch opreport.cpp opreport_options.cpp opreport_options.h Log Message: --output-file support - committing before trying something, hoipefully won't last Index: opreport.cpp =================================================================== RCS file: /cvsroot/oprofile/oprofile/pp/Attic/opreport.cpp,v retrieving revision 1.1.2.27 retrieving revision 1.1.2.28 diff -u -d -r1.1.2.27 -r1.1.2.28 --- opreport.cpp 8 May 2003 07:30:20 -0000 1.1.2.27 +++ opreport.cpp 8 May 2003 08:38:27 -0000 1.1.2.28 @@ -124,7 +124,7 @@ // See FIXME in opannotate.cpp for similar code profile_t profile; profile.add_sample_file(file_set.begin()->sample_filename, 0); - output_header(cout, profile.get_header()); + output_header(options::cout(), profile.get_header()); } } @@ -133,10 +133,10 @@ { // FIXME: left or right, op_time was using left // left io manipulator doesn't exist in 2.95 -// cout.setf(ios::left, ios::adjustfield); - cout << setw(9) << count << " "; +// options::cout().setf(ios::left, ios::adjustfield); + options::cout() << setw(9) << count << " "; double ratio = op_ratio(count, total_count); - cout << format_double(ratio * 100, 3, 4) << " "; + options::cout() << format_double(ratio * 100, 3, 4) << " "; } @@ -151,16 +151,16 @@ for (size_t i = 0; i < files.files.size(); ++i) { merged_file_count const & count = files.files[i]; - cout << "\t"; + options::cout() << "\t"; double tot_count = options::global_percent ? total_count : files.count; output_counter(tot_count, count.count); if (count.lib_image.empty()) - cout << " " << get_filename(count.image_name); + options::cout() << " " << get_filename(count.image_name); else - cout << " " << get_filename(count.lib_image); - cout << endl; + options::cout() << " " << get_filename(count.lib_image); + options::cout() << endl; } } @@ -185,14 +185,14 @@ for (it = set_file_count.begin(); it != set_file_count.end(); ++it) { output_counter(total_count, it->count); if (!options::merge_by.merge_lib) { - cout << get_filename(it->image_name); + options::cout() << get_filename(it->image_name); } else { if (it->lib_image.empty()) - cout << get_filename(it->image_name); + options::cout() << get_filename(it->image_name); else - cout << get_filename(it->lib_image); + options::cout() << get_filename(it->lib_image); } - cout << endl; + options::cout() << endl; if (options::include_dependent && !options::hide_dependent && !options::merge_by.merge_lib) { output_sub_count(*it, total_count); @@ -285,7 +285,7 @@ out.add_format(flags); - out.output(cout, symbols, options::reverse_sort, need_vma64); + out.output(options::cout(), symbols, options::reverse_sort, need_vma64); } Index: opreport_options.cpp =================================================================== RCS file: /cvsroot/oprofile/oprofile/pp/Attic/opreport_options.cpp,v retrieving revision 1.1.2.22 retrieving revision 1.1.2.23 diff -u -d -r1.1.2.22 -r1.1.2.23 --- opreport_options.cpp 7 May 2003 06:09:47 -0000 1.1.2.22 +++ opreport_options.cpp 8 May 2003 08:38:27 -0000 1.1.2.23 @@ -14,6 +14,7 @@ #include <iostream> #include <algorithm> #include <iterator> +#include <fstream> #include "profile_spec.h" #include "opreport_options.h" @@ -53,11 +54,30 @@ namespace { string threshold; -vector<string> merge; +string outfile; +vector<string> mergespec; vector<string> sort_by; vector<string> exclude_symbols; vector<string> include_symbols; +} + + +std::ostream & options::cout() +{ + if (!outfile.empty()) { + static ofstream stream(outfile.c_str()); + if (!stream) { + cerr << "Could not open output file \"" + << outfile << "\" for writing." << endl; + exit(EXIT_FAILURE); + } + return stream; + } + return std::cout; +} + + popt::option options_array[] = { popt::option(options::demangle, "demangle", 'd', "demangle GNU C++ symbol names (default on)"), @@ -65,6 +85,8 @@ "don't demangle GNU C++ symbol names"), popt::option(options::smart_demangle, "smart-demangle", 'D', "demangle GNU C++ symbol names and shrink them"), + popt::option(outfile, "output-file", 'o', + "output to the given filename", "file"), // PP:5 popt::option(options::symbols, "symbols", 'l', "list all symbols"), @@ -85,7 +107,7 @@ "exclude these comma separated symbols", "symbols"), popt::option(include_symbols, "include-symbols", 'i', "include these comma separated symbols", "symbols"), - popt::option(merge, "merge", 'm', + popt::option(mergespec, "merge", 'm', "comma separated list", "cpu,pid,lib"), popt::option(options::show_header, "no-header", '\0', "remove all header from output"), @@ -100,6 +122,7 @@ "count but total sample count"), }; + // FIXME: separate file if reused void handle_threshold() { @@ -132,19 +155,22 @@ sort_by.push_back("sample"); } - for (size_t i = 0; i < sort_by.size(); ++i) { - if (sort_by[i] == "vma") { + vector<string>::const_iterator cit = sort_by.begin(); + vector<string>::const_iterator end = sort_by.end(); + + for (; cit != end; ++cit) { + if (*cit == "vma") { options::sort_by_vma = true; - } else if (sort_by[i] == "sample") { + } else if (*cit == "sample") { options::sort_by_sample = true; - } else if (sort_by[i] == "symbol") { + } else if (*cit == "symbol") { options::sort_by_symbol = true; - } else if (sort_by[i] == "debug") { + } else if (*cit == "debug") { options::sort_by_debug = true; - } else if (sort_by[i] == "image") { + } else if (*cit == "image") { options::sort_by_image = true; } else { - cerr << "unknown sort option: " << sort_by[i] << endl; + cerr << "unknown sort option: " << *cit << endl; exit(EXIT_FAILURE); } } @@ -153,34 +179,35 @@ // FIXME: separate file if reused void handle_merge_option() { - for (size_t i = 0; i < merge.size(); ++i) { - if (merge[i] == "cpu") { + vector<string>::const_iterator cit = mergespec.begin(); + vector<string>::const_iterator end = mergespec.end(); + + for (; cit != end; ++cit) { + if (*cit == "cpu") { options::merge_by.merge_cpu = true; - } else if (merge[i] == "tid") { + } else if (*cit == "tid") { options::merge_by.merge_tid = true; - } else if (merge[i] == "tgid") { + } else if (*cit == "tgid") { // PP:5.21 tgid merge imply tid merging. options::merge_by.merge_tgid = true; options::merge_by.merge_tid = true; - } else if (merge[i] == "lib") { + } else if (*cit == "lib") { options::merge_by.merge_lib = true; - } else if (merge[i] == "unitmask") { + } else if (*cit == "unitmask") { options::merge_by.merge_unitmask = true; - } else if (merge[i] == "all") { + } else if (*cit == "all") { options::merge_by.merge_cpu = true; options::merge_by.merge_lib = true; options::merge_by.merge_tid = true; options::merge_by.merge_tgid = true; options::merge_by.merge_unitmask = true; } else { - cerr << "unknown merge option: " << merge[i] << endl; + cerr << "unknown merge option: " << *cit << endl; exit(EXIT_FAILURE); } } } -} // anonymous namespace - void handle_options(vector<string> const & non_options) { @@ -190,9 +217,7 @@ options::symbols = true; handle_threshold(); - handle_sort_option(); - handle_merge_option(); options::symbol_filter = string_filter(include_symbols, exclude_symbols); Index: opreport_options.h =================================================================== RCS file: /cvsroot/oprofile/oprofile/pp/Attic/opreport_options.h,v retrieving revision 1.1.2.16 retrieving revision 1.1.2.17 diff -u -d -r1.1.2.16 -r1.1.2.17 --- opreport_options.h 8 May 2003 07:30:20 -0000 1.1.2.16 +++ opreport_options.h 8 May 2003 08:38:27 -0000 1.1.2.17 @@ -14,6 +14,7 @@ #include <string> #include <vector> +#include <iosfwd> #include "common_option.h" #include "utility.h" @@ -38,6 +39,8 @@ extern double threshold; extern bool show_header; extern bool accumulated; + // I hate C++ + std::ostream & cout(); } /** |