timer.hxx

Go to the documentation of this file.
00001 // timer.hxx: 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 
00023 #ifndef VCSN_MISC_TIMER_HXX
00024 # define VCSN_MISC_TIMER_HXX
00025 
00026 # include <iosfwd>
00027 
00028 # include <sys/times.h>
00029 # include <unistd.h>
00030 
00031 # ifdef VAUCANSON
00032 #  include <vaucanson/misc/timer.hh>
00033 # else
00034 #  include "timer.hh"
00035 # endif
00036 
00037 NAMESPACE_VCSN_BEGIN
00038 
00039 namespace misc
00040 {
00041 
00042   /*------------------.
00043   | Timer.            |
00044   | General methods.  |
00045   `------------------*/
00046 
00047   inline
00048   Timer::~Timer ()
00049   {
00050   }
00051 
00052   /*--------------.
00053   | Timer.        |
00054   | Arithmetics.  |
00055   `--------------*/
00056 
00057   inline
00058   bool
00059   Timer::operator< (const Timer& rhs) const
00060   {
00061     precondition (! (is_running_ || rhs.is_running_));
00062 
00063     return graph_[0].total.cpu < rhs.graph_[0].total.cpu;
00064   }
00065 
00066   /*----------------------.
00067   | Timer.                |
00068   | Result computation.   |
00069   `----------------------*/
00070 
00071   inline
00072   void
00073   Timer::build_connected_components ()
00074   {
00075     comp_id_.resize (num_vertices (graph_));
00076     comp_count_ = strong_components (graph_, &comp_id_[0]);
00077   }
00078 
00079   /*-----------.
00080   | Timer.     |
00081   | Printing.  |
00082   `-----------*/
00083 
00084   inline
00085   std::ostream&
00086   Timer::print (std::ostream&         o,
00087                 timer::verbose_degree vd) const
00088   {
00089     print_output_graph(o, vd);
00090 
00091     return o;
00092   }
00093 
00094   inline
00095   std::ostream&
00096   Timer::export_dot (std::ostream&         o,
00097                      timer::verbose_degree vd,
00098                      double                ccr) const
00099   {
00100     write_graphviz (o, graph_,
00101                     timer::VertexWriter (*this, vd, ccr),
00102                     timer::EdgeWriter   (*this, vd, ccr),
00103                     timer::GraphWriter  (*this, vd, ccr));
00104     return o;
00105   }
00106 
00107   /*--------------.
00108   | ScopedTimer.  |
00109   `--------------*/
00110 
00111   inline
00112   ScopedTimer::ScopedTimer (Timer&             timer,
00113                             const unsigned int i)
00114   {
00115     timer_ = &timer;
00116     timer.push (i);
00117   }
00118 
00119   inline
00120   ScopedTimer::ScopedTimer (Timer&             timer,
00121                             const std::string& name)
00122   {
00123     timer_ = &timer;
00124     timer.push (name);
00125   }
00126 
00127   inline
00128   ScopedTimer::~ScopedTimer ()
00129   {
00130     timer_->pop ();
00131   }
00132 
00133   /*--------------------------.
00134   | Free standing functions.  |
00135   `--------------------------*/
00136 
00138   inline
00139   std::ostream&
00140   operator<< (std::ostream& o,
00141               const Timer&  t)
00142   {
00143     return t.print (o, timer::VERBOSE_NONE);
00144   }
00145 
00146 
00147 } // namespace misc
00148 
00149 NAMESPACE_VCSN_END
00150 
00151 #endif 

Generated on Sun Jul 29 19:35:30 2007 for Vaucanson by  doxygen 1.5.2