00001 //###################################################################### 00002 // 00003 // GraspIt! 00004 // Copyright (C) 2002-2009 Columbia University in the City of New York. 00005 // All rights reserved. 00006 // 00007 // GraspIt! is free software: you can redistribute it and/or modify 00008 // it under the terms of the GNU General Public License as published by 00009 // the Free Software Foundation, either version 3 of the License, or 00010 // (at your option) any later version. 00011 // 00012 // GraspIt! is distributed in the hope that it will be useful, 00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 // GNU General Public License for more details. 00016 // 00017 // You should have received a copy of the GNU General Public License 00018 // along with GraspIt!. If not, see <http://www.gnu.org/licenses/>. 00019 // 00020 // Author(s): Matei T. Ciocarlie 00021 // 00022 // $Id: profiling.cpp,v 1.6.4.1 2009/07/23 21:18:02 cmatei Exp $ 00023 // 00024 //###################################################################### 00025 00040 // ------------------------------------------- WINDOWS ----------------------------------------------- 00041 00042 #ifdef WIN32 00043 00044 #define NOMINMAX 00045 #include <windows.h> 00046 #undef NOMINMAX 00047 00048 #define PROF_TIME_UNIT unsigned __int64 00049 #define PROF_DURATION_UNIT unsigned __int64 00050 #define PROF_RESET_DURATION(DURATION) DURATION=0; 00051 #define PROF_ADD_DURATION(DURATION, START_TIME, END_TIME) DURATION += END_TIME - START_TIME; 00052 00053 // Gets time in the highest resolution available to the CPU, about a nanosecond 00054 #define PROF_GET_TIME(TIME) LARGE_INTEGER tmp; \ 00055 QueryPerformanceCounter(&tmp); \ 00056 TIME = tmp.QuadPart; 00057 #define PROF_CONVERT_TO_MICROS(DURATION,DOUBLE) DOUBLE = 1.0e6 * ((double)DURATION) / getProfiler().getCountsPerSec(); 00058 00059 /* 00060 // Gets time in units of 100 nanoseconds as 2 4-byte words 00061 #define PROF_GET_TIME(TIME) FILETIME tmp; \ 00062 GetSystemTimeAsFileTime(&tmp); \ 00063 TIME = (static_cast<unsigned __int64>(tmp.dwHighDateTime) << 32) | tmp.dwLowDateTime; 00064 #define PROF_CONVERT_TO_MICROS(DURATION, DOUBLE) DOUBLE = 0.1 * DURATION; 00065 */ 00066 00067 // -------------------------------------------------------------------------------------------------- 00068 #else 00069 // -------------------------------------------- LINUX ----------------------------------------------- 00070 00071 00072 //high-res version (microsecond) 00073 #include <sys/time.h> 00074 #include <sys/types.h> 00075 00076 #define PROF_TIME_UNIT struct timeval 00077 #define PROF_DURATION_UNIT struct timeval 00078 #define PROF_RESET_DURATION(DURATION) DURATION.tv_sec = DURATION.tv_usec = 0; 00079 #define PROF_GET_TIME(TIME) gettimeofday(&TIME, NULL); 00080 #define PROF_ADD_DURATION(DURATION,START,END) \ 00081 if (END.tv_usec < START.tv_usec) { \ 00082 int nsec = (START.tv_usec - END.tv_usec) / 1000000 + 1; \ 00083 START.tv_usec -= 1000000 * nsec; \ 00084 START.tv_sec += nsec; \ 00085 } \ 00086 if (END.tv_usec - START.tv_usec > 1000000) { \ 00087 int nsec = (END.tv_usec - START.tv_usec) / 1000000; \ 00088 START.tv_usec += 1000000 * nsec; \ 00089 START.tv_sec -= nsec; \ 00090 } \ 00091 DURATION.tv_sec += END.tv_sec - START.tv_sec; \ 00092 DURATION.tv_usec += END.tv_usec - START.tv_usec; 00093 #define PROF_CONVERT_TO_MICROS(DURATION,DOUBLE) DOUBLE = 1.0e6 * DURATION.tv_sec + DURATION.tv_usec; 00094 00095 /* 00096 //version WITH ONLY ONE SECOND RESOLUTION 00097 #include <ctime> 00098 #include <sys/types.h> 00099 00100 #define PROF_TIME_UNIT u_int64_t 00101 #define PROF_DURATION_UNIT u_int64_t 00102 #define PROF_RESET_DURATION(STR) STR = 0; 00103 #define PROF_GET_TIME(STR) STR = time(NULL); 00104 #define PROF_ADD_DURATION(DURATION,START,END) DURATION += END - START; 00105 #define PROF_CONVERT_TO_DOUBLE(DURATION,DOUBLE) DOUBLE = 1.0e6 * DURATION; 00106 */ 00107 #endif