format_output.h

Go to the documentation of this file.
00001 /**
00002  * @file format_output.h
00003  * outputting format for symbol lists
00004  *
00005  * @remark Copyright 2002 OProfile authors
00006  * @remark Read the file COPYING
00007  *
00008  * @author Philippe Elie
00009  * @author John Levon
00010  */
00011 
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 
00040 /// base class for formatter, handle common options to formatter
00041 class formatter {
00042 public:
00043         formatter(extra_images const & extra);
00044         virtual ~formatter();
00045 
00046         /// add a given column
00047         void add_format(format_flags flag);
00048 
00049         /// set the need_header boolean to false
00050         void show_header(bool);
00051         /// format for 64 bit wide VMAs
00052         void vma_format_64bit(bool);
00053         /// show long (full path) filenames
00054         void show_long_filenames(bool);
00055         /// use global count rather symbol count for details percent
00056         void show_global_percent(bool);
00057 
00058         /**
00059          * Set the number of collected profile classes. Each class
00060          * will output sample count and percentage in extra columns.
00061          *
00062          * This class assumes that the profile information has been
00063          * populated with the right number of classes.
00064          */
00065         void set_nr_classes(size_t nr_classes);
00066 
00067         /// output table header, implemented by calling the virtual function
00068         /// output_header_field()
00069         void output_header(std::ostream & out);
00070 
00071 protected:
00072         struct counts_t {
00073                 /// total sample count
00074                 count_array_t total;
00075                 /// samples so far
00076                 count_array_t cumulated_samples;
00077                 /// percentage so far
00078                 count_array_t cumulated_percent;
00079                 /// detailed percentage so far
00080                 count_array_t cumulated_percent_details;
00081         };
00082 
00083         /// data passed for output
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                 mutable counts_t & counts;
00095                 extra_images const & extra;
00096                 double diff;
00097         };
00098  
00099         /// format callback type
00100         typedef std::string (formatter::*fct_format)(field_datum const &);
00101  
00102         /** @name format functions.
00103          * The set of formatting functions, used internally by output().
00104          */
00105         //@{
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 &);
00118         //@}
00119  
00120         /// decribe one field of the colummned output.
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 
00134         /// actually do output
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  
00140         /// returns the nr of char needed to pad this field
00141         size_t output_header_field(std::ostream & out, format_flags fl,
00142                                    size_t padding);
00143 
00144         /// returns the nr of char needed to pad this field
00145         size_t output_field(std::ostream & out, field_datum const & datum,
00146                            format_flags fl, size_t padding,
00147                            bool hide_immutable);
00148  
00149         /// stores functors for doing actual formatting
00150         format_map_t format_map;
00151 
00152         /// number of profile classes
00153         size_t nr_classes;
00154 
00155         /// total counts
00156         counts_t counts;
00157 
00158         /// formatting flags set
00159         format_flags flags;
00160         /// true if we need to format as 64 bits quantities
00161         bool vma_64;
00162         /// false if we use basename(filename) in output rather filename
00163         bool long_filenames;
00164         /// true if we need to show header before the first output
00165         bool need_header;
00166         /// bool if details percentage are relative to total count rather to
00167         /// symbol count
00168         bool global_percent;
00169 
00170         /// To retrieve the real image location, usefull when acting on
00171         /// an archive and for 2.6 kernel modules
00172         extra_images const & extra_found_images;
00173 };
00174  
00175 
00176 /// class to output in a columned format symbols and associated samples
00177 class opreport_formatter : public formatter {
00178 public:
00179         /// build a ready to use formatter
00180         opreport_formatter(profile_container const & profile);
00181 
00182         /** output a vector of symbols to out according to the output format
00183          * specifier previously set by call(s) to add_format() */
00184         void output(std::ostream & out, symbol_collection const & syms);
00185 
00186         /// set the output_details boolean
00187         void show_details(bool);
00188 
00189 private:
00190  
00191         /** output one symbol symb to out according to the output format
00192          * specifier previously set by call(s) to add_format() */
00193         void output(std::ostream & out, symbol_entry const * symb);
00194 
00195         /// output details for the symbol
00196         void output_details(std::ostream & out, symbol_entry const * symb);
00197  
00198         /// container we work from
00199         profile_container const & profile;
00200  
00201         /// true if we need to show details for each symbols
00202         bool need_details;
00203 };
00204 
00205 
00206 /// class to output in a columned format caller/callee and associated samples
00207 class cg_formatter : public formatter {
00208 public:
00209         /// build a ready to use formatter
00210         cg_formatter(callgraph_container const & profile);
00211 
00212         /** output callgraph information according to the previously format
00213          * specifier set by call(s) to add_format() */
00214         void output(std::ostream & out, symbol_collection const & syms);
00215 };
00216 
00217 /// class to output a columned format symbols plus diff values
00218 class diff_formatter : public formatter {
00219 public:
00220         /// build a ready to use formatter
00221         diff_formatter(diff_container const & profile,
00222                        extra_images const & extra);
00223 
00224         /**
00225          * Output a vector of symbols to out according to the output
00226          * format specifier previously set by call(s) to add_format()
00227          */
00228         void output(std::ostream & out, diff_collection const & syms);
00229 
00230 private:
00231         /// output a single symbol
00232         void output(std::ostream & out, diff_symbol const & sym);
00233 
00234 };
00235 
00236 
00237 /// class to output in XML format
00238 class xml_formatter : public formatter {
00239 public:
00240         /// build a ready to use formatter
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 
00248         /** output one symbol symb to out according to the output format
00249          * specifier previously set by call(s) to add_format() */
00250         virtual void output_symbol(std::ostream & out,
00251                 symbol_entry const * symb, size_t lo, size_t hi,
00252                 bool is_module);
00253 
00254         /// output details for the symbol
00255         std::string output_symbol_details(symbol_entry const * symb,
00256                 size_t & detail_index, size_t const lo, size_t const hi);
00257 
00258         /// set the output_details boolean
00259         void show_details(bool);
00260 
00261         // output SymbolData XML elements
00262         void output_symbol_data(std::ostream & out);
00263 
00264 private:
00265         /// container we work from
00266         profile_container const * profile;
00267  
00268         // ordered collection of symbols associated with this profile
00269         symbol_collection & symbols;
00270 
00271         /// true if we need to show details for each symbols
00272         bool need_details;
00273 
00274         // count of DetailData items output so far
00275         size_t detail_count;
00276 
00277         /// with --details we need to reopen the bfd object for each symb to
00278         /// get it's contents, hence we store the filter used by the bfd ctor.
00279         string_filter const & symbol_filter;
00280 
00281         void output_sample_data(std::ostream & out,
00282                 sample_entry const & sample, size_t count);
00283 
00284         /// output attribute in XML
00285         void output_attribute(std::ostream & out, field_datum const & datum,
00286                               format_flags fl, tag_t tag);
00287 
00288         /// Retrieve a bfd object for this symbol, reopening a new bfd object
00289         /// only if necessary
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:
00302         /// build a ready to use formatter
00303         xml_cg_formatter(callgraph_container const & callgraph,
00304                 symbol_collection & symbols, string_filter const & sf);
00305 
00306         /** output one symbol symb to out according to the output format
00307          * specifier previously set by call(s) to add_format() */
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:
00312         /// container we work from
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 Thu Jul 17 19:52:46 2008 for oprofile by  doxygen 1.4.6