timer.hh

Go to the documentation of this file.
00001 // timer.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_HH
00019 # define VCSN_MISC_TIMER_HH
00020 
00256 # include <stack>
00257 # include <map>
00258 # include <list>
00259 # include <string>
00260 # include <iosfwd>
00261 # include <boost/graph/adjacency_list.hpp>
00262 # include <boost/graph/strong_components.hpp>
00263 # include <boost/graph/graphviz.hpp>
00264 
00265 /* Disable this when outside Vaucanson */
00266 # define VAUCANSON 1
00267 
00268 # ifdef VAUCANSON
00269 #  define NAMESPACE_VCSN_BEGIN namespace vcsn {
00270 #  define NAMESPACE_VCSN_END   } // namespace vcsn
00271 #  include <vaucanson/misc/contract.hh>
00272 #  include <vaucanson/misc/timer_internal_gathering.hh>
00273 #  include <vaucanson/misc/timer_internal_graph.hh>
00274 # else
00275 #  define NAMESPACE_VCSN_BEGIN
00276 #  define NAMESPACE_VCSN_END
00277 #  include <cassert>
00278 #  define precondition(C) assert(C)
00279 #  include "timer_internal_gathering.hh"
00280 #  include "timer_internal_graph.hh"
00281 # endif
00282 
00283 NAMESPACE_VCSN_BEGIN
00284 
00285 namespace misc
00286 {
00288   class Timer;
00289 
00291   class ScopedTimer
00292   {
00293   public:
00297     ScopedTimer (Timer& timer, const unsigned int i);
00298 
00303     ScopedTimer (Timer& timer, const std::string& name);
00304 
00307     ~ScopedTimer ();
00308   private:
00309     Timer* timer_;
00310   };
00311 
00312   class Timer
00313   {
00314   public:
00315 
00317     Timer ();
00320     Timer (const Timer& rhs);
00321 
00322     ~Timer ();
00323 
00327     const Timer& operator= (const Timer& rhs);
00328 
00334     unsigned int task (const std::string& name);
00335 
00339     void start ();
00340 
00343     void stop ();
00344 
00347     void clear ();
00348 
00352     std::ostream& print (std::ostream& o,
00353                          timer::verbose_degree vd = timer::VERBOSE_NORMAL)
00354       const;
00355 
00362     std::ostream& export_dot (std::ostream&         o,
00363                               timer::verbose_degree vd = timer::VERBOSE_NORMAL,
00364                               double                ccr = 1) const;
00365 
00370     std::ostream& dump (std::ostream& o) const;
00371 
00375     void push (const std::string& name);
00376 
00377     // Start a sub-timer for a task using its id number (which must
00378     // be declared beforehand).
00380     void push (const unsigned int i);
00381 
00384     void pop (const std::string& task_name);
00385 
00388     void pop (const unsigned int i);
00389 
00392     void pop ();
00393 
00397     bool operator< (const Timer& rhs) const;
00398 
00406     Timer& operator+= (const Timer& rhs);
00407 
00414     Timer operator+ (const Timer& rhs);
00415 
00420     Timer& operator/= (unsigned rhs);
00421 
00426     Timer operator/ (unsigned rhs) const;
00427 
00428   private:
00429     /*------------------------------.
00430     | Timer: Internal structures.   |
00431     `------------------------------*/
00432 
00433     // Graph output writers
00434     friend class timer::GraphWriter;
00435     friend class timer::VertexWriter;
00436     friend class timer::EdgeWriter;
00437 
00438     // Add task vertices and call edges to the graph
00439     void build_output_graph ();
00440     // Build connected component array
00441     void build_connected_components ();
00442 
00443     // Compute task & call times in graph
00444     void compute_output_graph ();
00445     // Compute component times in graph
00446     void compute_connected_components ();
00447 
00448     void print_output_graph (std::ostream& o,
00449                              timer::verbose_degree vd = timer::VERBOSE_NORMAL)
00450       const;
00451 
00452     timer::call_stack           calls_;
00453     timer::task_vector          tasks_;
00454     timer::task_names_map       names_;
00455     timer::TimeStamp            time_;
00456 
00457     timer::output_graph         graph_;
00458     timer::component_id_vector  comp_id_;
00459     timer::component_vector     comp_;
00460     unsigned int                comp_count_;
00461     unsigned int                task_count_;
00462 
00463     bool                        is_running_;
00464 
00465     bool                        cleared_;
00466   };
00467 } // namespace misc
00468 
00469 NAMESPACE_VCSN_END
00470 
00471 # if !defined VCSN_USE_INTERFACE_ONLY || defined VCSN_USE_LIB
00472 #  ifdef VAUCANSON
00473 #   include <vaucanson/misc/timer_internal_gathering.hxx>
00474 #   include <vaucanson/misc/timer_internal_graph.hxx>
00475 #   include <vaucanson/misc/timer.hxx>
00476 #   include <vaucanson/misc/timer_internal_gathering.cc>
00477 #   include <vaucanson/misc/timer_internal_graph.cc>
00478 #   include <vaucanson/misc/timer.cc>
00479 #  else
00480 #   include "timer_internal_gathering.hxx"
00481 #   include "timer_internal_graph.hxx"
00482 #   include "timer.hxx"
00483 #  endif
00484 # endif // !VCSN_USE_INTERFACE_ONLY
00485 
00486 #endif // !VCSN_MISC_TIMER_HH

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