diff --git a/examples/server/server.c b/examples/server/server.c index bc4591b64..896d4760a 100644 --- a/examples/server/server.c +++ b/examples/server/server.c @@ -484,9 +484,7 @@ THREAD_RETURN CYASSL_THREAD server_test(void* args) int resume = 0; int resumeCount = 0; int loops = 1; -#ifdef WOLFSSL_FUNC_TIME int cnt = 0; -#endif int echoData = 0; int block = TEST_BUFFER_SIZE; int throughput = 0; @@ -1641,15 +1639,14 @@ THREAD_RETURN CYASSL_THREAD server_test(void* args) } resumeCount = 0; -#ifdef WOLFSSL_FUNC_TIME cnt++; -#endif if (loops > 0 && --loops == 0) { break; /* out of while loop, done with normal and resume option */ } } /* while(1) */ WOLFSSL_TIME(cnt); + (void)cnt; #if defined(HAVE_CERTIFICATE_STATUS_REQUEST) \ || defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2) diff --git a/wolfcrypt/src/logging.c b/wolfcrypt/src/logging.c index d417a126c..0fdab2654 100644 --- a/wolfcrypt/src/logging.c +++ b/wolfcrypt/src/logging.c @@ -57,6 +57,10 @@ static struct wc_error_queue* wc_last_node; #endif #ifdef WOLFSSL_FUNC_TIME +/* WARNING: This code is only to be used for debugging performance. + * The code is not thread-safe. + * Do not use WOLFSSL_FUNC_TIME in production code. + */ static double wc_func_start[WC_FUNC_COUNT]; static double wc_func_time[WC_FUNC_COUNT] = { 0, }; static const char* wc_func_name[WC_FUNC_COUNT] = { @@ -94,52 +98,18 @@ static const char* wc_func_name[WC_FUNC_COUNT] = { "DoEarlyData", }; -#if defined(WOLFSSL_USER_CURRTIME) - extern double current_time(int reset); +#include -#elif defined(USE_WINDOWS_API) +/* WARNING: This function is not portable. */ +static INLINE double current_time(int reset) +{ + struct timeval tv; + gettimeofday(&tv, 0); + (void)reset; - #define WIN32_LEAN_AND_MEAN - #include - - static INLINE double current_time(int reset) - { - static int init = 0; - static LARGE_INTEGER freq; - - LARGE_INTEGER count; - - if (!init) { - QueryPerformanceFrequency(&freq); - init = 1; - } - - QueryPerformanceCounter(&count); - - (void)reset; - return (double)count.QuadPart / freq.QuadPart; - } - -#elif defined(WOLFSSL_TIRTOS) - extern double current_time(); -#else - -#if !defined(WOLFSSL_MDK_ARM) && !defined(WOLFSSL_KEIL_TCP_NET) && !defined(WOLFSSL_CHIBIOS) - #include - - static INLINE double current_time(int reset) - { - struct timeval tv; - gettimeofday(&tv, 0); - (void)reset; - - return (double)tv.tv_sec + (double)tv.tv_usec / 1000000; - } -#else - extern double current_time(int reset); -#endif -#endif /* USE_WINDOWS_API */ -#endif + return (double)tv.tv_sec + (double)tv.tv_usec / 1000000; +} +#endif /* WOLFSSL_FUNC_TIME */ #ifdef DEBUG_WOLFSSL @@ -182,6 +152,10 @@ void wolfSSL_Debugging_OFF(void) } #ifdef WOLFSSL_FUNC_TIME +/* WARNING: This code is only to be used for debugging performance. + * The code is not thread-safe. + * Do not use WOLFSSL_FUNC_TIME in production code. + */ void WOLFSSL_START(int funcNum) { double now = current_time(0) * 1000.0; diff --git a/wolfssl/wolfcrypt/logging.h b/wolfssl/wolfcrypt/logging.h index dc8e31902..cbff0fa64 100644 --- a/wolfssl/wolfcrypt/logging.h +++ b/wolfssl/wolfcrypt/logging.h @@ -46,6 +46,10 @@ enum wc_LogLevels { }; #ifdef WOLFSSL_FUNC_TIME +/* WARNING: This code is only to be used for debugging performance. + * The code is not thread-safe. + * Do not use WOLFSSL_FUNC_TIME in production code. + */ enum wc_FuncNum { WC_FUNC_CLIENT_HELLO_SEND = 0, WC_FUNC_CLIENT_HELLO_DO, @@ -113,6 +117,10 @@ WOLFSSL_API void wolfSSL_Debugging_OFF(void); #endif /* OPENSSL_EXTRA || DEBUG_WOLFSSL_VERBOSE */ #ifdef WOLFSSL_FUNC_TIME + /* WARNING: This code is only to be used for debugging performance. + * The code is not thread-safe. + * Do not use WOLFSSL_FUNC_TIME in production code. + */ WOLFSSL_API void WOLFSSL_START(int funcNum); WOLFSSL_API void WOLFSSL_END(int funcNum); WOLFSSL_API void WOLFSSL_TIME(int count);