00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifdef TIMING
00019
00020
00021
00022 #define TIMING_IMPL
00023 #include "timing.h"
00024
00025 #include <iostream>
00026 #include <iomanip>
00027 #include <sys/resource.h>
00028
00029 void
00030 Timer::print( std::ostream& s ) const
00031 {
00032 Vector::const_iterator itr = m_timings.begin();
00033 Vector::const_iterator end = m_timings.end();
00034 for ( ; itr != end ; ++itr )
00035 {
00036 s << m_tag << " "
00037 << itr->first.tv_sec << " "
00038 << itr->first.tv_usec << " "
00039 << itr->second.tv_sec << " "
00040 << itr->second.tv_usec << std::endl;
00041 }
00042 }
00043
00044 void
00045 Timer::start()
00046 {
00047 struct rusage ru;
00048
00049
00050 struct timeval dummy;
00051 getrusage(RUSAGE_SELF,&ru);
00052
00053 m_timings.push_back( Vector::value_type( ru.ru_utime, dummy ) );
00054 }
00055
00056 void
00057 Timer::stop()
00058 {
00059 struct rusage ru;
00060 getrusage(RUSAGE_SELF,&ru);
00061
00062 m_timings.back().second.tv_sec = ru.ru_utime.tv_sec;
00063 m_timings.back().second.tv_usec = ru.ru_utime.tv_usec;
00064 }
00065
00066 void
00067 Timer::cancel()
00068 {
00069 m_timings.pop_back();
00070 }
00071
00072 template Timer::Pair;
00073
00074 #include "vector_macros.h"
00075 INSTANTIATE_VECTOR( Timer::Vector );
00076
00077 #endif