0023880: Integration of grid "ncl" into the new testing system
[occt.git] / src / OSD / OSD_PerfMeter.h
CommitLineData
b311480e 1/*
973c2be1 2 Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 3
973c2be1 4 This file is part of Open CASCADE Technology software library.
b311480e 5
d5f74e42 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
973c2be1 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.
b311480e 11
973c2be1 12 Alternatively, this file may be used under the terms of Open CASCADE
13 commercial license or contractual agreement.
b311480e 14*/
15
7fd59977 16#ifndef _OSD_PERFMETER_H
17#define _OSD_PERFMETER_H
18
91720fc5 19/**
20 * Macros for convenient and fast usage of meters.
21 * Define PERF_ENABLE_METERS to make them available.
22 */
7fd59977 23#ifdef PERF_ENABLE_METERS
24
91720fc5 25/**
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.
29 */
30#define PERF_START_METER(_m_name) { \
31 static int __iMeter = -1; \
7fd59977 32 if (__iMeter >= 0) perf_start_imeter (__iMeter); \
33 else __iMeter = perf_start_meter (_m_name); \
34}
35
91720fc5 36/**
37 * @def PERF_STOP_METER(theMeterName)
38 * Forces meter MeterName to stop and cumulate the time elapsed since the start.
39 */
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); \
7fd59977 44}
45
91720fc5 46/**
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.
51 */
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); \
7fd59977 56}
57
91720fc5 58/**
59 * @def PERF_CLOSE_METER(theMeterName)
60 * Prints out and resets the given meter.
61 */
7fd59977 62#define PERF_CLOSE_METER(_m_name) perf_close_meter (_m_name);
63
91720fc5 64/**
65 * @def PERF_PRINT_ALL
66 * Prints all existing meters which have been entered at least once and resets them.
67 */
618617fe 68#define PERF_PRINT_ALL() { \
69 perf_print_all_meters(1); \
7fd59977 70}
71
7fd59977 72#else
91720fc5 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)
618617fe 77 #define PERF_PRINT_ALL()
7fd59977 78#endif
79
91720fc5 80/**
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
83 */
84Standard_EXPORTEXTERNC int perf_init_meter (const char* const theMeterName);
85
86/**
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
90 */
91Standard_EXPORTEXTERNC int perf_start_meter (const char* const theMeterName);
92
93/**
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
96 */
97Standard_EXPORTEXTERNC int perf_start_imeter (const int theMeterId);
98
99/**
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
102 */
103Standard_EXPORTEXTERNC int perf_stop_meter (const char* const theMeterName);
104
105/**
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
108 */
109Standard_EXPORTEXTERNC int perf_stop_imeter (const int theMeterId);
110
111/**
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
115 */
116Standard_EXPORTEXTERNC int perf_tick_meter (const char* const theMeterName);
117
118/**
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
121 */
122Standard_EXPORTEXTERNC int perf_tick_imeter (const int theMeterId);
123
124/**
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
129*/
130Standard_EXPORTEXTERNC int perf_get_meter (const char* const theMeterName,
131 int* theNbEnter,
132 double* theSeconds);
133
134/**
135 * Prints on stdout the cumulated time and the number of enters for the specified meter.
136 */
137Standard_EXPORTEXTERNC void perf_close_meter (const char* const theMeterName);
138
139/**
140 * Prints on stdout the cumulated time and the number of enters for the specified meter.
141 */
142Standard_EXPORTEXTERNC void perf_close_imeter (const int theMeterId);
143
144/**
145 * Prints on stdout the cumulated time and the number of enters for each alive meter which have the number of enters > 0.
618617fe 146 * Resets all meters if reset is non-null.
147 */
148Standard_EXPORTEXTERNC void perf_print_all_meters (int reset);
149
150/**
151 * Prints to supplied string buffer the cumulated time and the number of enters
152 * for each alive meter with the number of enters > 0.
153 * If buffer length is not sufficient, data of some meters may be lost.
154 * It is recommended to reserve 256 bytes per meter, 25600 bytes should fit all.
91720fc5 155 * Resets all meters.
156 */
618617fe 157Standard_EXPORTEXTERNC void perf_sprint_all_meters (char *buffer, int length, int reset);
91720fc5 158
159/**
160 * Deletes all meters and frees memory.
161 */
162Standard_EXPORTEXTERNC void perf_destroy_all_meters (void);
163
164/**
165 * ATTENTION!!!
618617fe 166 * This func calls perf_print_all_meters() and perf_destroy_all_meters()
91720fc5 167 * and is called automatically at the end of a program via system call atexit().
168 */
169Standard_EXPORTEXTERNC void perf_print_and_destroy (void);
7fd59977 170
7fd59977 171#endif