From 3421863c0122e1287f94e588505d318ec3e0c5bb Mon Sep 17 00:00:00 2001 From: Dick Hollenbeck Date: Fri, 13 Jan 2012 03:46:02 -0600 Subject: [PATCH] add GetRunningMicroSecs() to libcommon for debug timing --- CMakeModules/PerformFeatureChecks.cmake | 10 +++- CMakeModules/config.h.cmake | 3 ++ common/CMakeLists.txt | 1 + common/getrunningmicrosecs.cpp | 62 +++++++++++++++++++++++++ container_test.cpp | 18 +------ include/common.h | 8 ++++ pcbnew/kicad_plugin.cpp | 10 +--- 7 files changed, 85 insertions(+), 27 deletions(-) create mode 100644 common/getrunningmicrosecs.cpp diff --git a/CMakeModules/PerformFeatureChecks.cmake b/CMakeModules/PerformFeatureChecks.cmake index 8ae0e5af8d..16c989983d 100644 --- a/CMakeModules/PerformFeatureChecks.cmake +++ b/CMakeModules/PerformFeatureChecks.cmake @@ -39,6 +39,9 @@ macro(perform_feature_checks) include(CheckIncludeFile) + #include(CheckFunctionExists) + include(CheckLibraryExists) + include(CheckSymbolExists) check_include_file("malloc.h" HAVE_MALLOC_H) @@ -55,7 +58,6 @@ macro(perform_feature_checks) # re-introduce this. # check_include_file("strings.h" HAVE_STRINGS_H) - include(CheckSymbolExists) check_symbol_exists(strcasecmp "string.h" HAVE_STRCASECMP) check_symbol_exists(strcasecmp "strings.h" HAVE_STRCASECMP) check_symbol_exists(strncasecmp "string.h" HAVE_STRNCASECMP) @@ -70,6 +72,12 @@ macro(perform_feature_checks) check_symbol_exists(_snprintf "stdio.h" HAVE_ISO_SNPRINTF) check_symbol_exists(_hypot "math.h" HAVE_ISO_HYPOT) + #check_symbol_exists(clock_gettime "time.h" HAVE_CLOCK_GETTIME) non-standard library, does not work + check_library_exists(rt clock_gettime "" HAVE_CLOCK_GETTIME) + + # HAVE_GETTIMEOFDAY is already in use within 2.9 wxWidgets, so use HAVE_GETTIMEOFDAY_FUNC + check_symbol_exists(gettimeofday "sys/time.h" HAVE_GETTIMEOFDAY_FUNC) + # Generate config.h. configure_file(${PROJECT_SOURCE_DIR}/CMakeModules/config.h.cmake ${CMAKE_BINARY_DIR}/config.h) diff --git a/CMakeModules/config.h.cmake b/CMakeModules/config.h.cmake index c9cab8778d..ef7612b74e 100644 --- a/CMakeModules/config.h.cmake +++ b/CMakeModules/config.h.cmake @@ -23,6 +23,9 @@ #define hypot _hypot #endif +#cmakedefine HAVE_CLOCK_GETTIME +#cmakedefine HAVE_GETTIMEOFDAY_FUNC + #cmakedefine MALLOC_IN_STDLIB_H #if !defined( MALLOC_IN_STDLIB_H ) diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index a293a12363..3c85d350a2 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -54,6 +54,7 @@ set(COMMON_SRCS eda_doc.cpp filter_reader.cpp gestfich.cpp + getrunningmicrosecs.cpp gr_basic.cpp hotkeys_basic.cpp hotkey_grid_table.cpp diff --git a/common/getrunningmicrosecs.cpp b/common/getrunningmicrosecs.cpp new file mode 100644 index 0000000000..895b2bc26d --- /dev/null +++ b/common/getrunningmicrosecs.cpp @@ -0,0 +1,62 @@ + +#include + + +#if defined(HAVE_CLOCK_GETTIME) + +#include + +unsigned GetRunningMicroSecs() +{ + struct timespec now; + + clock_gettime( CLOCK_MONOTONIC, &now ); + + unsigned usecs = ((unsigned)now.tv_nsec)/1000 + ((unsigned)now.tv_sec) * 1000000; +// unsigned msecs = (now.tv_nsec / (1000*1000)) + now.tv_sec * 1000; + + return usecs; +} + + +#elif defined(HAVE_GETTIMEOFDAY_FUNC) + +#include +unsigned GetRunningMicroSecs() +{ + timeval tv; + + gettimeofday( &tv, 0 ); + + return (tv.tv_sec * 1000000) + tv.tv_usec; +} + + +#elif defined(_WIN32) + +#define WIN32_LEAN_AND_MEAN 1 +#include +#include + +unsigned GetRunningMicroSecs() +{ + LARGE_INTEGER curtime; + + static unsigned timerFreq; // timer frequency + + if( !timerFreq ) + { + QueryPerformanceFrequency( &curtime ); + + timerFreq = curtime.QuadPart / 1000000; // i.e., ticks per usec + + assert( timerFreq ); + } + + QueryPerformanceCounter( &curtime ); + + return ( curtime.LowPart / timerFreq ); +} + +#endif + diff --git a/container_test.cpp b/container_test.cpp index cec4cea43c..f817325522 100644 --- a/container_test.cpp +++ b/container_test.cpp @@ -4,7 +4,7 @@ #include #include #include - +#include #define TEST_NODES 100000000 @@ -16,22 +16,6 @@ typedef boost::ptr_vector EDA_ITEMV; void heap_warm_up(); - -/** - * Function GetRunningMicroSecs - * returns current relative time in microsecs. - */ -unsigned GetRunningMicroSecs() -{ - struct timespec now; - - clock_gettime( CLOCK_MONOTONIC, &now ); - - unsigned usecs = now.tv_nsec/1000 + now.tv_sec * 1000 * 1000; - return usecs; -} - - int main( int argc, char** argv ) { EDA_ITEMV v; diff --git a/include/common.h b/include/common.h index f9fe9e82d9..0f9817c980 100644 --- a/include/common.h +++ b/include/common.h @@ -506,4 +506,12 @@ int From_User_Unit( EDA_UNITS_T aUnit, double val, int internal_unit_value ); */ wxString GenDate(); +/** + * Function GetRunningMicroSecs + * returns an ever increasing indication of elapsed microseconds. Use this + * by computing differences between two calls. + * @author Dick Hollenbeck + */ +unsigned GetRunningMicroSecs(); + #endif // INCLUDE__COMMON_H_ diff --git a/pcbnew/kicad_plugin.cpp b/pcbnew/kicad_plugin.cpp index e1061d4638..f94ccdd634 100644 --- a/pcbnew/kicad_plugin.cpp +++ b/pcbnew/kicad_plugin.cpp @@ -60,7 +60,6 @@ #include #include #include -//#include #include #ifdef CVPCB @@ -256,13 +255,11 @@ void KICAD_PLUGIN::loadAllSections( bool doAppend ) loadPCB_TARGET(); } -#if defined(PCBNEW) else if( TESTLINE( "$ZONE" ) ) { SEGZONE* insertBeforeMe = doAppend ? NULL : m_board->m_Zone.GetFirst(); loadTrackList( insertBeforeMe, PCB_ZONE_T ); } -#endif else if( TESTLINE( "$GENERAL" ) ) { @@ -568,8 +565,6 @@ void KICAD_PLUGIN::loadSETUP() m_board->SetOriginAxisPosition( wxPoint( gx, gy ) ); } -#if 1 // defined(PCBNEW) - else if( TESTLINE( "Layers" ) ) { int tmp = intParse( line + SZ( "Layers" ) ); @@ -786,7 +781,6 @@ void KICAD_PLUGIN::loadSETUP() GetScreen()->m_GridOrigin.y = Oy; */ } -#endif else if( TESTLINE( "$EndSETUP" ) ) { @@ -2846,9 +2840,7 @@ void KICAD_PLUGIN::saveSETUP() const } */ - /* @todo no aFrame in a plugin - fprintf( m_fp, "AuxiliaryAxisOrg %s\n", fmtBIUPoint( aFrame->GetOriginAxisPosition() ).c_str() ); - */ + fprintf( m_fp, "AuxiliaryAxisOrg %s\n", fmtBIUPoint( m_board->GetOriginAxisPosition() ).c_str() ); /* @todo no globals {