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 under
7 the terms of the GNU Lesser General Public License 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.
23 #ifdef PERF_ENABLE_METERS
26 * @def PERF_START_METER(theMeterName)
27 * Forces meter MeterName to begin to count by remembering the current data of timer.
28 * Creates new meter if there is no such meter.
30 #define PERF_START_METER(_m_name) { \
31 static int __iMeter = -1; \
32 if (__iMeter >= 0) perf_start_imeter (__iMeter); \
33 else __iMeter = perf_start_meter (_m_name); \
37 * @def PERF_STOP_METER(theMeterName)
38 * Forces meter MeterName to stop and cumulate the time elapsed since the start.
40 #define PERF_STOP_METER(_m_name) { \
41 static int __iMeter = -1; \
42 if (__iMeter >= 0) perf_stop_imeter (__iMeter); \
43 else __iMeter = perf_stop_meter (_m_name); \
47 * @def PERF_TICK_METER(theMeterName)
48 * Increments the counter of meter MeterName without changing its state with respect to measurement of time.
49 * Creates new meter if there is no such meter.
50 * It is useful to count the number of enters to a part of code without wasting a time to measure CPU time.
52 #define PERF_TICK_METER(_m_name) { \
53 static int __iMeter = -1; \
54 if (__iMeter >= 0) perf_tick_imeter (__iMeter); \
55 else __iMeter = perf_tick_meter (_m_name); \
59 * @def PERF_CLOSE_METER(theMeterName)
60 * Prints out and resets the given meter.
62 #define PERF_CLOSE_METER(_m_name) perf_close_meter (_m_name);
66 * Prints all existing meters which have been entered at least once and resets them.
68 #define PERF_PRINT_ALL { \
69 perf_print_all_meters(); \
73 #define PERF_TICK_METER(_m_name)
74 #define PERF_START_METER(_m_name)
75 #define PERF_STOP_METER(_m_name)
76 #define PERF_CLOSE_METER(_m_name)
77 #define PERF_PRINT_ALL
81 * Creates new counter (if it is absent) identified by theMeterName and resets its cumulative value
82 * @return meter global identifier if OK, -1 if alloc problem
84 Standard_EXPORTEXTERNC int perf_init_meter (const char* const theMeterName);
87 * Forces meter theMeterName to begin to count by remembering the current data of timer.
88 * Creates new meter if there is no such meter.
89 * @return meter global identifier if OK, -1 if no such meter and cannot create a new one
91 Standard_EXPORTEXTERNC int perf_start_meter (const char* const theMeterName);
94 * Forces meter with number theMeterId to begin count by remembering the current data of timer.
95 * @return meter global identifier if OK, -1 if no such meter
97 Standard_EXPORTEXTERNC int perf_start_imeter (const int theMeterId);
100 * Forces meter theMeterName to stop and cumulate the time elapsed since the start.
101 * @return meter global identifier if OK, -1 if no such meter or it is has not been started
103 Standard_EXPORTEXTERNC int perf_stop_meter (const char* const theMeterName);
106 * Forces meter with number theMeterId to stop and cumulate the time elapsed since the start.
107 * @return meter global identifier if OK, -1 if no such meter or it is has not been started
109 Standard_EXPORTEXTERNC int perf_stop_imeter (const int theMeterId);
112 * Increments the counter of meter theMeterName without changing its state with respect to measurement of time.
113 * Creates new meter if there is no such meter.
114 * @return meter global identifier if OK, -1 if no such meter and cannot create a new one
116 Standard_EXPORTEXTERNC int perf_tick_meter (const char* const theMeterName);
119 * Increments the counter of meter theMeterId without changing its state with respect to measurement of time.
120 * @return meter global identifier if OK, -1 if no such meter
122 Standard_EXPORTEXTERNC int perf_tick_imeter (const int theMeterId);
125 * Tells the time cumulated by meter theMeterName and the number of enters to this meter.
126 * @param theNbEnter [OUT] number of enters if the pointer != NULL
127 * @param theSeconds [OUT] seconds if the pointer != NULL
128 * @return meter global identifier if OK, -1 if no such meter
130 Standard_EXPORTEXTERNC int perf_get_meter (const char* const theMeterName,
135 * Prints on stdout the cumulated time and the number of enters for the specified meter.
137 Standard_EXPORTEXTERNC void perf_close_meter (const char* const theMeterName);
140 * Prints on stdout the cumulated time and the number of enters for the specified meter.
142 Standard_EXPORTEXTERNC void perf_close_imeter (const int theMeterId);
145 * Prints on stdout the cumulated time and the number of enters for each alive meter which have the number of enters > 0.
148 Standard_EXPORTEXTERNC void perf_print_all_meters (void);
151 * Deletes all meters and frees memory.
153 Standard_EXPORTEXTERNC void perf_destroy_all_meters (void);
157 * This func calls both perf_print_all_meters() and perf_destroy_all_meters()
158 * and is called automatically at the end of a program via system call atexit().
160 Standard_EXPORTEXTERNC void perf_print_and_destroy (void);