Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   Related Pages  

timing.cc

00001 /*
00002  * Copyright 2003 Michael A. Marsh, Cornell University. All rights reserved.
00003  * This software is released under the modified BSD license.
00004  * See the file LICENSE in the top-level directory for details.
00005  */
00006 //
00007 // $Id: timing.cc,v 1.3 2004/05/19 15:56:46 mmarsh Exp $
00008 //
00009 // $Log: timing.cc,v $
00010 // Revision 1.3  2004/05/19 15:56:46  mmarsh
00011 // *** empty log message ***
00012 //
00013 // Revision 1.2  2003/11/04 22:31:47  mmarsh
00014 // *** empty log message ***
00015 //
00016 //
00017 
00018 #ifdef TIMING
00019 
00020 // Defining TIMING_IMPL will cause timing.h to define all of the structs
00021 // as globals.  By default, timing.h prepends "extern" to each declaration.
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 //   struct timeval tv;
00049 //   gettimeofday(&tv,0);
00050    struct timeval dummy;
00051    getrusage(RUSAGE_SELF,&ru);
00052 //   m_timings.push_back( Vector::value_type( tv, dummy ) );
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 //   gettimeofday(&(m_timings.back().second), 0);
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 /* TIMING */

Generated on Wed Jun 2 16:32:56 2004 for COrnell Data EXchange (CODEX) by doxygen1.2.18