Teuchos_CTimeMonitor.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "Teuchos_CTimeMonitor.h"
00030 #include "Teuchos_TimeMonitor.hpp"
00031 #include "Teuchos_implicit_cast.hpp"
00032
00033 namespace {
00034
00035 typedef Teuchos::Array< Teuchos::RCP<Teuchos::Time> > TimerArray_t;
00036 TimerArray_t timerArray;
00037
00038 }
00039
00040
00041 int Teuchos_startTimer( char timerName[], int timerID )
00042 {
00043 using Teuchos::implicit_cast;
00044 if( timerID < 0 ) {
00045
00046 timerArray.push_back(Teuchos::TimeMonitor::getNewTimer(timerName));
00047 timerArray.back()->start();
00048 return timerArray.size()-1;
00049 }
00050
00051 TEST_FOR_EXCEPTION(
00052 timerID >= implicit_cast<int>(timerArray.size()), std::logic_error,
00053 "Teuchos_startTimer(...): Error, timerID="<<timerID
00054 <<" is >= timerArray.size()="<<timerArray.size()
00055 <<" for timerName=\""<<timerName<<"\"!"
00056 );
00057 Teuchos::RCP<Teuchos::Time> timer = timerArray[timerID];
00058 TEST_FOR_EXCEPTION(
00059 timer->isRunning(), std::logic_error,
00060 "Teuchos_startTimer(...): Error, timerID="<<timerID
00061 <<", timerName=\""<<timerName<<"\" is already running!"
00062 );
00063 timer->start();
00064 return timerID;
00065 }
00066
00067
00068 void Teuchos_stopTimer( int timerID )
00069 {
00070 using Teuchos::implicit_cast;
00071 TEST_FOR_EXCEPTION(
00072 timerID < 0 || timerID >= implicit_cast<int>(timerArray.size()),
00073 std::logic_error,
00074 "Teuchos_stopTimer(...): Error, timerID="<<timerID<<" is invalid!"
00075 );
00076 Teuchos::RCP<Teuchos::Time> timer = timerArray[timerID];
00077 timer->stop();
00078
00079 timer->incrementNumCalls();
00080 }