b311480e |
1 | // Created on: 2002-04-03 |
2 | // Created by: Michael SAZONOV |
973c2be1 |
3 | // Copyright (c) 2002-2014 OPEN CASCADE SAS |
b311480e |
4 | // |
973c2be1 |
5 | // This file is part of Open CASCADE Technology software library. |
b311480e |
6 | // |
d5f74e42 |
7 | // This library is free software; you can redistribute it and/or modify it under |
8 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
9 | // by the Free Software Foundation, with special exception defined in the file |
10 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
11 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
12 | // |
973c2be1 |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
7fd59977 |
15 | |
16 | #ifndef OSD_PerfMeter_HeaderFile |
17 | #define OSD_PerfMeter_HeaderFile |
18 | |
19 | #include <OSD_PerfMeter.h> |
20 | |
91720fc5 |
21 | //! This class enables measuring the CPU time between two points of code execution, regardless of the scope of these points of code. |
22 | //! A meter is identified by its name (string). So multiple objects in various places of user code may point to the same meter. |
23 | //! The results will be printed on stdout upon finish of the program. |
24 | //! For details see OSD_PerfMeter.h |
25 | class OSD_PerfMeter |
26 | { |
27 | |
28 | public: |
29 | |
30 | //! Constructs a void meter (to further call Init and Start) |
31 | OSD_PerfMeter() : myIMeter(-1) {} |
32 | |
33 | //! Constructs and starts (if autoStart is true) the named meter |
34 | OSD_PerfMeter (const char* theMeter, |
35 | const bool theToAutoStart = true) |
36 | : myIMeter (perf_get_meter (theMeter, 0, 0)) |
37 | { |
38 | if (myIMeter < 0) myIMeter = perf_init_meter (theMeter); |
39 | if (theToAutoStart) Start(); |
7fd59977 |
40 | } |
7fd59977 |
41 | |
91720fc5 |
42 | //! Prepares the named meter |
43 | void Init (const char* theMeter) |
44 | { |
45 | myIMeter = perf_get_meter (theMeter, 0, 0); |
46 | if (myIMeter < 0) myIMeter = perf_init_meter (theMeter); |
47 | } |
48 | |
49 | //! Starts the meter |
50 | void Start() const { perf_start_imeter(myIMeter); } |
7fd59977 |
51 | |
91720fc5 |
52 | //! Stops the meter |
53 | void Stop() const { perf_stop_imeter(myIMeter); } |
7fd59977 |
54 | |
91720fc5 |
55 | //! Increments the counter w/o time measurement |
56 | void Tick() const { perf_tick_imeter(myIMeter); } |
7fd59977 |
57 | |
91720fc5 |
58 | //! Outputs the meter data and resets it to initial state |
59 | void Flush() const { perf_close_imeter(myIMeter); } |
7fd59977 |
60 | |
91720fc5 |
61 | //! Assures stopping upon destruction |
936f43da |
62 | ~OSD_PerfMeter() { if (myIMeter >= 0) Stop(); } |
7fd59977 |
63 | |
96f3bacc |
64 | private: |
65 | |
66 | OSD_PerfMeter(const OSD_PerfMeter&); |
67 | OSD_PerfMeter& operator= (const OSD_PerfMeter&); |
68 | |
91720fc5 |
69 | protected: |
7fd59977 |
70 | |
71 | int myIMeter; |
91720fc5 |
72 | |
7fd59977 |
73 | }; |
74 | |
91720fc5 |
75 | #endif // OSD_PerfMeter_HeaderFile |