format_output.h

Go to the documentation of this file.
00001 
00012 #ifndef FORMAT_OUTPUT_H
00013 #define FORMAT_OUTPUT_H
00014 
00015 #include "config.h"
00016 
00017 #include <string>
00018 #include <map>
00019 #include <iosfwd>
00020 
00021 #include "format_flags.h"
00022 #include "symbol.h"
00023 #include "string_filter.h"
00024 #include "xml_output.h"
00025 
00026 class symbol_entry;
00027 class sample_entry;
00028 class callgraph_container;
00029 class profile_container;
00030 class diff_container;
00031 class extra_images;
00032 class op_bfd;
00033 
00034 struct profile_classes;
00035 // FIXME: should be passed to the derived class formatter ctor
00036 extern profile_classes classes;
00037 
00038 namespace format_output {
00039 
00041 class formatter {
00042 public:
00043     formatter(extra_images const & extra);
00044     virtual ~formatter();
00045 
00047     void add_format(format_flags flag);
00048 
00050     void show_header(bool);
00052     void vma_format_64bit(bool);
00054     void show_long_filenames(bool);
00056     void show_global_percent(bool);
00057 
00065     void set_nr_classes(size_t nr_classes);
00066 
00069     void output_header(std::ostream & out);
00070 
00071 protected:
00072     struct counts_t {
00074         count_array_t total;
00076         count_array_t cumulated_samples;
00078         count_array_t cumulated_percent;
00080         count_array_t cumulated_percent_details;
00081     };
00082 
00084     struct field_datum {
00085         field_datum(symbol_entry const & sym,
00086                     sample_entry const & s,
00087                 size_t pc, counts_t & c,
00088                 extra_images const & extra, double d = 0.0)
00089             : symbol(sym), sample(s), pclass(pc),
00090               counts(c), extra(extra), diff(d) {}
00091         symbol_entry const & symbol;
00092         sample_entry const & sample;
00093         size_t pclass;
00094         counts_t & counts;
00095         extra_images const & extra;
00096         double diff;
00097     };
00098  
00100     typedef std::string (formatter::*fct_format)(field_datum const &);
00101  
00106     std::string format_vma(field_datum const &);
00107     std::string format_symb_name(field_datum const &);
00108     std::string format_image_name(field_datum const &);
00109     std::string format_app_name(field_datum const &);
00110     std::string format_linenr_info(field_datum const &);
00111     std::string format_nr_samples(field_datum const &);
00112     std::string format_nr_cumulated_samples(field_datum const &);
00113     std::string format_percent(field_datum const &);
00114     std::string format_cumulated_percent(field_datum const &);
00115     std::string format_percent_details(field_datum const &);
00116     std::string format_cumulated_percent_details(field_datum const &);
00117     std::string format_diff(field_datum const &);
00119  
00121     struct field_description {
00122         field_description() {}
00123         field_description(std::size_t w, std::string h,
00124                   fct_format f)
00125             : width(w), header_name(h), formatter(f) {}
00126  
00127         std::size_t width;
00128         std::string header_name;
00129         fct_format formatter;
00130     };
00131  
00132     typedef std::map<format_flags, field_description> format_map_t;
00133 
00135     void do_output(std::ostream & out, symbol_entry const & symbol,
00136               sample_entry const & sample, counts_t & c,
00137                   diff_array_t const & = diff_array_t(),
00138                   bool hide_immutable_field = false);
00139  
00141     size_t output_header_field(std::ostream & out, format_flags fl,
00142                                size_t padding);
00143 
00145     size_t output_field(std::ostream & out, field_datum const & datum,
00146                format_flags fl, size_t padding,
00147                bool hide_immutable);
00148  
00150     format_map_t format_map;
00151 
00153     size_t nr_classes;
00154 
00156     counts_t counts;
00157 
00159     format_flags flags;
00161     bool vma_64;
00163     bool long_filenames;
00165     bool need_header;
00168     bool global_percent;
00169 
00172     extra_images const & extra_found_images;
00173 };
00174  
00175 
00177 class opreport_formatter : public formatter {
00178 public:
00180     opreport_formatter(profile_container const & profile);
00181 
00184     void output(std::ostream & out, symbol_collection const & syms);
00185 
00187     void show_details(bool);
00188 
00189 private:
00190  
00193     void output(std::ostream & out, symbol_entry const * symb);
00194 
00196     void output_details(std::ostream & out, symbol_entry const * symb);
00197  
00199     profile_container const & profile;
00200  
00202     bool need_details;
00203 };
00204 
00205 
00207 class cg_formatter : public formatter {
00208 public:
00210     cg_formatter(callgraph_container const & profile);
00211 
00214     void output(std::ostream & out, symbol_collection const & syms);
00215 };
00216 
00218 class diff_formatter : public formatter {
00219 public:
00221     diff_formatter(diff_container const & profile,
00222                extra_images const & extra);
00223 
00228     void output(std::ostream & out, diff_collection const & syms);
00229 
00230 private:
00232     void output(std::ostream & out, diff_symbol const & sym);
00233 
00234 };
00235 
00236 
00238 class xml_formatter : public formatter {
00239 public:
00241     xml_formatter(profile_container const * profile,
00242               symbol_collection & symbols, extra_images const & extra,
00243               string_filter const & symbol_filter);
00244 
00245     // output body of XML output
00246     void output(std::ostream & out);
00247 
00250     virtual void output_symbol(std::ostream & out,
00251         symbol_entry const * symb, size_t lo, size_t hi,
00252         bool is_module);
00253 
00255     std::string output_symbol_details(symbol_entry const * symb,
00256         size_t & detail_index, size_t const lo, size_t const hi);
00257 
00259     void show_details(bool);
00260 
00261     // output SymbolData XML elements
00262     void output_symbol_data(std::ostream & out);
00263 
00264 private:
00266     profile_container const * profile;
00267  
00268     // ordered collection of symbols associated with this profile
00269     symbol_collection & symbols;
00270 
00272     bool need_details;
00273 
00274     // count of DetailData items output so far
00275     size_t detail_count;
00276 
00279     string_filter const & symbol_filter;
00280 
00281     void output_sample_data(std::ostream & out,
00282         sample_entry const & sample, size_t count);
00283 
00285     void output_attribute(std::ostream & out, field_datum const & datum,
00286                   format_flags fl, tag_t tag);
00287 
00290     bool get_bfd_object(symbol_entry const * symb, op_bfd * & abfd) const;
00291 
00292     void output_the_symbol_data(std::ostream & out,
00293         symbol_entry const * symb, op_bfd * & abfd);
00294 
00295     void output_cg_children(std::ostream & out,
00296         cg_symbol::children const cg_symb, op_bfd * & abfd);
00297 };
00298 
00299 // callgraph XML output version
00300 class xml_cg_formatter : public xml_formatter {
00301 public:
00303     xml_cg_formatter(callgraph_container const & callgraph,
00304         symbol_collection & symbols, string_filter const & sf);
00305 
00308     virtual void output_symbol(std::ostream & out,
00309         symbol_entry const * symb, size_t lo, size_t hi, bool is_module);
00310 
00311 private:
00313     callgraph_container const & callgraph;
00314 
00315     void output_symbol_core(std::ostream & out,
00316         cg_symbol::children const cg_symb,
00317         std::string const selfname, std::string const qname,
00318         size_t lo, size_t hi, bool is_module, tag_t tag);
00319 };
00320 
00321 } // namespace format_output 
00322 
00323 
00324 #endif /* !FORMAT_OUTPUT_H */

Generated on 8 Nov 2012 for Oprofile by  doxygen 1.6.1