Changeset 8e24ef
- Timestamp:
- Apr 2, 2011, 12:20:10 AM (15 years ago)
- Children:
- bbd746
- Parents:
- 93abe8
- git-author:
- Frederik Heber <heber@…> (03/15/11 09:53:34)
- git-committer:
- Frederik Heber <heber@…> (04/02/11 00:20:10)
- Files:
-
- 5 edited
-
configure.ac (modified) (3 diffs)
-
src/Helpers/Chronos.cpp (modified) (4 diffs)
-
src/Helpers/Chronos.hpp (modified) (4 diffs)
-
src/Helpers/Info.cpp (modified) (2 diffs)
-
src/unittests/ChronosUnitTest.cpp (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
configure.ac
r93abe8 r8e24ef 3 3 4 4 AC_PREREQ([2.65]) 5 AC_INIT([CodePatterns], [1. 0.13], [heber@ins.uni-bonn.de], [codepatterns], [http://trac.ins.uni-bonn.de/projects/CodePatterns/])5 AC_INIT([CodePatterns], [1.1.0], [heber@ins.uni-bonn.de], [codepatterns], [http://trac.ins.uni-bonn.de/projects/CodePatterns/]) 6 6 AC_CONFIG_AUX_DIR(config) 7 7 AC_CONFIG_SRCDIR([src/Patterns/Singleton_impl.hpp]) … … 25 25 # refer to the libtool manual, section "Updating library version information": 26 26 # http://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html 27 AC_SUBST([CODEPATTERNS_SO_VERSION], [ 6:0:1])28 AC_SUBST([CODEPATTERNS_API_VERSION], [1. 0.13])27 AC_SUBST([CODEPATTERNS_SO_VERSION], [7:0:0]) 28 AC_SUBST([CODEPATTERNS_API_VERSION], [1.1.0]) 29 29 30 30 # Checks for libraries. … … 41 41 AC_C_INLINE 42 42 AC_TYPE_SIZE_T 43 AC_CHECK_HEADERS([sys/times.h]) 43 44 44 45 # Checks for library functions. -
src/Helpers/Chronos.cpp
r93abe8 r8e24ef 22 22 #include <iostream> 23 23 24 #ifdef HAVE_SYS_TIMES_H 25 # include <sys/times.h> 26 #else 27 # include <time.h> 28 #endif 29 24 30 #include "Chronos.hpp" 25 31 … … 32 38 {} 33 39 34 intChronos::getTime(const std::string _name) const40 double Chronos::getTime(const std::string _name) const 35 41 { 36 42 // only those functions have a time that have run already 37 if ( IsTimeRunning.count(_name)) {43 if (TimeRunning.count(_name)) { 38 44 // return -1 if function is currently running 39 if ( !IsTimeRunning.count(_name))45 if (TimeRunning.count(_name) != 0.) 40 46 return AccountedTime.at(_name); 41 47 else 42 return -1 ;48 return -1.; 43 49 } 44 return 0 ;50 return 0.; 45 51 } 46 52 47 53 void Chronos::resetTime(const std::string _name) 48 54 { 49 if ( IsTimeRunning.count(_name)) {50 AccountedTime[_name] = 0 ;55 if (TimeRunning.count(_name)) { 56 AccountedTime[_name] = 0.; 51 57 } 52 58 } … … 55 61 { 56 62 // start time keeping 57 IsTimeRunning[_name] = true; 63 TimeRunning[_name] = getCurrentTime(); 64 } 65 66 double Chronos::getCurrentTime() const 67 { 68 #ifdef HAVE_SYS_TIMES_H 69 struct tms *buffer = new tms; 70 double currenttime; 71 if (times(buffer) != (clock_t)(-1)) 72 currenttime = ((double)buffer->tms_utime/(double)CLOCKS_PER_SEC); 73 else 74 currenttime = 0.; 75 delete buffer; 76 #else 77 const double currenttime = (clock()/(double)CLOCKS_PER_SEC); 78 #endif 79 //std::cout << "Current time is " << currenttime << std::endl; 80 return currenttime; 58 81 } 59 82 60 83 void Chronos::endTiming(const std::string _name) 61 84 { 62 // finish time keeping if present 63 ASSERT(IsTimeRunning.count(_name), "Chronos::endTiming() - no timer under "+_name+" running."); 64 IsTimeRunning[_name] = false; 85 const double endtime = getCurrentTime(); 86 const double starttime = TimeRunning[_name]; 87 88 // if present 89 ASSERT(TimeRunning.count(_name), "Chronos::endTiming() - no timer under "+_name+" running."); 90 // finish time keeping 91 const double RunTime = ((double)endtime - starttime); 92 TimekeepingMap::iterator iter = AccountedTime.find(_name); 93 if (iter != AccountedTime.end()) 94 AccountedTime[_name] += RunTime; 95 else 96 AccountedTime[_name] = RunTime; 97 98 // and zero for next run 99 TimeRunning[_name] = 0.; 65 100 } 66 101 67 intChronos::SumUpTotalTime() const102 double Chronos::SumUpTotalTime() const 68 103 { 69 int sum = 0;104 double sum = 0.; 70 105 for (TimekeepingMap::const_iterator iter = AccountedTime.begin(); 71 106 iter != AccountedTime.end(); … … 78 113 size_t Chronos::SumUpTotalFunctions() const 79 114 { 80 return IsTimeRunning.size();115 return TimeRunning.size(); 81 116 } 82 117 83 118 std::ostream& operator<<(std::ostream &ost, const Chronos &_time) 84 119 { 85 int sum = _time.SumUpTotalTime(); 86 ost << "Total time passed: " << sum << std::endl; 120 ost << "List of functions present:" << std::endl; 121 for (Chronos::TimekeepingMap::const_iterator iter = _time.AccountedTime.begin(); 122 iter != _time.AccountedTime.end(); 123 ++iter) 124 ost << "\t" << iter->first << "\t" << iter->second << "s" << std::endl; 125 ost << "Total time passed: " << _time.SumUpTotalTime() << std::endl; 87 126 ost << "Total functions: " << _time.SumUpTotalFunctions() << std::endl; 88 89 127 return ost; 90 128 } 91 129 130 // construct the remainder of the singleton 131 CONSTRUCT_SINGLETON(Chronos) 92 132 93 CONSTRUCT_SINGLETON(Chronos) 133 // catch if someone wants to use Info objects in here 134 #ifdef INFO_HPP_ 135 BOOST_PP_ASSERT_MSG(1,\ 136 ERROR: This is a safety measure to generate a compiler warning\n \ 137 if you really try to use info.hpp in __FILE__.) 138 #endif 139 -
src/Helpers/Chronos.hpp
r93abe8 r8e24ef 26 26 //!> unit tests needs access to private members 27 27 friend class ChronosTest; 28 //!> operator needs to access some internals 29 friend std::ostream& operator<<(std::ostream &ost, const Chronos &_time); 28 30 public : 29 31 … … 33 35 * @return current amount of time passed for this function, 0 if unknown, -1 if currently running 34 36 */ 35 intgetTime(const std::string _name) const;37 double getTime(const std::string _name) const; 36 38 37 39 /** Resets time counter for this function \a _name to zero. … … 55 57 /** Sums up total time accounted for. 56 58 * 57 * @return total time 59 * @return total time in seconds 58 60 */ 59 intSumUpTotalTime() const;61 double SumUpTotalTime() const; 60 62 61 63 /** Sums up all functions accounted. … … 72 74 73 75 private: 76 /** Returns the current timer in seconds. 77 * 78 * This function is present to allow for changing of time measurements 79 * without the other functions noticing. 80 * 81 * \note We convert clock() by CLOCKS_PER_SEC. 82 * 83 * @return current time in unit of seconds 84 */ 85 double getCurrentTime() const; 74 86 75 typedef std::map<const std::string, int> TimekeepingMap; 76 typedef std::map<const std::string, bool> TimerStatusMap; 87 88 typedef std::map<const std::string, double> TimekeepingMap; 89 typedef std::map<const std::string, double> TimerStatusMap; 77 90 78 91 TimekeepingMap AccountedTime; 79 TimerStatusMap IsTimeRunning;92 TimerStatusMap TimeRunning; 80 93 }; 81 94 -
src/Helpers/Info.cpp
r93abe8 r8e24ef 39 39 { 40 40 verbosity++; 41 DoLog(0) && (Log() << Verbose(0) << "Begin of " << FunctionName << endl);41 LOG(0, "INFO: Begin of "+FunctionName); 42 42 43 43 // one more info object … … 62 62 63 63 // verbosity stuff 64 DoLog(0) && (Log() << Verbose(0) << "End of " << FunctionName << endl);64 LOG(0, "INFO: End of "+FunctionName); 65 65 verbosity--; 66 66 -
src/unittests/ChronosUnitTest.cpp
r93abe8 r8e24ef 40 40 { 41 41 Info FunctionInfo(__func__); 42 for (int i=0;i<10000000;++i) 43 std::cout << ""; 42 44 } 43 45 … … 45 47 { 46 48 Info FunctionInfo(__func__); 49 for (int i=0;i<1000000;++i) 50 std::cout << ""; 47 51 } 48 52 … … 80 84 void ChronosTest::dummyTest() 81 85 { 86 double timings[4]; 82 87 // first dummy 83 88 dummy(); 84 CPPUNIT_ASSERT( Chronos::getInstance(). IsTimeRunning.find(std::string("dummy"))85 != Chronos::getInstance(). IsTimeRunning.end() );89 CPPUNIT_ASSERT( Chronos::getInstance().TimeRunning.find(std::string("dummy")) 90 != Chronos::getInstance().TimeRunning.end() ); 86 91 CPPUNIT_ASSERT_EQUAL( (size_t) 1, Chronos::getInstance().SumUpTotalFunctions() ); 92 timings[0] = Chronos::getInstance().AccountedTime[std::string("dummy")]; 93 std::cout << "Timing[0]: " << timings[0] << std::endl; 94 CPPUNIT_ASSERT(timings[0] > 0.); 87 95 dummy(); 88 96 // second call goes to same entry 89 97 CPPUNIT_ASSERT_EQUAL( (size_t) 1, Chronos::getInstance().SumUpTotalFunctions() ); 98 timings[1] = Chronos::getInstance().AccountedTime[std::string("dummy")] - timings[0]; 99 std::cout << "Timing[1]: " << timings[1] << std::endl; 100 CPPUNIT_ASSERT(timings[1] > 0.); 101 90 102 91 103 // second dummy 92 104 dummy_two(); 93 CPPUNIT_ASSERT( Chronos::getInstance(). IsTimeRunning.find(std::string("dummy_two"))94 != Chronos::getInstance(). IsTimeRunning.end() );105 CPPUNIT_ASSERT( Chronos::getInstance().TimeRunning.find(std::string("dummy_two")) 106 != Chronos::getInstance().TimeRunning.end() ); 95 107 CPPUNIT_ASSERT_EQUAL( (size_t) 2, Chronos::getInstance().SumUpTotalFunctions() ); 108 timings[2] = Chronos::getInstance().AccountedTime[std::string("dummy_two")]; 109 std::cout << "Timing[2]: " << timings[2] << std::endl; 110 CPPUNIT_ASSERT(timings[2] > 0.); 111 112 // "inline" dummy 113 { 114 Info DummyInfo("dummy_three"); 115 for (int i=0;i<1000000;++i) 116 std::cout << ""; 117 } 118 CPPUNIT_ASSERT( Chronos::getInstance().TimeRunning.find(std::string("dummy_three")) 119 != Chronos::getInstance().TimeRunning.end() ); 120 CPPUNIT_ASSERT_EQUAL( (size_t) 3, Chronos::getInstance().SumUpTotalFunctions() ); 121 timings[3] = Chronos::getInstance().AccountedTime[std::string("dummy_three")]; 122 std::cout << "Timing[3]: " << timings[3] << std::endl; 123 CPPUNIT_ASSERT(timings[3] > 0.); 124 125 // check summing of times 126 CPPUNIT_ASSERT_EQUAL( timings[0] + timings[1] + timings[2] + timings[3], Chronos::getInstance().SumUpTotalTime()); 127 128 std::cout << Chronos::getInstance() << std::endl; 96 129 }
Note:
See TracChangeset
for help on using the changeset viewer.
