0023237: OSD_PerfMeter reports wrong (zero) times
[occt.git] / src / OSD / OSD_PerfMeter.h
CommitLineData
b311480e 1/*
2 Copyright (c) 1999-2012 OPEN CASCADE SAS
3
4 The content of this file is subject to the Open CASCADE Technology Public
5 License Version 6.5 (the "License"). You may not use the content of this file
6 except in compliance with the License. Please obtain a copy of the License
7 at http://www.opencascade.org and read it completely before using this file.
8
9 The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
10 main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11
12 The Original Code and all software distributed under the License is
13 distributed on an "AS IS" basis, without warranty of any kind, and the
14 Initial Developer hereby disclaims all such warranties, including without
15 limitation, any warranties of merchantability, fitness for a particular
16 purpose or non-infringement. Please see the License for the specific terms
17 and conditions governing the rights and limitations under the License.
18
19*/
20
7fd59977 21#ifndef _OSD_PERFMETER_H
22#define _OSD_PERFMETER_H
23
24/*
25 Macros for convenient and fast usage of meters.
26 Define PERF_ENABLE_METERS to make them available.
27*/
28
29#ifdef PERF_ENABLE_METERS
30
31/* PERF_START_METER
32 Forces meter MeterName to begin to count by remembering
33 the current data of timer.
34 Creates new meter if there is no such meter
35*/
36#define PERF_START_METER(_m_name) { \
37 static int __iMeter = -1; \
38 if (__iMeter >= 0) perf_start_imeter (__iMeter); \
39 else __iMeter = perf_start_meter (_m_name); \
40}
41
42/* PERF_STOP_METER
43 Forces meter MeterName to stop and cumulate the time elapsed
44 since the start
45*/
46#define PERF_STOP_METER(_m_name) { \
47 static int __iMeter = -1; \
48 if (__iMeter >= 0) perf_stop_imeter (__iMeter); \
49 else __iMeter = perf_stop_meter (_m_name); \
50}
51
52/* PERF_TICK_METER
53 Increments the counter of meter MeterName without changing
54 its state with respect to measurement of time.
55 Creates new meter if there is no such meter.
56 It is useful to count the number of enters to a part of code
57 without wasting a time to measure CPU time.
58*/
59#define PERF_TICK_METER(_m_name) { \
60 static int __iMeter = -1; \
61 if (__iMeter >= 0) perf_tick_imeter (__iMeter); \
62 else __iMeter = perf_tick_meter (_m_name); \
63}
64
65/* PERF_CLOSE_METER
66 Prints out and resets the given meter
67*/
68#define PERF_CLOSE_METER(_m_name) perf_close_meter (_m_name);
69
70/* PERF_PRINT_ALL
71 Prints all existing meters which have been entered at least once
72 and resets them
73*/
74#define PERF_PRINT_ALL { \
75 perf_print_all_meters(); \
76}
77
78
79#else
80#define PERF_TICK_METER(_m_name)
81#define PERF_START_METER(_m_name)
82#define PERF_STOP_METER(_m_name)
83#define PERF_CLOSE_METER(_m_name)
84#define PERF_PRINT_ALL
85#endif
86
c2ae831c 87Standard_EXPORTEXTERNC int perf_init_meter (const char * const MeterName);
7fd59977 88/* Creates new counter (if it is absent) identified by
89 MeterName and resets its cumulative value
90 Returns : iMeter if OK, -1 if alloc problem
91*/
92
c2ae831c 93Standard_EXPORTEXTERNC int perf_start_meter (const char * const MeterName);
7fd59977 94/* Forces meter MeterName to begin to count by remembering
95 the current data of timer.
96 Creates new meter if there is no such meter
97 Returns : iMeter if OK, -1 if no such meter and cannot create a new one
98*/
99
c2ae831c 100Standard_EXPORTEXTERNC int perf_start_imeter (const int iMeter);
7fd59977 101/* Forces meter with number iMeter to begin count by remembering
102 the current data of timer.
103 Returns : iMeter if OK, -1 if no such meter
104*/
105
c2ae831c 106Standard_EXPORTEXTERNC int perf_stop_meter (const char * const MeterName);
7fd59977 107/* Forces meter MeterName to stop and cumulate the time elapsed since the start
108 Returns : iMeter if OK, -1 if no such meter or it is has not been started
109*/
110
c2ae831c 111Standard_EXPORTEXTERNC int perf_stop_imeter (const int iMeter);
7fd59977 112/* Forces meter with number iMeter to stop and cumulate the time
113 elapsed since the start.
114 Returns : iMeter if OK, -1 if no such meter or it is has not been started
115*/
116
c2ae831c 117Standard_EXPORTEXTERNC int perf_tick_meter (const char * const MeterName);
7fd59977 118/* Increments the counter of meter MeterName without changing
119 its state with respect to measurement of time.
120 Creates new meter if there is no such meter
121 Returns : iMeter if OK, -1 if no such meter and cannot create a new one
122*/
123
c2ae831c 124Standard_EXPORTEXTERNC int perf_tick_imeter (const int iMeter);
7fd59977 125/* Increments the counter of meter iMeter without changing
126 its state with respect to measurement of time.
127 Returns : iMeter if OK, -1 if no such meter
128*/
129
c2ae831c 130Standard_EXPORTEXTERNC int perf_get_meter (const char * const MeterName,
7fd59977 131 int * nb_enter,
132 double * seconds);
133/* Tells the time cumulated by meter MeterName and the number
134 of enters to this meter
135 Output : *nb_enter, *seconds if the pointers != NULL
136 Returns : iMeter if OK, -1 if no such meter
137*/
138
c2ae831c 139Standard_EXPORTEXTERNC void perf_close_meter (const char * const MeterName);
7fd59977 140/* Prints on stdout the cumulated time and the number of enters
141 for the specified meter
142*/
143
c2ae831c 144Standard_EXPORTEXTERNC void perf_close_imeter (const int iMeter);
7fd59977 145/* Prints on stdout the cumulated time and the number of enters
146 for the specified meter
147*/
148
c2ae831c 149Standard_EXPORTEXTERNC void perf_print_all_meters (void);
7fd59977 150/* Prints on stdout the cumulated time and the number of
151 enters for each alive meter which have the number of enters > 0.
152 Resets all meters
153*/
154
c2ae831c 155Standard_EXPORTEXTERNC void perf_destroy_all_meters (void);
7fd59977 156/* Deletes all meters and frees memory
157*/
158
c2ae831c 159Standard_EXPORTEXTERNC void perf_print_and_destroy (void);
7fd59977 160/* ATTENTION !!!
161 This func calls both perf_print_all_meters() and perf_destroy_all_meters()
162 and is called automatically at the end of a program
163 via system call atexit()
164*/
165
7fd59977 166#endif