42cf5bc1 |
1 | // Created on: 2001-12-13 |
2 | // Created by: Sergey KUUl |
3 | // Copyright (c) 2001-2014 OPEN CASCADE SAS |
4 | // |
5 | // This file is part of Open CASCADE Technology software library. |
6 | // |
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 |
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. |
12 | // |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
15 | |
16 | #ifndef _MoniTool_Timer_HeaderFile |
17 | #define _MoniTool_Timer_HeaderFile |
18 | |
19 | #include <Standard.hxx> |
20 | #include <Standard_Type.hxx> |
21 | |
22 | #include <OSD_Timer.hxx> |
23 | #include <Standard_Integer.hxx> |
24 | #include <Standard_Real.hxx> |
25 | #include <MMgt_TShared.hxx> |
26 | #include <Standard_OStream.hxx> |
27 | #include <Standard_CString.hxx> |
28 | #include <MoniTool_DataMapOfTimer.hxx> |
29 | class OSD_Timer; |
30 | |
31 | |
32 | class MoniTool_Timer; |
33 | DEFINE_STANDARD_HANDLE(MoniTool_Timer, MMgt_TShared) |
34 | |
35 | //! Provides convenient service on global timers |
36 | //! accessed by string name, mostly aimed for debugging purposes |
37 | //! |
38 | //! As an instance, envelopes the OSD_Timer to have it as Handle |
39 | //! |
40 | //! As a tool, supports static dictionary of timers |
41 | //! and provides static methods to easily access them |
42 | class MoniTool_Timer : public MMgt_TShared |
43 | { |
44 | |
45 | public: |
46 | |
47 | |
48 | //! Create timer in empty state |
49 | MoniTool_Timer(); |
50 | |
51 | const OSD_Timer& Timer() const; |
52 | |
53 | //! Return reference to embedded OSD_Timer |
54 | OSD_Timer& Timer(); |
55 | |
56 | void Start(); |
57 | |
58 | void Stop(); |
59 | |
60 | //! Start, Stop and reset the timer |
61 | //! In addition to doing that to embedded OSD_Timer, |
62 | //! manage also counter of hits |
63 | void Reset(); |
64 | |
65 | //! Return value of hits counter (count of Start/Stop pairs) |
66 | Standard_Integer Count() const; |
67 | |
68 | //! Returns value of nesting counter |
69 | Standard_Integer IsRunning() const; |
70 | |
71 | //! Return value of CPU time minus accumulated amendment |
72 | Standard_Real CPU(); |
73 | |
74 | //! Return value of accumulated amendment on CPU time |
75 | Standard_Real Amend() const; |
76 | |
77 | //! Dumps current state of a timer shortly (one-line output) |
78 | Standard_EXPORT void Dump (Standard_OStream& ostr); |
79 | |
80 | //! Returns a timer from a dictionary by its name |
81 | //! If timer not existed, creates a new one |
82 | Standard_EXPORT static Handle(MoniTool_Timer) Timer (const Standard_CString name); |
83 | |
84 | static void Start (const Standard_CString name); |
85 | |
86 | //! Inline methods to conveniently start/stop timer by name |
87 | //! Shortcut to Timer(name)->Start/Stop() |
88 | static void Stop (const Standard_CString name); |
89 | |
90 | //! Returns map of timers |
91 | Standard_EXPORT static MoniTool_DataMapOfTimer& Dictionary(); |
92 | |
93 | //! Clears map of timers |
94 | Standard_EXPORT static void ClearTimers(); |
95 | |
96 | //! Dumps contents of the whole dictionary |
97 | Standard_EXPORT static void DumpTimers (Standard_OStream& ostr); |
98 | |
99 | //! Computes and remembers amendments for times to |
100 | //! access, start, and stop of timer, and estimates |
101 | //! second-order error measured by 10 nested timers |
102 | Standard_EXPORT static void ComputeAmendments(); |
103 | |
104 | //! The computed amendmens are returned (for information only) |
105 | Standard_EXPORT static void GetAmendments (Standard_Real& Access, Standard_Real& Internal, Standard_Real& External, Standard_Real& Error10); |
106 | |
107 | |
108 | |
109 | |
92efcf78 |
110 | DEFINE_STANDARD_RTTIEXT(MoniTool_Timer,MMgt_TShared) |
42cf5bc1 |
111 | |
112 | protected: |
113 | |
114 | |
115 | |
116 | |
117 | private: |
118 | |
119 | |
120 | Standard_EXPORT static void AmendAccess(); |
121 | |
122 | Standard_EXPORT void AmendStart(); |
123 | |
124 | //! Internal functions to amend other timers to avoid |
125 | //! side effects of operations with current one |
126 | Standard_EXPORT void AmendStop(); |
127 | |
128 | OSD_Timer myTimer; |
129 | Standard_Integer myCount; |
130 | Standard_Integer myNesting; |
131 | Standard_Real myAmend; |
132 | Handle(MoniTool_Timer) myPrev; |
133 | Handle(MoniTool_Timer) myNext; |
134 | |
135 | |
136 | }; |
137 | |
138 | |
139 | #include <MoniTool_Timer.lxx> |
140 | |
141 | |
142 | |
143 | |
144 | |
145 | #endif // _MoniTool_Timer_HeaderFile |