0024428: Implementation of LGPL license
[occt.git] / src / OSD / OSD_PerfMeter.h
1 /*
2  Copyright (c) 1999-2014 OPEN CASCADE SAS
3
4  This file is part of Open CASCADE Technology software library.
5
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.
11
12  Alternatively, this file may be used under the terms of Open CASCADE
13  commercial license or contractual agreement.
14 */
15
16 #ifndef _OSD_PERFMETER_H
17 #define _OSD_PERFMETER_H
18
19 /*
20   Macros for convenient and fast usage of meters.
21   Define PERF_ENABLE_METERS to make them available.
22 */
23
24 #ifdef PERF_ENABLE_METERS
25
26 /* PERF_START_METER
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
30 */
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);   \
35 }
36
37 /* PERF_STOP_METER
38    Forces meter MeterName to stop and cumulate the time elapsed
39    since the start
40 */
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);    \
45 }
46
47 /* PERF_TICK_METER
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.
53 */
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);    \
58 }
59
60 /* PERF_CLOSE_METER
61    Prints out and resets the given meter
62 */
63 #define PERF_CLOSE_METER(_m_name) perf_close_meter (_m_name);
64
65 /* PERF_PRINT_ALL
66    Prints all existing meters which have been entered at least once
67    and resets them
68 */
69 #define PERF_PRINT_ALL {                              \
70   perf_print_all_meters();                            \
71 }
72
73
74 #else
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
80 #endif
81
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
86 */
87
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
93 */
94
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
99 */
100
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
104 */
105
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
110 */
111
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
117 */
118
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
123 */
124
125 Standard_EXPORTEXTERNC int     perf_get_meter          (const char * const MeterName,
126                                                  int        * nb_enter,
127                                                  double     * seconds);
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
132 */
133
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
137 */
138
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
142 */
143
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.
147    Resets all meters
148 */
149
150 Standard_EXPORTEXTERNC void    perf_destroy_all_meters (void);
151 /* Deletes all meters and frees memory
152 */
153
154 Standard_EXPORTEXTERNC void    perf_print_and_destroy (void);
155 /* ATTENTION !!!
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()
159 */
160
161 #endif