1 // Created on: 2001-12-13
2 // Created by: Sergey KUUl
3 // Copyright (c) 2001-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #ifndef _MoniTool_Timer_HeaderFile
17 #define _MoniTool_Timer_HeaderFile
19 #include <Standard.hxx>
20 #include <Standard_Type.hxx>
22 #include <OSD_Timer.hxx>
23 #include <Standard_Integer.hxx>
24 #include <Standard_Real.hxx>
25 #include <Standard_Transient.hxx>
26 #include <Standard_OStream.hxx>
27 #include <Standard_CString.hxx>
28 #include <MoniTool_DataMapOfTimer.hxx>
33 DEFINE_STANDARD_HANDLE(MoniTool_Timer, Standard_Transient)
35 //! Provides convenient service on global timers
36 //! accessed by string name, mostly aimed for debugging purposes
38 //! As an instance, envelopes the OSD_Timer to have it as Handle
40 //! As a tool, supports static dictionary of timers
41 //! and provides static methods to easily access them
42 class MoniTool_Timer : public Standard_Transient
48 //! Create timer in empty state
51 const OSD_Timer& Timer() const;
53 //! Return reference to embedded OSD_Timer
60 //! Start, Stop and reset the timer
61 //! In addition to doing that to embedded OSD_Timer,
62 //! manage also counter of hits
65 //! Return value of hits counter (count of Start/Stop pairs)
66 Standard_Integer Count() const;
68 //! Returns value of nesting counter
69 Standard_Integer IsRunning() const;
71 //! Return value of CPU time minus accumulated amendment
74 //! Return value of accumulated amendment on CPU time
75 Standard_Real Amend() const;
77 //! Dumps current state of a timer shortly (one-line output)
78 Standard_EXPORT void Dump (Standard_OStream& ostr);
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);
84 static void Start (const Standard_CString name);
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);
90 //! Returns map of timers
91 Standard_EXPORT static MoniTool_DataMapOfTimer& Dictionary();
93 //! Clears map of timers
94 Standard_EXPORT static void ClearTimers();
96 //! Dumps contents of the whole dictionary
97 Standard_EXPORT static void DumpTimers (Standard_OStream& ostr);
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();
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);
110 DEFINE_STANDARD_RTTIEXT(MoniTool_Timer,Standard_Transient)
120 Standard_EXPORT static void AmendAccess();
122 Standard_EXPORT void AmendStart();
124 //! Internal functions to amend other timers to avoid
125 //! side effects of operations with current one
126 Standard_EXPORT void AmendStop();
129 Standard_Integer myCount;
130 Standard_Integer myNesting;
131 Standard_Real myAmend;
132 Handle(MoniTool_Timer) myPrev;
133 Handle(MoniTool_Timer) myNext;
139 #include <MoniTool_Timer.lxx>
145 #endif // _MoniTool_Timer_HeaderFile