From: omy Date: Fri, 30 Nov 2012 12:17:28 +0000 (+0400) Subject: 0023237: OSD_PerfMeter reports wrong (zero) times X-Git-Tag: V6_6_0_beta~201 X-Git-Url: http://git.dev.opencascade.org/gitweb/?a=commitdiff_plain;h=c2ae831c12056122f8d4ee2f7aab8aace0afe822;p=occt-copy.git 0023237: OSD_PerfMeter reports wrong (zero) times Commit details: 1) in OSD_PerfMeter, use static functions of OSD_Chronometer class for time measurements instead of specific code to avoid incorrect results on CentOS (due to wrong valus of CLK_TCK); 2) changed definition of OSD_PerfMeter from .c to .cxx to avoid problems with C-functions; 3) fixed OSD_PerfMeter.h for building on Unix systems; 4) removed platform-specific #defines; 5) added test case for OSD_PerfMeter as bugs fclasses bug23237; 6) Removed DebugTools package (duplicates OSD_PerfMeter) 7) Avoid compiler (GCC) error casting BRepPrimAPI_Make* instances to TopoDS_Shape --- diff --git a/src/DebugTools/DebugTools.h b/src/DebugTools/DebugTools.h deleted file mode 100755 index 878ccfeaa3..0000000000 --- a/src/DebugTools/DebugTools.h +++ /dev/null @@ -1,93 +0,0 @@ -/* - Copyright (c) 1999-2012 OPEN CASCADE SAS - - The content of this file is subject to the Open CASCADE Technology Public - License Version 6.5 (the "License"). You may not use the content of this file - except in compliance with the License. Please obtain a copy of the License - at http://www.opencascade.org and read it completely before using this file. - - The Initial Developer of the Original Code is Open CASCADE S.A.S., having its - main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. - - The Original Code and all software distributed under the License is - distributed on an "AS IS" basis, without warranty of any kind, and the - Initial Developer hereby disclaims all such warranties, including without - limitation, any warranties of merchantability, fitness for a particular - purpose or non-infringement. Please see the License for the specific terms - and conditions governing the rights and limitations under the License. - -*/ - -#ifndef _DEBUGTOOLS_H -#define _DEBUGTOOLS_H - -#ifndef Standard_EXPORT -#ifdef WNT -#define Standard_EXPORT __declspec( dllexport ) -#else -#define Standard_EXPORT extern -#endif -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -Standard_EXPORT int perf_init_meter (const char * const MeterName); -Standard_EXPORT int perf_tick_meter (const char * const MeterName); -Standard_EXPORT int perf_tick_imeter (const int iMeter); -Standard_EXPORT int perf_start_meter (const char * const MeterName); -Standard_EXPORT int perf_start_imeter (const int iMeter); -Standard_EXPORT int perf_stop_meter (const char * const MeterName); -Standard_EXPORT int perf_stop_imeter (const int iMeter); -Standard_EXPORT int perf_get_meter (const char * const MeterName, - int * nb_enter, - double * seconds); -Standard_EXPORT void perf_close_meter (const char * const MeterName); -Standard_EXPORT void perf_print_all_meters (void); -Standard_EXPORT void perf_destroy_all_meters (void); - -#ifdef __cplusplus -} -#endif - -#ifdef PERF_ENABLE_METERS -#define PERF_TICK_METER(_m_name) { \ - static int __iMeter = 0; \ - if (__iMeter) perf_tick_imeter (__iMeter); \ - else __iMeter = perf_tick_meter (_m_name); \ -} - -#define PERF_START_METER(_m_name) { \ - static int __iMeter = 0; \ - if (__iMeter) perf_start_imeter (__iMeter); \ - else __iMeter = perf_start_meter (_m_name); \ -} - -#define PERF_STOP_METER(_m_name) { \ - static int __iMeter = 0; \ - if (__iMeter) perf_stop_imeter (__iMeter); \ - else __iMeter = perf_stop_meter (_m_name); \ -} - -#define PERF_CLOSE_METER(_m_name) perf_close_meter (_m_name); - -#define PERF_PRINT_ALL { \ - perf_print_all_meters(); \ -} - -#define PERF_PRINT_ALL_METERS { \ - perf_print_all_meters(); \ - perf_destroy_all_meters(); \ -} - -#else -#define PERF_TICK_METER(_m_name) -#define PERF_START_METER(_m_name) -#define PERF_STOP_METER(_m_name) -#define PERF_CLOSE_METER(_m_name) -#define PERF_PRINT_ALL -#define PERF_PRINT_ALL_METERS -#endif - -#endif diff --git a/src/DebugTools/FILES b/src/DebugTools/FILES deleted file mode 100755 index 0edd258bd6..0000000000 --- a/src/DebugTools/FILES +++ /dev/null @@ -1,2 +0,0 @@ -DebugTools.h -Perf.cxx diff --git a/src/DebugTools/Perf.cxx b/src/DebugTools/Perf.cxx deleted file mode 100755 index f20e90cebd..0000000000 --- a/src/DebugTools/Perf.cxx +++ /dev/null @@ -1,405 +0,0 @@ -// Copyright (c) 1999-2012 OPEN CASCADE SAS -// -// The content of this file is subject to the Open CASCADE Technology Public -// License Version 6.5 (the "License"). You may not use the content of this file -// except in compliance with the License. Please obtain a copy of the License -// at http://www.opencascade.org and read it completely before using this file. -// -// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its -// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. -// -// The Original Code and all software distributed under the License is -// distributed on an "AS IS" basis, without warranty of any kind, and the -// Initial Developer hereby disclaims all such warranties, including without -// limitation, any warranties of merchantability, fitness for a particular -// purpose or non-infringement. Please see the License for the specific terms -// and conditions governing the rights and limitations under the License. - -/*====================================================================== -File : Perf.c -Purpose : Set of functions to measure the CPU user time -Author : Michael SAZONOV -Created : 10/08/2000 -History : 25/09/2001 : AGV : (const char *) in prototypes; - search in table using hashvalue - 09/11/2001 : AGV : Add functions perf_*_imeter for performance - Add function perf_tick_meter -======================================================================*/ - -#include -#include -#include -#include -#include - -#ifndef WNT -#include -#endif - -/* Function times() is more precise than clock() because it does not take into - account the system time and the time of child processes */ -#include -#ifdef WNT -#define STRICT -#include -typedef __int64 PERF_TIME; -#define PICK_TIME(_utime) { \ - FILETIME t1, t2, ktime; \ - GetThreadTimes (GetCurrentThread(), &t1, &t2, &ktime, (FILETIME *)&(_utime));\ -} -#define GET_SECONDS(_utime) (((double)(_utime))/10000000.) -#else -#include -typedef clock_t PERF_TIME; -#define PICK_TIME(_utime) { \ - struct tms tmbuf; \ - times (&tmbuf); \ - (_utime) = tmbuf.tms_utime; \ -} - -#ifndef CLK_TCK -#define CLK_TCK 100 /* as SunOS */ -#endif - -#define GET_SECONDS(_utime) (((double)(_utime))/CLK_TCK) -#endif -/*====================================================================== - DEFINITIONS -======================================================================*/ - -typedef struct { - char* name; /* identifier */ - unsigned int hash; /* hash value */ - PERF_TIME cumul_time; /* cumulative time */ - PERF_TIME start_time; /* to store start time */ - int nb_enter; /* number of enters */ -} t_TimeCounter; - -#define MAX_METERS 100 - -static t_TimeCounter MeterTable[MAX_METERS]; -static int nb_meters = 0; - -static t_TimeCounter* find_meter (const char * const MeterName); -static t_TimeCounter* _perf_init_meter (const char * const MeterName, - const int doFind); -static unsigned int hash_value (const char * const aString); - -/*====================================================================== -Function : perf_init_meter -Purpose : Creates new counter (if it is absent) identified by - MeterName and resets its cumulative value -Returns : iMeter if OK, 0 if alloc problem -======================================================================*/ -int perf_init_meter (const char * const MeterName) -{ - t_TimeCounter* ptc = _perf_init_meter (MeterName, ~0); - return (ptc ? (ptc-MeterTable)+1 : 0); -} - -/*====================================================================== -Function : perf_tick_meter -Purpose : Increments the counter of meter MeterName without changing - its state with respect to measurement of time. - creates new meter if there is no such meter -Returns : iMeter if OK, 0 if no such meter and cannot create a new one -======================================================================*/ -int perf_tick_meter (const char * const MeterName) -{ - t_TimeCounter* ptc = find_meter (MeterName); - - if (!ptc) { - /* create new meter */ - ptc = _perf_init_meter (MeterName, 0); - } - - if (ptc) { - ptc -> nb_enter ++; - return (ptc-MeterTable) + 1; - } - return 0; -} - -/*====================================================================== -Function : perf_tick_imeter -Purpose : Increments the counter of meter iMeter without changing - its state with respect to measurement of time. -Returns : iMeter if OK, 0 if no such meter -======================================================================*/ -int perf_tick_imeter (const int iMeter) -{ - if (iMeter > 0 && iMeter <= nb_meters) { - MeterTable[iMeter-1].nb_enter ++; - return iMeter; - } - return 0; -} - -/*====================================================================== -Function : perf_start_meter -Purpose : Forces meter MeterName to begin to count by remembering - the current data of timer; - creates new meter if there is no such meter -Returns : iMeter if OK, 0 if no such meter and cannot create a new one -======================================================================*/ -int perf_start_meter (const char * const MeterName) -{ - t_TimeCounter* ptc = find_meter (MeterName); - - if (!ptc) { - /* create new meter */ - ptc = _perf_init_meter (MeterName, 0); - } - - if (ptc) { - PICK_TIME (ptc->start_time) - return (ptc - MeterTable) + 1; - } - - return 0; -} - -/*====================================================================== -Function : perf_start_imeter -Purpose : Forces meter with number iMeter to begin count by remembering - the current data of timer; - the meter must be previously created -Returns : iMeter if OK, 0 if no such meter -======================================================================*/ -int perf_start_imeter (const int iMeter) -{ - if (iMeter > 0 && iMeter <= nb_meters) { - t_TimeCounter * const ptc = &MeterTable[iMeter-1]; - PICK_TIME (ptc->start_time) - return iMeter; - } - return 0; -} - -/*====================================================================== -Function : perf_stop_meter -Purpose : Forces meter MeterName to stop and cumulate time elapsed - since start -Returns : 1 if OK, 0 if no such meter or it is has not been started -======================================================================*/ -int perf_stop_meter (const char * const MeterName) -{ - t_TimeCounter* ptc = find_meter (MeterName); - - if (ptc && ptc->start_time) { - PERF_TIME utime; - PICK_TIME (utime) - ptc->cumul_time += utime - ptc->start_time; - ptc->start_time = 0; - ptc->nb_enter++; - return (ptc-MeterTable) + 1; - } - - return 0; -} - -/*====================================================================== -Function : perf_stop_imeter -Purpose : Forces meter with number iMeter to stop and cumulate the time - elapsed since the start -Returns : iMeter if OK, 0 if no such meter -======================================================================*/ -int perf_stop_imeter (const int iMeter) -{ - if (iMeter > 0 && iMeter <= nb_meters) { - t_TimeCounter * const ptc = &MeterTable[iMeter-1]; - - if (ptc->start_time) { - PERF_TIME utime; - PICK_TIME (utime) - ptc->cumul_time += utime - ptc->start_time; - ptc->start_time = 0; - ptc->nb_enter++; - return iMeter; - } - } - return 0; -} - -/*====================================================================== -Function : perf_get_meter -Purpose : Tells the time cumulated by meter MeterName and the number - of enters to this meter -Output : *nb_enter, *seconds if the pointers != NULL -Returns : iMeter if OK, 0 if no such meter -======================================================================*/ -int perf_get_meter (const char * const MeterName, - int * nb_enter, - double * seconds) -{ - t_TimeCounter* ptc = find_meter (MeterName); - - if (!ptc) return 0; - - if (nb_enter) *nb_enter = ptc->nb_enter; - if (seconds) *seconds = GET_SECONDS(ptc->cumul_time); - return (ptc-MeterTable) + 1; -} - -/*====================================================================== -Function : perf_print_all_meters -Purpose : Prints on stdout the cumulated time and the number of - enters for each meter in MeterTable; - resets all meters -Output : none -Returns : none -======================================================================*/ -void perf_print_all_meters (void) -{ - int i; - - if (!nb_meters) return; - - printf (" Perf meter results : enters seconds enters/sec\n"); - - for (i=0; inb_enter) { - double secs = GET_SECONDS(ptc->cumul_time); - - if (ptc->start_time) - printf ("Warning : meter %s has not been stopped\n", ptc->name); - - printf ("%-40s : %7d %8.2f %10.2f\n", - ptc->name, ptc->nb_enter, secs, - (secs>0. ? ptc->nb_enter / secs : 0.)); - - ptc->cumul_time = 0; - ptc->start_time = 0; - ptc->nb_enter = 0; - } - } -} - -/*====================================================================== -Function : perf_close_meter -Purpose : Prints out a meter and resets it -Returns : none -======================================================================*/ -void perf_close_meter (const char * const MeterName) -{ - t_TimeCounter* ptc = find_meter (MeterName); - if (ptc && ptc->nb_enter) { - if (ptc->start_time) - printf (" ===> Warning : meter %s has not been stopped\n", ptc->name); - printf (" ===> [%s] : %d enters, %9.3f seconds\n", - ptc->name, ptc->nb_enter, GET_SECONDS(ptc->cumul_time)); - ptc->cumul_time = 0; - ptc->start_time = 0; - ptc->nb_enter = 0; - } -} - -/*====================================================================== -Function : perf_destroy_all_meters -Purpose : Deletes all meters and frees memory -Returns : none -======================================================================*/ -void perf_destroy_all_meters (void) -{ - int i; - for (i=0; i= MAX_METERS) return 0; - ptc = &MeterTable[nb_meters]; - - ptc -> name = strdup (MeterName); - if (!ptc -> name) - return 0; - - ptc -> hash = hash_value (MeterName); - nb_meters++; - } - - ptc->cumul_time = 0; - ptc->start_time = 0; - ptc->nb_enter = 0; - if (hasbeencalled == 0) { - /*atexit (perf_print_and_destroy);*/ - hasbeencalled = ~0; - } - return ptc; -} - -/*====================================================================== -Function : find_meter -Purpose : Finds the meter MeterName in the MeterTable -Returns : Pointer to meter object -Remarks : For internal use in this module -======================================================================*/ -static t_TimeCounter* find_meter (const char * const MeterName) -{ - int i; - const unsigned int aHash = hash_value (MeterName); - for (i=0; i 0; i--) { - const unsigned int bTmp = aCRC ^ (const unsigned int) (* aPtr++); - aCRC = ((aCRC >> 8) ^ wCRC16a[bTmp & 0x0F]) ^ wCRC16b[(bTmp >> 4) & 0x0F]; - } - return aCRC; -} diff --git a/src/OSD/FILES b/src/OSD/FILES index 3c20c771ba..8379d40671 100755 --- a/src/OSD/FILES +++ b/src/OSD/FILES @@ -15,9 +15,9 @@ OSD_WNT_BREAK.hxx OSD_signal.cxx OSD_signal_WNT.cxx OSD_ThreadFunction.hxx -OSD_PThread.hxx +OSD_PThread.hxx OSD_Localizer.cxx -OSD_PerfMeter.c +OSD_PerfMeter.cxx OSD_PerfMeter.h OSD_PerfMeter.hxx OSD_MAllocHook.cxx diff --git a/src/OSD/OSD_PerfMeter.c b/src/OSD/OSD_PerfMeter.c deleted file mode 100644 index be57c92e9a..0000000000 --- a/src/OSD/OSD_PerfMeter.c +++ /dev/null @@ -1,386 +0,0 @@ -/* - Created on: 2000-08-10 - Created by: Michael SAZONOV - Copyright (c) 2000-2012 OPEN CASCADE SAS - - The content of this file is subject to the Open CASCADE Technology Public - License Version 6.5 (the "License"). You may not use the content of this file - except in compliance with the License. Please obtain a copy of the License - at http://www.opencascade.org and read it completely before using this file. - - The Initial Developer of the Original Code is Open CASCADE S.A.S., having its - main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. - - The Original Code and all software distributed under the License is - distributed on an "AS IS" basis, without warranty of any kind, and the - Initial Developer hereby disclaims all such warranties, including without - limitation, any warranties of merchantability, fitness for a particular - purpose or non-infringement. Please see the License for the specific terms - and conditions governing the rights and limitations under the License. - -*/ - -/*====================================================================== -*/ -/*Purpose : Set of functions to measure the CPU user time -*/ -/*25/09/2001 : AGV : (const char *) in prototypes; -*/ -/*09/11/2001 : AGV : Add functions perf_*_imeter for performance -*/ -/*Add function perf_tick_meter -*/ -/*14/05/2002 : AGV : Portability UNIX/Windows -*/ -/*======================================================================*/ -#include -#include -#include -#include -#include -#include - -/* ------- Definitions for Windows compiler -------- */ -#ifdef WNT -#define STRICT -#include -typedef __int64 PERF_TIME; -#define PICK_TIME(_utime) { \ - FILETIME t1, t2, ktime; \ - GetThreadTimes (GetCurrentThread(), &t1, &t2, &ktime, (FILETIME *)&(_utime));\ -} -#define GET_SECONDS(_utime) (((double)(_utime))/10000000.) - -/* ------- POSIX Definitions ---------------------- */ -#else -#include -typedef clock_t PERF_TIME; -#define PICK_TIME(_utime) { \ - struct tms tmbuf; \ - times (&tmbuf); \ - (_utime) = tmbuf.tms_utime; \ -} -#define GET_SECONDS(_utime) (((double)(_utime))/CLOCKS_PER_SEC) -// #define GET_SECONDS(_utime) (((double)(_utime))/CLK_TCK) -#endif - -/*====================================================================== - DEFINITIONS -======================================================================*/ - -typedef struct { - char* name; /* identifier */ - PERF_TIME cumul_time; /* cumulative time */ - PERF_TIME start_time; /* to store start time */ - int nb_enter; /* number of enters */ -} t_TimeCounter; - -#define MAX_METERS 100 - -static t_TimeCounter MeterTable[MAX_METERS]; -static int nb_meters = 0; - -static int find_meter (const char * const MeterName); -static int _perf_init_meter (const char * const MeterName, - const int doFind); - -/*====================================================================== -Function : perf_init_meter -Purpose : Creates new counter (if it is absent) identified by - MeterName and resets its cumulative value -Returns : iMeter if OK, -1 if alloc problem -======================================================================*/ -int perf_init_meter (const char * const MeterName) -{ - return _perf_init_meter (MeterName, ~0); -} - -/*====================================================================== -Function : perf_tick_meter -Purpose : Increments the counter of meter MeterName without changing - its state with respect to measurement of time. - creates new meter if there is no such meter -Returns : iMeter if OK, -1 if no such meter and cannot create a new one -======================================================================*/ -int perf_tick_meter (const char * const MeterName) -{ - int ic = find_meter (MeterName); - - if (ic == -1) { - /* create new meter */ - ic = _perf_init_meter (MeterName, 0); - } - - if (ic >= 0) - MeterTable[ic].nb_enter ++; - - return ic; -} - -/*====================================================================== -Function : perf_tick_imeter -Purpose : Increments the counter of meter iMeter without changing - its state with respect to measurement of time. -Returns : iMeter if OK, -1 if no such meter -======================================================================*/ -int perf_tick_imeter (const int iMeter) -{ - if (iMeter >= 0 && iMeter < nb_meters) { - MeterTable[iMeter].nb_enter ++; - return iMeter; - } - return -1; -} - -/*====================================================================== -Function : perf_start_meter -Purpose : Forces meter MeterName to begin to count by remembering - the current data of timer; - creates new meter if there is no such meter -Returns : iMeter if OK, -1 if no such meter and cannot create a new one -======================================================================*/ -int perf_start_meter (const char * const MeterName) -{ - int ic = find_meter (MeterName); - - if (ic == -1) { - /* create new meter */ - ic = _perf_init_meter (MeterName, 0); - } - - if (ic >= 0) - PICK_TIME (MeterTable[ic].start_time) - - return ic; -} - -/*====================================================================== -Function : perf_start_imeter -Purpose : Forces meter with number iMeter to begin count by remembering - the current data of timer; - the meter must be previously created -Returns : iMeter if OK, -1 if no such meter -======================================================================*/ -int perf_start_imeter (const int iMeter) -{ - if (iMeter >= 0 && iMeter < nb_meters) { - PICK_TIME (MeterTable[iMeter].start_time) - return iMeter; - } - return -1; -} - -/*====================================================================== -Function : perf_stop_meter -Purpose : Forces meter MeterName to stop and cumulate time elapsed - since start -Returns : iMeter if OK, -1 if no such meter or it is has not been started -======================================================================*/ -int perf_stop_meter (const char * const MeterName) -{ - const int ic = find_meter (MeterName); - - if (ic >= 0 && MeterTable[ic].start_time) { - t_TimeCounter * const ptc = &MeterTable[ic]; - PERF_TIME utime; - PICK_TIME (utime) - ptc->cumul_time += utime - ptc->start_time; - ptc->start_time = 0; - ptc->nb_enter++; - } - - return ic; -} - -/*====================================================================== -Function : perf_stop_imeter -Purpose : Forces meter with number iMeter to stop and cumulate the time - elapsed since the start -Returns : iMeter if OK, -1 if no such meter or it is has not been started -======================================================================*/ -int perf_stop_imeter (const int iMeter) -{ - if (iMeter >= 0 && iMeter < nb_meters) { - t_TimeCounter * const ptc = &MeterTable[iMeter]; - if (ptc->start_time) { - PERF_TIME utime; - PICK_TIME (utime) - ptc->cumul_time += utime - ptc->start_time; - ptc->start_time = 0; - ptc->nb_enter++; - return iMeter; - } - } - return -1; -} - -/*====================================================================== -Function : perf_get_meter -Purpose : Tells the time cumulated by meter MeterName and the number - of enters to this meter -Output : *nb_enter, *seconds if the pointers != NULL -Returns : iMeter if OK, -1 if no such meter -======================================================================*/ -int perf_get_meter (const char * const MeterName, - int * nb_enter, - double * seconds) -{ - const int ic = find_meter (MeterName); - - if (ic >= 0) { - if (nb_enter) *nb_enter = MeterTable[ic].nb_enter; - if (seconds) *seconds = GET_SECONDS(MeterTable[ic].cumul_time); - } - return ic; -} - -/*====================================================================== -Function : perf_print_all_meters -Purpose : Prints on stdout the cumulated time and the number of - enters for each meter in MeterTable; - resets all meters -Output : none -Returns : none -======================================================================*/ -void perf_print_all_meters (void) -{ - int i; - for (i=0; inb_enter) { - printf (" Perf meter results :" - " enters seconds \xe6sec/enter\n"); - break; - } - } - - while (i < nb_meters) { - t_TimeCounter * const ptc = &MeterTable[i++]; - - if (ptc && ptc->nb_enter) { - const double secs = GET_SECONDS(ptc->cumul_time); - - if (ptc->start_time) - printf ("Warning : meter %s has not been stopped\n", ptc->name); - - printf ("%-42s : %7d %8.2f %10.2f\n", - ptc->name, ptc->nb_enter, secs, - (secs>0. ? 1000000 * secs/ptc->nb_enter : 0.)); - - ptc->cumul_time = 0; - ptc->start_time = 0; - ptc->nb_enter = 0; - } - } -} - -/*====================================================================== -Function : perf_close_meter -Purpose : Prints out a meter and resets it -Returns : none -======================================================================*/ -void perf_close_meter (const char * const MeterName) -{ - const int ic = find_meter (MeterName); - if (ic >= 0 && MeterTable[ic].nb_enter) { - t_TimeCounter * const ptc = &MeterTable[ic]; - if (ptc->start_time) - printf (" ===> Warning : meter %s has not been stopped\n", ptc->name); - printf (" ===> [%s] : %d enters, %9.3f seconds\n", - ptc->name, ptc->nb_enter, GET_SECONDS(ptc->cumul_time)); - ptc->cumul_time = 0; - ptc->start_time = 0; - ptc->nb_enter = 0; - } -} - -/*====================================================================== -Function : perf_close_imeter -Purpose : Prints out a meter and resets it -Returns : none -======================================================================*/ -void perf_close_imeter (const int iMeter) -{ - if (iMeter >= 0 && iMeter < nb_meters && MeterTable[iMeter].nb_enter) { - t_TimeCounter * const ptc = &MeterTable[iMeter]; - if (ptc->start_time) - printf (" ===> Warning : meter %s has not been stopped\n", ptc->name); - printf (" ===> [%s] : %d enters, %9.3f seconds\n", - ptc->name, ptc->nb_enter, GET_SECONDS(ptc->cumul_time)); - ptc->cumul_time = 0; - ptc->start_time = 0; - ptc->nb_enter = 0; - } -} - -/*====================================================================== -Function : perf_destroy_all_meters -Purpose : Deletes all meters and frees memory -Returns : none -======================================================================*/ -void perf_destroy_all_meters (void) -{ - int i; - for (i=0; i= MAX_METERS) return 0; - ic = nb_meters; - - MeterTable[ic].name = strdup (MeterName); - if (!MeterTable[ic].name) - return -1; - - nb_meters++; - } - - MeterTable[ic].cumul_time = 0; - MeterTable[ic].start_time = 0; - MeterTable[ic].nb_enter = 0; - if (hasbeencalled == 0) { - atexit (perf_print_and_destroy); - hasbeencalled = ~0; - } - return ic; -} - -/*====================================================================== -Function : find_meter -Purpose : Finds the meter MeterName in the MeterTable -Returns : Index of meter object, -1 if not found -Remarks : For internal use in this module -======================================================================*/ -static int find_meter (const char * const MeterName) -{ - int i; - for (i=0; i +#include +#include +#include +#include +#include +#include + + +/*====================================================================== + DEFINITIONS +======================================================================*/ + +typedef Standard_Real PERF_TIME; + +#define PICK_TIME(_utime) { \ + Standard_Real ktime; \ + OSD_Chronometer::GetThreadCPU(_utime, ktime);\ +} + +typedef struct { + char* name; /* identifier */ + PERF_TIME cumul_time; /* cumulative time */ + PERF_TIME start_time; /* to store start time */ + int nb_enter; /* number of enters */ +} t_TimeCounter; + +#define MAX_METERS 100 + +static t_TimeCounter MeterTable[MAX_METERS]; +static int nb_meters = 0; + +static int find_meter (const char * const MeterName); +static int _perf_init_meter (const char * const MeterName, + const int doFind); + +/*====================================================================== +Function : perf_init_meter +Purpose : Creates new counter (if it is absent) identified by + MeterName and resets its cumulative value +Returns : iMeter if OK, -1 if alloc problem +======================================================================*/ +int perf_init_meter (const char * const MeterName) +{ + return _perf_init_meter (MeterName, ~0); +} + +/*====================================================================== +Function : perf_tick_meter +Purpose : Increments the counter of meter MeterName without changing + its state with respect to measurement of time. + creates new meter if there is no such meter +Returns : iMeter if OK, -1 if no such meter and cannot create a new one +======================================================================*/ +int perf_tick_meter (const char * const MeterName) +{ + int ic = find_meter (MeterName); + + if (ic == -1) { + /* create new meter */ + ic = _perf_init_meter (MeterName, 0); + } + + if (ic >= 0) + MeterTable[ic].nb_enter ++; + + return ic; +} + +/*====================================================================== +Function : perf_tick_imeter +Purpose : Increments the counter of meter iMeter without changing + its state with respect to measurement of time. +Returns : iMeter if OK, -1 if no such meter +======================================================================*/ +int perf_tick_imeter (const int iMeter) +{ + if (iMeter >= 0 && iMeter < nb_meters) { + MeterTable[iMeter].nb_enter ++; + return iMeter; + } + return -1; +} + +/*====================================================================== +Function : perf_start_meter +Purpose : Forces meter MeterName to begin to count by remembering + the current data of timer; + creates new meter if there is no such meter +Returns : iMeter if OK, -1 if no such meter and cannot create a new one +======================================================================*/ +int perf_start_meter (const char * const MeterName) +{ + int ic = find_meter (MeterName); + + if (ic == -1) { + /* create new meter */ + ic = _perf_init_meter (MeterName, 0); + } + + if (ic >= 0) + PICK_TIME (MeterTable[ic].start_time) + + return ic; +} + +/*====================================================================== +Function : perf_start_imeter +Purpose : Forces meter with number iMeter to begin count by remembering + the current data of timer; + the meter must be previously created +Returns : iMeter if OK, -1 if no such meter +======================================================================*/ +int perf_start_imeter (const int iMeter) +{ + if (iMeter >= 0 && iMeter < nb_meters) { + PICK_TIME (MeterTable[iMeter].start_time) + return iMeter; + } + return -1; +} + +/*====================================================================== +Function : perf_stop_meter +Purpose : Forces meter MeterName to stop and cumulate time elapsed + since start +Returns : iMeter if OK, -1 if no such meter or it is has not been started +======================================================================*/ +int perf_stop_meter (const char * const MeterName) +{ + const int ic = find_meter (MeterName); + + if (ic >= 0 && MeterTable[ic].start_time) { + t_TimeCounter * const ptc = &MeterTable[ic]; + PERF_TIME utime; + PICK_TIME (utime) + ptc->cumul_time += utime - ptc->start_time; + ptc->start_time = 0; + ptc->nb_enter++; + } + + return ic; +} + +/*====================================================================== +Function : perf_stop_imeter +Purpose : Forces meter with number iMeter to stop and cumulate the time + elapsed since the start +Returns : iMeter if OK, -1 if no such meter or it is has not been started +======================================================================*/ +int perf_stop_imeter (const int iMeter) +{ + if (iMeter >= 0 && iMeter < nb_meters) { + t_TimeCounter * const ptc = &MeterTable[iMeter]; + if (ptc->start_time) { + PERF_TIME utime; + PICK_TIME (utime) + ptc->cumul_time += utime - ptc->start_time; + ptc->start_time = 0; + ptc->nb_enter++; + return iMeter; + } + } + return -1; +} + +/*====================================================================== +Function : perf_get_meter +Purpose : Tells the time cumulated by meter MeterName and the number + of enters to this meter +Output : *nb_enter, *seconds if the pointers != NULL +Returns : iMeter if OK, -1 if no such meter +======================================================================*/ +int perf_get_meter (const char * const MeterName, + int * nb_enter, + double * seconds) +{ + const int ic = find_meter (MeterName); + + if (ic >= 0) { + if (nb_enter) *nb_enter = MeterTable[ic].nb_enter; + if (seconds) *seconds = MeterTable[ic].cumul_time; + } + return ic; +} + +/*====================================================================== +Function : perf_print_all_meters +Purpose : Prints on stdout the cumulated time and the number of + enters for each meter in MeterTable; + resets all meters +Output : none +Returns : none +======================================================================*/ +void perf_print_all_meters (void) +{ + int i; + for (i=0; inb_enter) { + printf (" Perf meter results :" + " enters seconds \xe6sec/enter\n"); + break; + } + } + + while (i < nb_meters) { + t_TimeCounter * const ptc = &MeterTable[i++]; + + if (ptc && ptc->nb_enter) { + const double secs = ptc->cumul_time; + + if (ptc->start_time) + printf ("Warning : meter %s has not been stopped\n", ptc->name); + + printf ("%-42s : %7d %8.2f %10.2f\n", + ptc->name, ptc->nb_enter, secs, + (secs>0. ? 1000000 * secs/ptc->nb_enter : 0.)); + + ptc->cumul_time = 0; + ptc->start_time = 0; + ptc->nb_enter = 0; + } + } +} + +/*====================================================================== +Function : perf_close_meter +Purpose : Prints out a meter and resets it +Returns : none +======================================================================*/ +void perf_close_meter (const char * const MeterName) +{ + const int ic = find_meter (MeterName); + if (ic >= 0 && MeterTable[ic].nb_enter) { + t_TimeCounter * const ptc = &MeterTable[ic]; + if (ptc->start_time) + printf (" ===> Warning : meter %s has not been stopped\n", ptc->name); + printf (" ===> [%s] : %d enters, %9.3f seconds\n", + ptc->name, ptc->nb_enter, ptc->cumul_time); + ptc->cumul_time = 0; + ptc->start_time = 0; + ptc->nb_enter = 0; + } +} + +/*====================================================================== +Function : perf_close_imeter +Purpose : Prints out a meter and resets it +Returns : none +======================================================================*/ +void perf_close_imeter (const int iMeter) +{ + if (iMeter >= 0 && iMeter < nb_meters && MeterTable[iMeter].nb_enter) { + t_TimeCounter * const ptc = &MeterTable[iMeter]; + if (ptc->start_time) + printf (" ===> Warning : meter %s has not been stopped\n", ptc->name); + printf (" ===> [%s] : %d enters, %9.3f seconds\n", + ptc->name, ptc->nb_enter, ptc->cumul_time); + ptc->cumul_time = 0; + ptc->start_time = 0; + ptc->nb_enter = 0; + } +} + +/*====================================================================== +Function : perf_destroy_all_meters +Purpose : Deletes all meters and frees memory +Returns : none +======================================================================*/ +void perf_destroy_all_meters (void) +{ + int i; + for (i=0; i= MAX_METERS) return 0; + ic = nb_meters; + + MeterTable[ic].name = strdup (MeterName); + if (!MeterTable[ic].name) + return -1; + + nb_meters++; + } + + MeterTable[ic].cumul_time = 0; + MeterTable[ic].start_time = 0; + MeterTable[ic].nb_enter = 0; + if (hasbeencalled == 0) { + atexit (perf_print_and_destroy); + hasbeencalled = ~0; + } + return ic; +} + +/*====================================================================== +Function : find_meter +Purpose : Finds the meter MeterName in the MeterTable +Returns : Index of meter object, -1 if not found +Remarks : For internal use in this module +======================================================================*/ +static int find_meter (const char * const MeterName) +{ + int i; + for (i=0; i 0. Resets all meters */ -Standard_EXPORT void perf_destroy_all_meters (void); +Standard_EXPORTEXTERNC void perf_destroy_all_meters (void); /* Deletes all meters and frees memory */ -extern void perf_print_and_destroy (void); +Standard_EXPORTEXTERNC void perf_print_and_destroy (void); /* ATTENTION !!! This func calls both perf_print_all_meters() and perf_destroy_all_meters() and is called automatically at the end of a program via system call atexit() */ -#ifdef __cplusplus -} -#endif - #endif diff --git a/src/QABugs/QABugs_19.cxx b/src/QABugs/QABugs_19.cxx index 9e49574637..b11142a596 100644 --- a/src/QABugs/QABugs_19.cxx +++ b/src/QABugs/QABugs_19.cxx @@ -18,7 +18,6 @@ // and conditions governing the rights and limitations under the License. - #include #include @@ -39,6 +38,15 @@ #include +#include +#include +#include +#include +#include +#include +#include +#include + //static Standard_Integer OCC230 (Draw_Interpretor& /*di*/, Standard_Integer /*argc*/, const char ** /*argv*/) static Standard_Integer OCC230 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv) { @@ -97,12 +105,56 @@ static Standard_Integer OCC23361 (Draw_Interpretor& di, Standard_Integer /*argc* return 0; } +static Standard_Integer OCC23237 (Draw_Interpretor& di, Standard_Integer /*argc*/, const char** /*argv*/) +{ + OSD_PerfMeter aPM("TestMeter",0); + OSD_Timer aTM; + + // run some operation in cycle for about 2 seconds to have good values of times to compare + int count = 0; + printf("OSD_PerfMeter test.\nRunning Boolean operation on solids in loop.\n"); + for (; aTM.ElapsedTime() < 2.; count++) + { + aPM.Start(); + aTM.Start(); + + // do some operation that will take considerable time compared with time or starting / stopping timers + BRepPrimAPI_MakeBox aBox (10., 10., 10.); + BRepPrimAPI_MakeSphere aSphere (10.); + BRepAlgo_Cut (aBox.Shape(), aSphere.Shape()); + + aTM.Stop(); + aPM.Stop(); + } + + int aNbEnters = 0; + Standard_Real aPerfMeter_CPUtime = 0., aTimer_ElapsedTime = aTM.ElapsedTime(); + + perf_get_meter("TestMeter", &aNbEnters, &aPerfMeter_CPUtime); + + Standard_Real aTimeDiff = (fabs(aTimer_ElapsedTime - aPerfMeter_CPUtime) / aTimer_ElapsedTime); + + printf("\nMeasurement results (%d cycles):\n", count); + printf("\nOSD_PerfMeter CPU time: %lf\nOSD_Timer elapsed time: %lf\n", aPerfMeter_CPUtime, aTimer_ElapsedTime); + printf("Time delta is: %.3lf %%\n", aTimeDiff * 100); + + if (aTimeDiff > 0.2) + di << "OCC23237: Error: too much difference between CPU and elapsed times"; + else if (aNbEnters != count) + di << "OCC23237: Error: counter reported by PerfMeter (" << aNbEnters << ") does not correspond to actual number of cycles"; + else + di << "OCC23237: OK"; + + return 0; +} + void QABugs::Commands_19(Draw_Interpretor& theCommands) { char *group = "QABugs"; theCommands.Add ("OCC230", "OCC230 TrimmedCurve Pnt2d Pnt2d", __FILE__, OCC230, group); theCommands.Add ("OCC142", "OCC142", __FILE__, OCC142, group); theCommands.Add ("OCC23361", "OCC23361", __FILE__, OCC23361, group); + theCommands.Add("OCC23237", "OCC23237", __FILE__, OCC23237, group); return; } diff --git a/src/QANCollection/QANCollection1.cxx b/src/QANCollection/QANCollection1.cxx index aaa05c277b..d3a296d6eb 100755 --- a/src/QANCollection/QANCollection1.cxx +++ b/src/QANCollection/QANCollection1.cxx @@ -22,7 +22,7 @@ #include #include -#include +#include #include #include diff --git a/src/QANCollection/QANCollectionTest.cxx b/src/QANCollection/QANCollectionTest.cxx index f9ae214ae6..4340d02513 100755 --- a/src/QANCollection/QANCollectionTest.cxx +++ b/src/QANCollection/QANCollectionTest.cxx @@ -37,8 +37,7 @@ typedef NCollection_BaseCollection MyBaseCollPnt; #endif #define PERF_ENABLE_METERS -#include -//////////////#include +#include extern Handle(NCollection_BaseAllocator) getAlloc (const int i); @@ -46,6 +45,8 @@ const Standard_Integer REPEAT = 100; void createArray (TColgp_Array1OfPnt& anArrPnt) { + OSD_PerfMeter aPerfMeter("Create array"); + for (Standard_Integer j = 0; j < 2*REPEAT; j++) { PERF_START_METER("Create array") for (Standard_Integer i = anArrPnt.Lower(); i <= anArrPnt.Upper(); i++) @@ -150,5 +151,5 @@ void assignSequence (MySequence& aDest, const MySequence& aSrc) void printAllMeters () { - PERF_PRINT_ALL_METERS + PERF_PRINT_ALL } diff --git a/src/QANCollection/QANCollection_PerfArrays.hxx b/src/QANCollection/QANCollection_PerfArrays.hxx index 74e3275420..e46dc8299f 100755 --- a/src/QANCollection/QANCollection_PerfArrays.hxx +++ b/src/QANCollection/QANCollection_PerfArrays.hxx @@ -23,7 +23,7 @@ #define QANCollection_PerfArrays_HeaderFile #define PERF_ENABLE_METERS -#include +#include ////////////////////////////////#include #include #include @@ -108,7 +108,7 @@ void CompArray1 (const Standard_Integer theRep, ////////////////////////////////aTOper.Stop(); PERF_STOP_METER("TCollection_Array1 operator=") } - PERF_PRINT_ALL_METERS + PERF_PRINT_ALL } // ===================== Test perform of Array2 type ========================== @@ -195,7 +195,7 @@ void CompArray2 (const Standard_Integer theRep, ////////////////////////////////aTOper.Stop(); PERF_STOP_METER("TCollection_Array2 operator=") } - PERF_PRINT_ALL_METERS + PERF_PRINT_ALL } diff --git a/src/QANCollection/QANCollection_PerfLists.hxx b/src/QANCollection/QANCollection_PerfLists.hxx index 2e9120433a..60d76077fb 100755 --- a/src/QANCollection/QANCollection_PerfLists.hxx +++ b/src/QANCollection/QANCollection_PerfLists.hxx @@ -97,7 +97,7 @@ void CompList (const Standard_Integer theRep, ////////////////////////////////aTClea.Stop(); PERF_STOP_METER("TCollection_List clearing") } - PERF_PRINT_ALL_METERS + PERF_PRINT_ALL } // ===================== Test perform of Queue type ========================== @@ -182,7 +182,7 @@ void CompQueue (const Standard_Integer theRep, ////////////////////////////////aTClea.Stop(); PERF_STOP_METER("TCollection_Queue clearing") } - PERF_PRINT_ALL_METERS + PERF_PRINT_ALL } // ===================== Test perform of Stack type ========================== @@ -267,7 +267,7 @@ void CompStack (const Standard_Integer theRep, ////////////////////////////////aTClea.Stop(); PERF_STOP_METER("TCollection_Stack clearing") } - PERF_PRINT_ALL_METERS + PERF_PRINT_ALL } @@ -361,7 +361,7 @@ void CompSet (const Standard_Integer theRep, ////////////////////////////////aTClea.Stop(); PERF_STOP_METER("TCollection_Set clearing") } - PERF_PRINT_ALL_METERS + PERF_PRINT_ALL } @@ -433,7 +433,7 @@ void CompSList (const Standard_Integer theRep, ////////////////////////////////aTClea.Stop(); PERF_STOP_METER("TCollection_SList clearing") } - PERF_PRINT_ALL_METERS + PERF_PRINT_ALL } // ===================== Test perform of Sequence type ========================== @@ -526,7 +526,7 @@ void CompSequence (const Standard_Integer theRep, ////////////////////////////////aTClea.Stop(); PERF_STOP_METER("TCollection_Sequence clearing") } - PERF_PRINT_ALL_METERS + PERF_PRINT_ALL } #endif diff --git a/src/QANCollection/QANCollection_PerfMaps.hxx b/src/QANCollection/QANCollection_PerfMaps.hxx index 841b115cfb..09faecd51c 100755 --- a/src/QANCollection/QANCollection_PerfMaps.hxx +++ b/src/QANCollection/QANCollection_PerfMaps.hxx @@ -118,7 +118,7 @@ void CompMap (const Standard_Integer theRep, ////////////////////////////////aTClea.Stop(); PERF_STOP_METER("TCollection_Map clearing") } - PERF_PRINT_ALL_METERS + PERF_PRINT_ALL } // ===================== Test perform of DataMap type ========================== @@ -213,7 +213,7 @@ void CompDataMap (const Standard_Integer theRep, ////////////////////////////////aTClea.Stop(); PERF_STOP_METER("TCollection_DataMap clearing") } - PERF_PRINT_ALL_METERS + PERF_PRINT_ALL } // ===================== Test perform of DoubleMap type ========================== @@ -323,7 +323,7 @@ void CompDoubleMap (const Standard_Integer theRep, ////////////////////////////////aTClea.Stop(); PERF_STOP_METER("TCollection_DoubleMap clearing") } - PERF_PRINT_ALL_METERS + PERF_PRINT_ALL if (iFail1 || iFail2) cout << "Warning : N map failed " << iFail1 << " times, T map - " << iFail2 << endl; @@ -420,7 +420,7 @@ void CompIndexedMap (const Standard_Integer theRep, ////////////////////////////////aTClea.Stop(); PERF_STOP_METER("TCollection_IndexedMap clearing") } - PERF_PRINT_ALL_METERS + PERF_PRINT_ALL } // ===================== Test perform of IndexedDataMap type ========================== @@ -516,7 +516,7 @@ void CompIndexedDataMap (const Standard_Integer theRep, ////////////////////////////////aTClea.Stop(); PERF_STOP_METER("TCollection_IndexedDataMap clearing") } - PERF_PRINT_ALL_METERS + PERF_PRINT_ALL } #endif diff --git a/src/QANCollection/QANCollection_PerfSparseArray.hxx b/src/QANCollection/QANCollection_PerfSparseArray.hxx index 4c47ba9c24..4120fb1c61 100755 --- a/src/QANCollection/QANCollection_PerfSparseArray.hxx +++ b/src/QANCollection/QANCollection_PerfSparseArray.hxx @@ -23,7 +23,7 @@ #define QANCollection_PerfSparseArray_HeaderFile #define PERF_ENABLE_METERS -#include +#include ////////////////////////////////#include #include #include @@ -81,7 +81,7 @@ void CompSparseArray (const Standard_Integer theRep, const Standard_Integer theS } - PERF_PRINT_ALL_METERS + PERF_PRINT_ALL } #endif diff --git a/src/TKQADraw/PACKAGES b/src/TKQADraw/PACKAGES index 3b6271d2e8..864fba1e92 100755 --- a/src/TKQADraw/PACKAGES +++ b/src/TKQADraw/PACKAGES @@ -1,4 +1,4 @@ -DebugTools + QABugs QADNaming QADraw diff --git a/tests/bugs/fclasses/bug23237 b/tests/bugs/fclasses/bug23237 new file mode 100644 index 0000000000..dd9aaa3fdc --- /dev/null +++ b/tests/bugs/fclasses/bug23237 @@ -0,0 +1,11 @@ +puts "============" +puts "CR23237" +puts "===========" +puts "" +################################################ +# Bug in OSD_PerfMeter +################################################ + +pload QAcommands + +OCC23237 \ No newline at end of file