00001 #ifndef MERCURYTIMER_H 00002 #define MERCURYTIMER_H 00003 00004 #include "global.h" 00005 #include <map> 00006 00007 int64_t GetMicrosecondsSinceEpoch(); 00008 00010 class MercuryTimer 00011 { 00012 public: 00013 MercuryTimer(); 00014 ~MercuryTimer(); 00016 double Peek(); 00018 double Age(); 00020 void Touch(); 00022 inline void Pause() { m_paused = !m_paused; } 00023 00024 MercuryTimer operator-(const MercuryTimer& t); 00025 MercuryTimer operator+(const MercuryTimer& t); 00026 void operator=(const MercuryTimer& t); 00027 private: 00028 uint64_t GetTimeMicroseconds(); 00029 int64_t FixupTimeIfLooped( int64_t usecs ); 00030 int64_t FixupTimeIfBackwards( int64_t usecs ); 00031 00032 long m_secs; 00033 long m_usecs; 00034 00035 double m_pTime; 00036 bool m_paused; 00037 }; 00038 00040 class MercuryTimerBenchmark 00041 { 00042 public: 00044 void Start( const MString & sName ); 00046 void End( const MString & sName ); 00047 void Print( ); 00048 private: 00050 struct BenchPoint 00051 { 00052 BenchPoint() { fTotalTime = 0; iTimesRun = 0; } 00053 float fTotalTime; 00054 int iTimesRun; 00055 MercuryTimer tTimer; 00056 }; 00057 std::map< MString, BenchPoint > m_mTotals; 00058 }; 00059 00060 extern MercuryTimerBenchmark BENCHMARK; 00061 00062 #endif 00063 00064 /* 00065 *Copyright (c) 2001-2003 Chris Danford, Glenn Maynard 00066 * (c) 2005 Joshua Allen 00067 * All rights reserved. 00068 * 00069 * Permission is hereby granted, free of charge, to any person obtaining a 00070 * copy of this software and associated documentation files (the 00071 * "Software"), to deal in the Software without restriction, including 00072 * without limitation the rights to use, copy, modify, merge, publish, 00073 * distribute, and/or sell copies of the Software, and to permit persons to 00074 * whom the Software is furnished to do so, provided that the above 00075 * copyright notice(s) and this permission notice appear in all copies of 00076 * the Software and that both the above copyright notice(s) and this 00077 * permission notice appear in supporting documentation. 00078 * 00079 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 00080 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00081 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF 00082 * THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS 00083 * INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT 00084 * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS 00085 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR 00086 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 00087 * PERFORMANCE OF THIS SOFTWARE. 00088 */