2 Copyright (c) 1999-2014 OPEN CASCADE SAS
4 This file is part of Open CASCADE Technology software library.
6 This library is free software; you can redistribute it and / or modify it
7 under the terms of the GNU Lesser General Public version 2.1 as published
8 by the Free Software Foundation, with special exception defined in the file
9 OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 distribution for complete text of the license and disclaimer of any warranty.
12 Alternatively, this file may be used under the terms of Open CASCADE
13 commercial license or contractual agreement.
16 #ifndef _OSD_PERFMETER_H
17 #define _OSD_PERFMETER_H
20 Macros for convenient and fast usage of meters.
21 Define PERF_ENABLE_METERS to make them available.
24 #ifdef PERF_ENABLE_METERS
27 Forces meter MeterName to begin to count by remembering
28 the current data of timer.
29 Creates new meter if there is no such meter
31 #define PERF_START_METER(_m_name) { \
32 static int __iMeter = -1; \
33 if (__iMeter >= 0) perf_start_imeter (__iMeter); \
34 else __iMeter = perf_start_meter (_m_name); \
38 Forces meter MeterName to stop and cumulate the time elapsed
41 #define PERF_STOP_METER(_m_name) { \
42 static int __iMeter = -1; \
43 if (__iMeter >= 0) perf_stop_imeter (__iMeter); \
44 else __iMeter = perf_stop_meter (_m_name); \
48 Increments the counter of meter MeterName without changing
49 its state with respect to measurement of time.
50 Creates new meter if there is no such meter.
51 It is useful to count the number of enters to a part of code
52 without wasting a time to measure CPU time.
54 #define PERF_TICK_METER(_m_name) { \
55 static int __iMeter = -1; \
56 if (__iMeter >= 0) perf_tick_imeter (__iMeter); \
57 else __iMeter = perf_tick_meter (_m_name); \
61 Prints out and resets the given meter
63 #define PERF_CLOSE_METER(_m_name) perf_close_meter (_m_name);
66 Prints all existing meters which have been entered at least once
69 #define PERF_PRINT_ALL { \
70 perf_print_all_meters(); \
75 #define PERF_TICK_METER(_m_name)
76 #define PERF_START_METER(_m_name)
77 #define PERF_STOP_METER(_m_name)
78 #define PERF_CLOSE_METER(_m_name)
79 #define PERF_PRINT_ALL
82 Standard_EXPORTEXTERNC int perf_init_meter (const char * const MeterName);
83 /* Creates new counter (if it is absent) identified by
84 MeterName and resets its cumulative value
85 Returns : iMeter if OK, -1 if alloc problem
88 Standard_EXPORTEXTERNC int perf_start_meter (const char * const MeterName);
89 /* Forces meter MeterName to begin to count by remembering
90 the current data of timer.
91 Creates new meter if there is no such meter
92 Returns : iMeter if OK, -1 if no such meter and cannot create a new one
95 Standard_EXPORTEXTERNC int perf_start_imeter (const int iMeter);
96 /* Forces meter with number iMeter to begin count by remembering
97 the current data of timer.
98 Returns : iMeter if OK, -1 if no such meter
101 Standard_EXPORTEXTERNC int perf_stop_meter (const char * const MeterName);
102 /* Forces meter MeterName to stop and cumulate the time elapsed since the start
103 Returns : iMeter if OK, -1 if no such meter or it is has not been started
106 Standard_EXPORTEXTERNC int perf_stop_imeter (const int iMeter);
107 /* Forces meter with number iMeter to stop and cumulate the time
108 elapsed since the start.
109 Returns : iMeter if OK, -1 if no such meter or it is has not been started
112 Standard_EXPORTEXTERNC int perf_tick_meter (const char * const MeterName);
113 /* Increments the counter of meter MeterName without changing
114 its state with respect to measurement of time.
115 Creates new meter if there is no such meter
116 Returns : iMeter if OK, -1 if no such meter and cannot create a new one
119 Standard_EXPORTEXTERNC int perf_tick_imeter (const int iMeter);
120 /* Increments the counter of meter iMeter without changing
121 its state with respect to measurement of time.
122 Returns : iMeter if OK, -1 if no such meter
125 Standard_EXPORTEXTERNC int perf_get_meter (const char * const MeterName,
128 /* Tells the time cumulated by meter MeterName and the number
129 of enters to this meter
130 Output : *nb_enter, *seconds if the pointers != NULL
131 Returns : iMeter if OK, -1 if no such meter
134 Standard_EXPORTEXTERNC void perf_close_meter (const char * const MeterName);
135 /* Prints on stdout the cumulated time and the number of enters
136 for the specified meter
139 Standard_EXPORTEXTERNC void perf_close_imeter (const int iMeter);
140 /* Prints on stdout the cumulated time and the number of enters
141 for the specified meter
144 Standard_EXPORTEXTERNC void perf_print_all_meters (void);
145 /* Prints on stdout the cumulated time and the number of
146 enters for each alive meter which have the number of enters > 0.
150 Standard_EXPORTEXTERNC void perf_destroy_all_meters (void);
151 /* Deletes all meters and frees memory
154 Standard_EXPORTEXTERNC void perf_print_and_destroy (void);
156 This func calls both perf_print_all_meters() and perf_destroy_all_meters()
157 and is called automatically at the end of a program
158 via system call atexit()