Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 #ifndef PixelTimeFormatter_h
00009 #define PixelTimeFormatter_h
00010
00017 #include <iostream>
00018 #include <sstream>
00019 #include <string>
00020 #include <time.h>
00021 #include <sys/time.h>
00022 #include <cstdlib>
00023
00024 #define USE_TIMER_ 0
00025
00026 namespace pos{
00027 class PixelTimeFormatter
00028 {
00029 public:
00030
00031
00032 PixelTimeFormatter(std::string source )
00033 {
00034 if( !USE_TIMER_) return ;
00035 origin_ = source ;
00036 std::cout << "[PixelTimeFormatter::PixelTimeFormatter()]\t\t Time counter started for " << origin_ << std::endl ;
00037 startTime_ = getImSecTime() ;
00038 }
00039
00040 void stopTimer(void)
00041 {
00042 if( !USE_TIMER_ ) return ;
00043 endTime_ = getImSecTime() ;
00044 double start = startTime_.tv_sec + startTime_.tv_usec/1000000. ;
00045 double stop = endTime_.tv_sec + endTime_.tv_usec/1000000. ;
00046 std::cout << "[PixelTimeFormatter::stopTimer()]\t\t\t Elapsed time: " << stop-start << " seconds for " << origin_ << std::endl ;
00047 }
00048
00049
00050 static std::string getTime(void)
00051 {
00052 char theDate[20] ;
00053 struct tm *thisTime;
00054 time_t aclock;
00055 std::string date ;
00056 time( &aclock );
00057 thisTime = localtime( &aclock );
00058
00059 sprintf(theDate,
00060 "%d-%02d-%02d %02d:%02d:%02d", thisTime->tm_year+1900,
00061 thisTime->tm_mon+1,
00062 thisTime->tm_mday,
00063 thisTime->tm_hour,
00064 thisTime->tm_min,
00065 thisTime->tm_sec );
00066 date = theDate ;
00067
00068 return date ;
00069 }
00070
00071
00072 struct tm * getITime(void)
00073 {
00074 struct tm *thisTime;
00075 time_t aclock;
00076 time( &aclock );
00077 thisTime = localtime( &aclock );
00078 return thisTime ;
00079 }
00080
00081
00082 static std::string getmSecTime(void)
00083 {
00084 char theDate[20] ;
00085 struct timeval msecTime;
00086 gettimeofday(&msecTime, (struct timezone *)0) ;
00087
00088 sprintf(theDate,
00089 "%d-%d",
00090 (unsigned int)msecTime.tv_sec,
00091 (unsigned int)msecTime.tv_usec );
00092 return std::string(theDate) ;
00093 }
00094
00095
00096 struct timeval getImSecTime(void)
00097 {
00098 struct timeval msecTime;
00099 gettimeofday(&msecTime, (struct timezone *)0) ;
00100
00101 return msecTime ;
00102 }
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137 private:
00138
00139 struct timeval startTime_ ;
00140 struct timeval endTime_ ;
00141 std::string origin_ ;
00142 bool verbose_ ;
00143 } ;
00144 }
00145
00146 #endif