- Main Page
- Modules
- Namespaces
- Classes
- Files
- Related Pages

# timer_internal_graph.hh

Go to the documentation of this file.

    00001 // timer_internal_graph.hh: this file is part of the Vaucanson project.
    00002 //
    00003 // Vaucanson, a generic library for finite state machines.
    00004 //
    00005 // Copyright (C) 2006, 2007 The Vaucanson Group.
    00006 //
    00007 // This program is free software; you can redistribute it and/or
    00008 // modify it under the terms of the GNU General Public License
    00009 // as published by the Free Software Foundation; either version 2
    00010 // of the License, or (at your option) any later version.
    00011 //
    00012 // The complete GNU General Public Licence Notice can be found as the
    00013 // `COPYING' file in the root directory.
    00014 //
    00015 // The Vaucanson Group consists of people listed in the `AUTHORS' file.
    00016 //
    00017
    00018 #ifndef VCSN_MISC_TIMER_INTERNAL_GRAPH_HH
    00019 # define VCSN_MISC_TIMER_INTERNAL_GRAPH_HH
    00020
    00030 # include <list>
    00031 # include <string>
    00032 # include <iosfwd>
    00033 # include <boost/graph/adjacency_list.hpp>
    00034 # include <boost/graph/strong_components.hpp>
    00035 # include <boost/graph/graphviz.hpp>
    00036
    00037 # ifdef VAUCANSON
    00038 #  define NAMESPACE_VCSN_BEGIN namespace vcsn {
    00039 #  define NAMESPACE_VCSN_END   } // namespace vcsn
    00040 #  include <vaucanson/misc/timer_internal_gathering.hh>
    00041 # else
    00042 #  define NAMESPACE_VCSN_BEGIN
    00043 #  define NAMESPACE_VCSN_END
    00044 #  include <cassert>
    00045 #  include "timer_internal_gathering.hh"
    00046 #  define precondition(C) assert(C)
    00047 # endif
    00048
    00049 NAMESPACE_VCSN_BEGIN
    00050
    00051 namespace misc
    00052 {
    00053   class Timer;
    00054
    00055   namespace timer
    00056   {
    00057     class TimeStamp;
    00058
    00060     typedef enum verbose_degree
    00061       {
    00062         VERBOSE_NONE,
    00063         VERBOSE_MINIMAL,
    00064         VERBOSE_NORMAL,
    00065         VERBOSE_MAXIMAL
    00066       };
    00067
    00068     // Return the corresponding verbose_degree.
    00069     verbose_degree get_verbose_degree (int i);
    00070
    00071     // Graph output writers
    00072     class GraphWriter;
    00073     class VertexWriter;
    00074     class EdgeWriter;
    00075
    00076     // Extensive time representation
    00077     // (compare TimeStamp in timer_internal_gathering.hh)
    00078     struct TimeStats
    00079     {
    00080       TimeVal   user;
    00081       TimeVal   system;
    00082       TimeVal   cpu;
    00083       TimeVal   average;
    00084       double    charge;
    00085
    00086       TimeStats ();
    00087
    00088       friend class misc::Timer;
    00089
    00090     private:
    00091       // Dump time in XML
    00092       void dump (std::ostream& o,
    00093                  const std::string& name) const;
    00094     };
    00095
    00096     // Data analysis structures
    00097     struct GraphCall
    00098     {
    00099       // clear on init
    00100       GraphCall ();
    00101
    00102       void add_times (TimeStamp&                total,
    00103                       TimeStamp&                self,
    00104                       TimeStamp&                program,
    00105                       unsigned int              cnt);
    00106
    00107       void add_self_time (TimeStamp&            self,
    00108                           unsigned int          cnt);
    00109
    00110       void add_total_time (TimeStamp&           total,
    00111                            unsigned int         cnt);
    00112
    00113       void compute_average (TimeVal             program_cpu);
    00114
    00115
    00116       unsigned int      count;
    00117       unsigned int      from;
    00118       unsigned int      to;
    00119
    00120       TimeStats         total;
    00121       TimeStats         self;
    00122     };
    00123
    00124     struct GraphTask
    00125     {
    00126       // clear on init
    00127       GraphTask ();
    00128
    00129       void add_times (TimeStamp&                total,
    00130                       TimeStamp&                self,
    00131                       TimeStamp&                program,
    00132                       unsigned int              cnt);
    00133
    00134       void add_int_time (TimeStamp&             self,
    00135                          unsigned int           cnt);
    00136
    00137       void compute_average (TimeVal             program_cpu);
    00138
    00139
    00140       // Ordering using CPU time.
    00141       bool operator< (const GraphTask& task) const;
    00142
    00143       unsigned int      id;
    00144       std::string       name;
    00145
    00146       unsigned int      count;
    00147       unsigned int      recursive_count;
    00148       unsigned int      int_count;
    00149
    00150       TimeStats         total;
    00151       TimeStats         self;
    00152     };
    00153
    00154     struct GraphComponent
    00155     {
    00156       // clear on init
    00157       GraphComponent ();
    00158
    00159       void add_member (GraphTask&               task);
    00160
    00161       void add_call_inc (GraphCall&             call);
    00162
    00163       void add_call_out (GraphCall&             call);
    00164
    00165       void add_call_internal (GraphCall&        call);
    00166
    00167       void compute_average (TimeVal             program_cpu);
    00168
    00169       unsigned int      member_count;
    00170       std::list<int>    members;
    00171
    00172       std::list<GraphCall*> calls_in;
    00173       std::list<GraphCall*> calls_out;
    00174
    00175       unsigned int      out_calls;
    00176       unsigned int      int_calls;
    00177       unsigned int      calls;
    00178
    00179       unsigned int      id;
    00180
    00181       TimeStats         total;
    00182       TimeStats         self;
    00183
    00184       TimeVal           int_average;
    00185     };
    00186
    00187     typedef boost::adjacency_list<boost::vecS, boost::vecS,
    00188                                   boost::bidirectionalS,
    00189                                   GraphTask,
    00190                                   GraphCall> output_graph;
    00191
    00192     typedef std::pair<output_graph::vertex_iterator,
    00193                       output_graph::vertex_iterator> vertex_range;
    00194     typedef std::pair<output_graph::edge_iterator,
    00195                       output_graph::edge_iterator> edge_range;
    00196     typedef std::pair<output_graph::in_edge_iterator,
    00197                       output_graph::in_edge_iterator> in_edge_range;
    00198     typedef std::pair<output_graph::out_edge_iterator,
    00199                       output_graph::out_edge_iterator> out_edge_range;
    00200     typedef std::pair<output_graph::edge_iterator,
    00201                       output_graph::edge_iterator> edge_range;
    00202
    00203     typedef std::vector<int> component_id_vector;
    00204     typedef std::vector<GraphComponent> component_vector;
    00205
    00206     class VertexWriter
    00207     {
    00208     public:
    00209       VertexWriter (const Timer&         timer,
    00210                     const verbose_degree vd,
    00211                     double               ccr);
    00212
    00213       void operator() (std::ostream& out,
    00214                        const output_graph::vertex_descriptor& v) const;
    00215     private:
    00216       const output_graph&        g_;
    00217       const component_vector&    c_;
    00218       const component_id_vector& c_id_;
    00219       verbose_degree             vd_;
    00220       double                     chrg_col_ratio_;
    00221     };
    00222
    00223     class EdgeWriter
    00224     {
    00225     public:
    00226       EdgeWriter (const Timer&         timer,
    00227                   const verbose_degree vd,
    00228                   double               ccr);
    00229
    00230       void operator() (std::ostream& out,
    00231                        const output_graph::edge_descriptor& e) const;
    00232     private:
    00233       const output_graph&        g_;
    00234       const component_id_vector& c_id_;
    00235       verbose_degree             vd_;
    00236       double                     chrg_col_ratio_;
    00237     };
    00238
    00239     class GraphWriter
    00240     {
    00241     public:
    00242       GraphWriter (const Timer&         timer,
    00243                    const verbose_degree vd,
    00244                    double               ccr);
    00245
    00246       void operator() (std::ostream& out) const;
    00247     private:
    00248       const output_graph&        g_;
    00249       const component_vector&    c_;
    00250       const component_id_vector& c_id_;
    00251       verbose_degree             vd_;
    00252       double                     chrg_col_ratio_;
    00253     };
    00254   } // namespace timer
    00255 } // namespace misc
    00256
    00257 NAMESPACE_VCSN_END
    00258
    00259 #endif // !VCSN_MISC_TIMER_INTERNAL_GRAPH_HH