timer_internal_gathering.hxx

Go to the documentation of this file.
00001 // timer_internal_gathering.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 
00025 #ifndef VCSN_MISC_TIMER_INTERNAL_GATHERING_HXX
00026 # define VCSN_MISC_TIMER_INTERNAL_GATHERING_HXX
00027 
00028 # include <iostream>
00029 # include <iomanip>
00030 
00031 # ifdef VAUCANSON
00032 #  include <vaucanson/misc/timer_internal_gathering.hh>
00033 # else
00034 #  include "timer_internal_gathering.hh"
00035 # endif
00036 
00037 NAMESPACE_VCSN_BEGIN
00038 
00039 namespace misc
00040 {
00041   namespace timer
00042   {
00043     /*-----------------.
00044     | Timer::TimeVal.  |
00045     `-----------------*/
00046 
00047     inline
00048     TimeVal::TimeVal ()
00049       : tv_sec  (0),
00050         tv_usec (0)
00051     {
00052     }
00053 
00054     inline
00055     TimeVal::TimeVal (int i)
00056       : tv_sec  (i),
00057         tv_usec (0)
00058     {
00059     }
00060 
00061     inline
00062     TimeVal::TimeVal (double d)
00063       : tv_sec  (long (d)),
00064         tv_usec (long (d * 1000000) % 1000000)
00065     {
00066     }
00067 
00068 
00069     inline
00070     TimeVal::TimeVal (const TimeVal& tv)
00071       : tv_sec  (tv.tv_sec),
00072         tv_usec (tv.tv_usec)
00073     {
00074     }
00075 
00076     inline
00077     TimeVal::TimeVal (const timeval& tv)
00078       : tv_sec  (tv.tv_sec),
00079         tv_usec (tv.tv_usec)
00080     {
00081     }
00082 
00083     inline
00084     TimeVal
00085     TimeVal::operator+ (const TimeVal& tv) const
00086     {
00087       TimeVal res;
00088       res.tv_sec = tv.tv_sec + tv_sec;
00089       res.tv_usec = tv.tv_usec + tv_usec;
00090       res.tv_sec += res.tv_usec / 1000000;
00091       res.tv_usec = res.tv_usec % 1000000;
00092       return res;
00093     }
00094 
00095     inline
00096     TimeVal
00097     TimeVal::operator- (const TimeVal& tv) const
00098     {
00099       TimeVal res (*this);
00100       res.tv_sec -= tv.tv_sec;
00101       res.tv_usec -= tv.tv_usec;
00102       res.tv_sec += res.tv_usec / 1000000;
00103       res.tv_usec = res.tv_usec % 1000000;
00104       return res;
00105     }
00106 
00107     inline
00108     TimeVal&
00109     TimeVal::operator+= (const TimeVal& tv)
00110     {
00111       tv_sec += tv.tv_sec;
00112       tv_usec += tv.tv_usec;
00113       tv_sec += tv_usec / 1000000;
00114       tv_usec = tv_usec % 1000000;
00115       return *this;
00116     }
00117 
00118     inline
00119     TimeVal&
00120     TimeVal::operator-= (const TimeVal& tv)
00121     {
00122       tv_sec -= tv.tv_sec;
00123       tv_usec -= tv.tv_usec;
00124       tv_sec += tv_usec / 1000000;
00125       tv_usec = tv_usec % 1000000;
00126       return *this;
00127     }
00128 
00129     inline
00130     TimeVal&
00131     TimeVal::operator= (const TimeVal& tv)
00132     {
00133       if (this == &tv)
00134         return *this;
00135       tv_sec = tv.tv_sec;
00136       tv_usec = tv.tv_usec;
00137       return *this;
00138     }
00139 
00140     inline
00141     TimeVal&
00142     TimeVal::operator/= (double d)
00143     {
00144       double t;
00145 
00146       t = tv_sec / d;
00147       tv_sec = long (t);
00148       tv_usec = long (tv_usec / d + (t - tv_sec) * 1000000);
00149       tv_sec += tv_usec / 1000000;
00150       tv_usec = tv_usec % 1000000;
00151       return *this;
00152     }
00153 
00154     inline
00155     TimeVal
00156     TimeVal::operator/ (double d) const
00157     {
00158       TimeVal res;
00159       double t;
00160 
00161       t = tv_sec / d;
00162       res.tv_sec = long (t);
00163       res.tv_usec = long (tv_usec / d + (t - res.tv_sec) * 1000000);
00164       return res;
00165     }
00166 
00167     inline
00168     bool
00169     TimeVal::operator< (const TimeVal& tv) const
00170     {
00171       return (tv_sec == tv.tv_sec ?
00172               tv_usec < tv.tv_usec :
00173               tv_sec < tv.tv_sec);
00174     }
00175 
00176     inline
00177     bool
00178     TimeVal::operator> (const TimeVal& tv) const
00179     {
00180       return (tv_sec == tv.tv_sec ?
00181               tv_usec > tv.tv_usec :
00182               tv_sec > tv.tv_sec);
00183     }
00184 
00185     inline
00186     bool
00187     TimeVal::operator== (const TimeVal& tv) const
00188     {
00189       return (tv_sec == tv.tv_sec && tv_usec == tv.tv_usec);
00190     }
00191 
00192 
00193     inline
00194     void
00195     TimeVal::clear ()
00196     {
00197       tv_sec = 0;
00198       tv_usec = 0;
00199     }
00200 
00201     inline
00202     void
00203     TimeVal::set (const timeval& tv)
00204     {
00205       tv_sec = tv.tv_sec;
00206       tv_usec = tv.tv_usec;
00207     }
00208 
00209     inline
00210     double
00211     TimeVal::us () const
00212     {
00213       return tv_usec + 1000000 * tv_sec;
00214     }
00215 
00216     inline
00217     double
00218     TimeVal::ms () const
00219     {
00220       return double (tv_usec) / 1000 + 1000 * tv_sec;
00221     }
00222 
00223     inline
00224     double
00225     TimeVal::s () const
00226     {
00227       return double (tv_usec) / 1000000 + tv_sec;
00228     }
00229 
00230     inline
00231     double
00232     TimeVal::m () const
00233     {
00234       return (double (tv_usec) / 1000000 + double (tv_sec)) / 60;
00235     }
00236 
00237     inline
00238     double
00239     TimeVal::h () const
00240     {
00241       return (double (tv_usec) / 1000000 + double (tv_sec)) / 3600;
00242     }
00243 
00244 
00245     /*--------------------------.
00246     | Free standing functions.  |
00247     `--------------------------*/
00248 
00249     inline
00250     std::ostream&
00251     operator<< (std::ostream&  o,
00252                 const TimeVal& tv)
00253     {
00254       return tv.print (o);
00255     }
00256 
00257     inline
00258     std::ostream& print_time (std::ostream&   o,
00259                               timer::TimeVal& time,
00260                               time_unit       u)
00261     {
00262       return time.print (o, u);
00263     }
00264 
00265     /*-------------------.
00266     | Timer::TimeStamp.  |
00267     `-------------------*/
00268 
00269     inline
00270     TimeStamp::TimeStamp ()
00271     {
00272     }
00273 
00274     inline
00275     std::ostream&
00276     TimeStamp::print (std::ostream& o) const
00277     {
00278       return o << '(' << user_ << ", " << sys_ << ')';
00279     }
00280 
00281     inline
00282     bool
00283     TimeStamp::operator< (const TimeStamp& rhs) const
00284     {
00285       return user_ + sys_ < rhs.user_ + rhs.sys_;
00286     }
00287 
00288     /*--------------.
00289     | Timer::Task.  |
00290     `--------------*/
00291 
00292     inline
00293     Task::Task ()
00294     {
00295     }
00296 
00297     inline
00298     Task::Task (const std::string& name,
00299                 unsigned int       id)
00300       : name_ (name),
00301         id_   (id)
00302     {
00303     }
00304 
00305     inline
00306     Task::~Task ()
00307     {
00308     }
00309 
00310     inline
00311     Call&
00312     Task::call(unsigned int called)
00313     {
00314       return calls_[called];
00315     }
00316 
00317     /*---------------------.
00318     | Timer::StackedCall.  |
00319     `---------------------*/
00320 
00321     inline
00322     StackedCall::StackedCall ()
00323     {
00324       total_.set_to_now ();
00325       children_.clear ();
00326     }
00327 
00328     inline
00329     StackedCall::StackedCall (unsigned int called)
00330     {
00331       called_ = called;
00332       total_.set_to_now ();
00333       children_.clear ();
00334     }
00335   } // namespace timer
00336 } // namespace misc
00337 
00338 NAMESPACE_VCSN_END
00339 
00340 #endif 

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