1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-05 18:16:23 +03:00

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
This commit is contained in:
omy 2012-11-30 16:17:28 +04:00
parent ed9161a431
commit c2ae831c12
15 changed files with 115 additions and 582 deletions

View File

@ -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

View File

@ -1,2 +0,0 @@
DebugTools.h
Perf.cxx

View File

@ -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 <msv@nnov.matra-dtv.fr>
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 <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <DebugTools.h>
#ifndef WNT
#include <unistd.h>
#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 <time.h>
#ifdef WNT
#define STRICT
#include <windows.h>
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 <sys/times.h>
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; i<nb_meters; i++) {
t_TimeCounter* ptc = &MeterTable[i];
if (ptc && ptc->nb_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<nb_meters; i++)
free (MeterTable[i].name);
nb_meters = 0;
}
/* agv - non portable: #pragma fini (perf_print_and_destroy) */
void perf_print_and_destroy (void)
{
perf_print_all_meters ();
perf_destroy_all_meters ();
}
/*======================================================================
Function : _perf_init_meter
Purpose : Creates new counter (if it is absent) identified by
MeterName and resets its cumulative value
Returns : the pointer if OK, 0 if alloc problem
Remarks : For internal use in this module
======================================================================*/
static t_TimeCounter* _perf_init_meter (const char * const MeterName,
const int doFind)
{
static int hasbeencalled = 0;
t_TimeCounter* ptc = 0;
if (doFind)
ptc = find_meter (MeterName);
if (!ptc) {
if (nb_meters >= 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<nb_meters; i++)
if (MeterTable[i].hash == aHash)
if (!strcmp (MeterTable[i].name, MeterName)) return &MeterTable[i];
return NULL;
}
static const unsigned int wCRC16a[16] =
{
0000000, 0140301, 0140601, 0000500,
0141401, 0001700, 0001200, 0141101,
0143001, 0003300, 0003600, 0143501,
0002400, 0142701, 0142201, 0002100,
};
static const unsigned int wCRC16b[16] =
{
0000000, 0146001, 0154001, 0012000,
0170001, 0036000, 0024000, 0162001,
0120001, 0066000, 0074000, 0132001,
0050000, 0116001, 0104001, 0043000,
};
/*======================================================================
Function : hash_value
Returns : the hash value of the string
Remarks : For internal use in this module
======================================================================*/
static unsigned int hash_value (const char * const aString)
{
int i;
unsigned int aCRC = 0;
const int aLen = strlen (aString);
const unsigned char * aPtr = (const unsigned char *) aString;
for (i = aLen; i > 0; i--) {
const unsigned int bTmp = aCRC ^ (const unsigned int) (* aPtr++);
aCRC = ((aCRC >> 8) ^ wCRC16a[bTmp & 0x0F]) ^ wCRC16b[(bTmp >> 4) & 0x0F];
}
return aCRC;
}

View File

@ -15,9 +15,9 @@ OSD_WNT_BREAK.hxx
OSD_signal.cxx OSD_signal.cxx
OSD_signal_WNT.cxx OSD_signal_WNT.cxx
OSD_ThreadFunction.hxx OSD_ThreadFunction.hxx
OSD_PThread.hxx OSD_PThread.hxx
OSD_Localizer.cxx OSD_Localizer.cxx
OSD_PerfMeter.c OSD_PerfMeter.cxx
OSD_PerfMeter.h OSD_PerfMeter.h
OSD_PerfMeter.hxx OSD_PerfMeter.hxx
OSD_MAllocHook.cxx OSD_MAllocHook.cxx

View File

@ -38,36 +38,21 @@
#include <stdlib.h> #include <stdlib.h>
#include <limits.h> #include <limits.h>
#include <time.h> #include <time.h>
#include <OSD_Chronometer.hxx>
#include <OSD_PerfMeter.h> #include <OSD_PerfMeter.h>
/* ------- Definitions for Windows compiler -------- */
#ifdef WNT
#define STRICT
#include <windows.h>
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 <sys/times.h>
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 DEFINITIONS
======================================================================*/ ======================================================================*/
typedef Standard_Real PERF_TIME;
#define PICK_TIME(_utime) { \
Standard_Real ktime; \
OSD_Chronometer::GetThreadCPU(_utime, ktime);\
}
typedef struct { typedef struct {
char* name; /* identifier */ char* name; /* identifier */
PERF_TIME cumul_time; /* cumulative time */ PERF_TIME cumul_time; /* cumulative time */
@ -80,8 +65,8 @@ typedef struct {
static t_TimeCounter MeterTable[MAX_METERS]; static t_TimeCounter MeterTable[MAX_METERS];
static int nb_meters = 0; static int nb_meters = 0;
static int find_meter (const char * const MeterName); static int find_meter (const char * const MeterName);
static int _perf_init_meter (const char * const MeterName, static int _perf_init_meter (const char * const MeterName,
const int doFind); const int doFind);
/*====================================================================== /*======================================================================
@ -229,7 +214,7 @@ int perf_get_meter (const char * const MeterName,
if (ic >= 0) { if (ic >= 0) {
if (nb_enter) *nb_enter = MeterTable[ic].nb_enter; if (nb_enter) *nb_enter = MeterTable[ic].nb_enter;
if (seconds) *seconds = GET_SECONDS(MeterTable[ic].cumul_time); if (seconds) *seconds = MeterTable[ic].cumul_time;
} }
return ic; return ic;
} }
@ -258,7 +243,7 @@ void perf_print_all_meters (void)
t_TimeCounter * const ptc = &MeterTable[i++]; t_TimeCounter * const ptc = &MeterTable[i++];
if (ptc && ptc->nb_enter) { if (ptc && ptc->nb_enter) {
const double secs = GET_SECONDS(ptc->cumul_time); const double secs = ptc->cumul_time;
if (ptc->start_time) if (ptc->start_time)
printf ("Warning : meter %s has not been stopped\n", ptc->name); printf ("Warning : meter %s has not been stopped\n", ptc->name);
@ -287,7 +272,7 @@ void perf_close_meter (const char * const MeterName)
if (ptc->start_time) if (ptc->start_time)
printf (" ===> Warning : meter %s has not been stopped\n", ptc->name); printf (" ===> Warning : meter %s has not been stopped\n", ptc->name);
printf (" ===> [%s] : %d enters, %9.3f seconds\n", printf (" ===> [%s] : %d enters, %9.3f seconds\n",
ptc->name, ptc->nb_enter, GET_SECONDS(ptc->cumul_time)); ptc->name, ptc->nb_enter, ptc->cumul_time);
ptc->cumul_time = 0; ptc->cumul_time = 0;
ptc->start_time = 0; ptc->start_time = 0;
ptc->nb_enter = 0; ptc->nb_enter = 0;
@ -306,7 +291,7 @@ void perf_close_imeter (const int iMeter)
if (ptc->start_time) if (ptc->start_time)
printf (" ===> Warning : meter %s has not been stopped\n", ptc->name); printf (" ===> Warning : meter %s has not been stopped\n", ptc->name);
printf (" ===> [%s] : %d enters, %9.3f seconds\n", printf (" ===> [%s] : %d enters, %9.3f seconds\n",
ptc->name, ptc->nb_enter, GET_SECONDS(ptc->cumul_time)); ptc->name, ptc->nb_enter, ptc->cumul_time);
ptc->cumul_time = 0; ptc->cumul_time = 0;
ptc->start_time = 0; ptc->start_time = 0;
ptc->nb_enter = 0; ptc->nb_enter = 0;

View File

@ -84,62 +84,50 @@
#define PERF_PRINT_ALL #define PERF_PRINT_ALL
#endif #endif
#ifndef Standard_EXPORT Standard_EXPORTEXTERNC int perf_init_meter (const char * const MeterName);
#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);
/* Creates new counter (if it is absent) identified by /* Creates new counter (if it is absent) identified by
MeterName and resets its cumulative value MeterName and resets its cumulative value
Returns : iMeter if OK, -1 if alloc problem Returns : iMeter if OK, -1 if alloc problem
*/ */
Standard_EXPORT int perf_start_meter (const char * const MeterName); Standard_EXPORTEXTERNC int perf_start_meter (const char * const MeterName);
/* Forces meter MeterName to begin to count by remembering /* Forces meter MeterName to begin to count by remembering
the current data of timer. the current data of timer.
Creates new meter if there is no such meter Creates new meter if there is no such meter
Returns : iMeter if OK, -1 if no such meter and cannot create a new one Returns : iMeter if OK, -1 if no such meter and cannot create a new one
*/ */
Standard_EXPORT int perf_start_imeter (const int iMeter); Standard_EXPORTEXTERNC int perf_start_imeter (const int iMeter);
/* Forces meter with number iMeter to begin count by remembering /* Forces meter with number iMeter to begin count by remembering
the current data of timer. the current data of timer.
Returns : iMeter if OK, -1 if no such meter Returns : iMeter if OK, -1 if no such meter
*/ */
Standard_EXPORT int perf_stop_meter (const char * const MeterName); Standard_EXPORTEXTERNC int perf_stop_meter (const char * const MeterName);
/* Forces meter MeterName to stop and cumulate the time elapsed since the start /* Forces meter MeterName 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 Returns : iMeter if OK, -1 if no such meter or it is has not been started
*/ */
Standard_EXPORT int perf_stop_imeter (const int iMeter); Standard_EXPORTEXTERNC int perf_stop_imeter (const int iMeter);
/* Forces meter with number iMeter to stop and cumulate the time /* Forces meter with number iMeter to stop and cumulate the time
elapsed since the start. elapsed since the start.
Returns : iMeter if OK, -1 if no such meter or it is has not been started Returns : iMeter if OK, -1 if no such meter or it is has not been started
*/ */
Standard_EXPORT int perf_tick_meter (const char * const MeterName); Standard_EXPORTEXTERNC int perf_tick_meter (const char * const MeterName);
/* Increments the counter of meter MeterName without changing /* Increments the counter of meter MeterName without changing
its state with respect to measurement of time. its state with respect to measurement of time.
Creates new meter if there is no such meter Creates new meter if there is no such meter
Returns : iMeter if OK, -1 if no such meter and cannot create a new one Returns : iMeter if OK, -1 if no such meter and cannot create a new one
*/ */
Standard_EXPORT int perf_tick_imeter (const int iMeter); Standard_EXPORTEXTERNC int perf_tick_imeter (const int iMeter);
/* Increments the counter of meter iMeter without changing /* Increments the counter of meter iMeter without changing
its state with respect to measurement of time. its state with respect to measurement of time.
Returns : iMeter if OK, -1 if no such meter Returns : iMeter if OK, -1 if no such meter
*/ */
Standard_EXPORT int perf_get_meter (const char * const MeterName, Standard_EXPORTEXTERNC int perf_get_meter (const char * const MeterName,
int * nb_enter, int * nb_enter,
double * seconds); double * seconds);
/* Tells the time cumulated by meter MeterName and the number /* Tells the time cumulated by meter MeterName and the number
@ -148,35 +136,31 @@ Standard_EXPORT int perf_get_meter (const char * const MeterName,
Returns : iMeter if OK, -1 if no such meter Returns : iMeter if OK, -1 if no such meter
*/ */
Standard_EXPORT void perf_close_meter (const char * const MeterName); Standard_EXPORTEXTERNC void perf_close_meter (const char * const MeterName);
/* Prints on stdout the cumulated time and the number of enters /* Prints on stdout the cumulated time and the number of enters
for the specified meter for the specified meter
*/ */
Standard_EXPORT void perf_close_imeter (const int iMeter); Standard_EXPORTEXTERNC void perf_close_imeter (const int iMeter);
/* Prints on stdout the cumulated time and the number of enters /* Prints on stdout the cumulated time and the number of enters
for the specified meter for the specified meter
*/ */
Standard_EXPORT void perf_print_all_meters (void); Standard_EXPORTEXTERNC void perf_print_all_meters (void);
/* Prints on stdout the cumulated time and the number of /* Prints on stdout the cumulated time and the number of
enters for each alive meter which have the number of enters > 0. enters for each alive meter which have the number of enters > 0.
Resets all meters 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 /* Deletes all meters and frees memory
*/ */
extern void perf_print_and_destroy (void); Standard_EXPORTEXTERNC void perf_print_and_destroy (void);
/* ATTENTION !!! /* ATTENTION !!!
This func calls both perf_print_all_meters() and perf_destroy_all_meters() This func calls both perf_print_all_meters() and perf_destroy_all_meters()
and is called automatically at the end of a program and is called automatically at the end of a program
via system call atexit() via system call atexit()
*/ */
#ifdef __cplusplus
}
#endif
#endif #endif

View File

@ -18,7 +18,6 @@
// and conditions governing the rights and limitations under the License. // and conditions governing the rights and limitations under the License.
#include <QABugs.hxx> #include <QABugs.hxx>
#include <Draw_Interpretor.hxx> #include <Draw_Interpretor.hxx>
@ -39,6 +38,15 @@
#include <PCollection_HAsciiString.hxx> #include <PCollection_HAsciiString.hxx>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <OSD_PerfMeter.hxx>
#include <OSD_Timer.hxx>
#include <BRepPrimAPI_MakeBox.hxx>
#include <BRepPrimAPI_MakeSphere.hxx>
#include <BRepAlgo_Cut.hxx>
//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*/)
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; 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) { void QABugs::Commands_19(Draw_Interpretor& theCommands) {
char *group = "QABugs"; char *group = "QABugs";
theCommands.Add ("OCC230", "OCC230 TrimmedCurve Pnt2d Pnt2d", __FILE__, OCC230, group); theCommands.Add ("OCC230", "OCC230 TrimmedCurve Pnt2d Pnt2d", __FILE__, OCC230, group);
theCommands.Add ("OCC142", "OCC142", __FILE__, OCC142, group); theCommands.Add ("OCC142", "OCC142", __FILE__, OCC142, group);
theCommands.Add ("OCC23361", "OCC23361", __FILE__, OCC23361, group); theCommands.Add ("OCC23361", "OCC23361", __FILE__, OCC23361, group);
theCommands.Add("OCC23237", "OCC23237", __FILE__, OCC23237, group);
return; return;
} }

View File

@ -22,7 +22,7 @@
#include <QANCollection.hxx> #include <QANCollection.hxx>
#include <Draw_Interpretor.hxx> #include <Draw_Interpretor.hxx>
#include <DebugTools.h> #include <OSD_PerfMeter.hxx>
#include <TColgp_Array1OfPnt.hxx> #include <TColgp_Array1OfPnt.hxx>
#include <TColgp_SequenceOfPnt.hxx> #include <TColgp_SequenceOfPnt.hxx>

View File

@ -37,8 +37,7 @@ typedef NCollection_BaseCollection<gp_Pnt> MyBaseCollPnt;
#endif #endif
#define PERF_ENABLE_METERS #define PERF_ENABLE_METERS
#include <DebugTools.h> #include <OSD_PerfMeter.hxx>
//////////////#include <Perf_Meter.hxx>
extern Handle(NCollection_BaseAllocator) getAlloc (const int i); extern Handle(NCollection_BaseAllocator) getAlloc (const int i);
@ -46,6 +45,8 @@ const Standard_Integer REPEAT = 100;
void createArray (TColgp_Array1OfPnt& anArrPnt) void createArray (TColgp_Array1OfPnt& anArrPnt)
{ {
OSD_PerfMeter aPerfMeter("Create array");
for (Standard_Integer j = 0; j < 2*REPEAT; j++) { for (Standard_Integer j = 0; j < 2*REPEAT; j++) {
PERF_START_METER("Create array") PERF_START_METER("Create array")
for (Standard_Integer i = anArrPnt.Lower(); i <= anArrPnt.Upper(); i++) for (Standard_Integer i = anArrPnt.Lower(); i <= anArrPnt.Upper(); i++)
@ -150,5 +151,5 @@ void assignSequence (MySequence& aDest, const MySequence& aSrc)
void printAllMeters () void printAllMeters ()
{ {
PERF_PRINT_ALL_METERS PERF_PRINT_ALL
} }

View File

@ -23,7 +23,7 @@
#define QANCollection_PerfArrays_HeaderFile #define QANCollection_PerfArrays_HeaderFile
#define PERF_ENABLE_METERS #define PERF_ENABLE_METERS
#include <DebugTools.h> #include <OSD_PerfMeter.hxx>
////////////////////////////////#include <Perf_Meter.hxx> ////////////////////////////////#include <Perf_Meter.hxx>
#include <TColgp_Array1OfPnt.hxx> #include <TColgp_Array1OfPnt.hxx>
#include <TColgp_Array2OfPnt.hxx> #include <TColgp_Array2OfPnt.hxx>
@ -108,7 +108,7 @@ void CompArray1 (const Standard_Integer theRep,
////////////////////////////////aTOper.Stop(); ////////////////////////////////aTOper.Stop();
PERF_STOP_METER("TCollection_Array1 operator=") PERF_STOP_METER("TCollection_Array1 operator=")
} }
PERF_PRINT_ALL_METERS PERF_PRINT_ALL
} }
// ===================== Test perform of Array2 type ========================== // ===================== Test perform of Array2 type ==========================
@ -195,7 +195,7 @@ void CompArray2 (const Standard_Integer theRep,
////////////////////////////////aTOper.Stop(); ////////////////////////////////aTOper.Stop();
PERF_STOP_METER("TCollection_Array2 operator=") PERF_STOP_METER("TCollection_Array2 operator=")
} }
PERF_PRINT_ALL_METERS PERF_PRINT_ALL
} }

View File

@ -97,7 +97,7 @@ void CompList (const Standard_Integer theRep,
////////////////////////////////aTClea.Stop(); ////////////////////////////////aTClea.Stop();
PERF_STOP_METER("TCollection_List clearing") PERF_STOP_METER("TCollection_List clearing")
} }
PERF_PRINT_ALL_METERS PERF_PRINT_ALL
} }
// ===================== Test perform of Queue type ========================== // ===================== Test perform of Queue type ==========================
@ -182,7 +182,7 @@ void CompQueue (const Standard_Integer theRep,
////////////////////////////////aTClea.Stop(); ////////////////////////////////aTClea.Stop();
PERF_STOP_METER("TCollection_Queue clearing") PERF_STOP_METER("TCollection_Queue clearing")
} }
PERF_PRINT_ALL_METERS PERF_PRINT_ALL
} }
// ===================== Test perform of Stack type ========================== // ===================== Test perform of Stack type ==========================
@ -267,7 +267,7 @@ void CompStack (const Standard_Integer theRep,
////////////////////////////////aTClea.Stop(); ////////////////////////////////aTClea.Stop();
PERF_STOP_METER("TCollection_Stack clearing") 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(); ////////////////////////////////aTClea.Stop();
PERF_STOP_METER("TCollection_Set clearing") 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(); ////////////////////////////////aTClea.Stop();
PERF_STOP_METER("TCollection_SList clearing") PERF_STOP_METER("TCollection_SList clearing")
} }
PERF_PRINT_ALL_METERS PERF_PRINT_ALL
} }
// ===================== Test perform of Sequence type ========================== // ===================== Test perform of Sequence type ==========================
@ -526,7 +526,7 @@ void CompSequence (const Standard_Integer theRep,
////////////////////////////////aTClea.Stop(); ////////////////////////////////aTClea.Stop();
PERF_STOP_METER("TCollection_Sequence clearing") PERF_STOP_METER("TCollection_Sequence clearing")
} }
PERF_PRINT_ALL_METERS PERF_PRINT_ALL
} }
#endif #endif

View File

@ -118,7 +118,7 @@ void CompMap (const Standard_Integer theRep,
////////////////////////////////aTClea.Stop(); ////////////////////////////////aTClea.Stop();
PERF_STOP_METER("TCollection_Map clearing") PERF_STOP_METER("TCollection_Map clearing")
} }
PERF_PRINT_ALL_METERS PERF_PRINT_ALL
} }
// ===================== Test perform of DataMap type ========================== // ===================== Test perform of DataMap type ==========================
@ -213,7 +213,7 @@ void CompDataMap (const Standard_Integer theRep,
////////////////////////////////aTClea.Stop(); ////////////////////////////////aTClea.Stop();
PERF_STOP_METER("TCollection_DataMap clearing") PERF_STOP_METER("TCollection_DataMap clearing")
} }
PERF_PRINT_ALL_METERS PERF_PRINT_ALL
} }
// ===================== Test perform of DoubleMap type ========================== // ===================== Test perform of DoubleMap type ==========================
@ -323,7 +323,7 @@ void CompDoubleMap (const Standard_Integer theRep,
////////////////////////////////aTClea.Stop(); ////////////////////////////////aTClea.Stop();
PERF_STOP_METER("TCollection_DoubleMap clearing") PERF_STOP_METER("TCollection_DoubleMap clearing")
} }
PERF_PRINT_ALL_METERS PERF_PRINT_ALL
if (iFail1 || iFail2) if (iFail1 || iFail2)
cout << "Warning : N map failed " << iFail1 << " times, T map - " << cout << "Warning : N map failed " << iFail1 << " times, T map - " <<
iFail2 << endl; iFail2 << endl;
@ -420,7 +420,7 @@ void CompIndexedMap (const Standard_Integer theRep,
////////////////////////////////aTClea.Stop(); ////////////////////////////////aTClea.Stop();
PERF_STOP_METER("TCollection_IndexedMap clearing") PERF_STOP_METER("TCollection_IndexedMap clearing")
} }
PERF_PRINT_ALL_METERS PERF_PRINT_ALL
} }
// ===================== Test perform of IndexedDataMap type ========================== // ===================== Test perform of IndexedDataMap type ==========================
@ -516,7 +516,7 @@ void CompIndexedDataMap (const Standard_Integer theRep,
////////////////////////////////aTClea.Stop(); ////////////////////////////////aTClea.Stop();
PERF_STOP_METER("TCollection_IndexedDataMap clearing") PERF_STOP_METER("TCollection_IndexedDataMap clearing")
} }
PERF_PRINT_ALL_METERS PERF_PRINT_ALL
} }
#endif #endif

View File

@ -23,7 +23,7 @@
#define QANCollection_PerfSparseArray_HeaderFile #define QANCollection_PerfSparseArray_HeaderFile
#define PERF_ENABLE_METERS #define PERF_ENABLE_METERS
#include <DebugTools.h> #include <OSD_PerfMeter.hxx>
////////////////////////////////#include <Perf_Meter.hxx> ////////////////////////////////#include <Perf_Meter.hxx>
#include <NCollection_SparseArray.hxx> #include <NCollection_SparseArray.hxx>
#include <NCollection_SparseArrayBase.hxx> #include <NCollection_SparseArrayBase.hxx>
@ -81,7 +81,7 @@ void CompSparseArray (const Standard_Integer theRep, const Standard_Integer theS
} }
PERF_PRINT_ALL_METERS PERF_PRINT_ALL
} }
#endif #endif

View File

@ -1,4 +1,4 @@
DebugTools
QABugs QABugs
QADNaming QADNaming
QADraw QADraw

View File

@ -0,0 +1,11 @@
puts "============"
puts "CR23237"
puts "==========="
puts ""
################################################
# Bug in OSD_PerfMeter
################################################
pload QAcommands
OCC23237