Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "timeutil.h"
00018 #include <iostream>
00019
00020 #ifdef _WINDOWS
00021 #include <time.h>
00022 #include <windows.h>
00023 #endif
00024
00025 namespace g2o {
00026
00027 #ifdef _WINDOWS
00028 #if defined(_MSC_VER) || defined(_MSC_EXTENSIONS)
00029 #define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64
00030 #else
00031 #define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL
00032 #endif
00033
00034 struct timezone
00035 {
00036 int tz_minuteswest;
00037 int tz_dsttime;
00038 };
00039
00040 int gettimeofday(struct timeval *tv, struct timezone *tz)
00041 {
00042
00043 FILETIME ft;
00044
00045
00046 unsigned __int64 tmpres = 0;
00047 static int tzflag = 0;
00048
00049 if (NULL != tv)
00050 {
00051 GetSystemTimeAsFileTime(&ft);
00052
00053
00054
00055
00056 tmpres |= ft.dwHighDateTime;
00057 tmpres <<= 32;
00058 tmpres |= ft.dwLowDateTime;
00059
00060
00061 tmpres /= 10;
00062
00063
00064
00065 tmpres -= DELTA_EPOCH_IN_MICROSECS;
00066
00067
00068
00069 tv->tv_sec = (long)(tmpres / 1000000UL);
00070 tv->tv_usec = (long)(tmpres % 1000000UL);
00071 }
00072
00073 if (NULL != tz) {
00074 if (!tzflag) {
00075 _tzset();
00076 tzflag++;
00077 }
00078
00079 long sec;
00080 int hours;
00081 _get_timezone(&sec);
00082 _get_daylight(&hours);
00083
00084
00085 tz->tz_minuteswest = sec / 60;
00086 tz->tz_dsttime = hours;
00087 }
00088
00089 return 0;
00090 }
00091 #endif
00092
00093 ScopeTime::ScopeTime(const char* title) : _title(title), _startTime(get_time()) {}
00094
00095 ScopeTime::~ScopeTime() {
00096 std::cerr << _title<<" took "<<1000*(get_time()-_startTime)<<"ms.\n";
00097 }
00098
00099 }