Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:04:17

0001 // Created on: 2001-12-13
0002 // Created by: Sergey KUUl
0003 // Copyright (c) 2001-2014 OPEN CASCADE SAS
0004 //
0005 // This file is part of Open CASCADE Technology software library.
0006 //
0007 // This library is free software; you can redistribute it and/or modify it under
0008 // the terms of the GNU Lesser General Public License version 2.1 as published
0009 // by the Free Software Foundation, with special exception defined in the file
0010 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0011 // distribution for complete text of the license and disclaimer of any warranty.
0012 //
0013 // Alternatively, this file may be used under the terms of Open CASCADE
0014 // commercial license or contractual agreement.
0015 
0016 #ifndef _MoniTool_Timer_HeaderFile
0017 #define _MoniTool_Timer_HeaderFile
0018 
0019 #include <Standard.hxx>
0020 #include <Standard_Type.hxx>
0021 
0022 #include <OSD_Timer.hxx>
0023 #include <Standard_Integer.hxx>
0024 #include <Standard_Transient.hxx>
0025 #include <Standard_OStream.hxx>
0026 #include <Standard_CString.hxx>
0027 #include <MoniTool_DataMapOfTimer.hxx>
0028 
0029 
0030 class MoniTool_Timer;
0031 DEFINE_STANDARD_HANDLE(MoniTool_Timer, Standard_Transient)
0032 
0033 //! Provides convenient service on global timers
0034 //! accessed by string name, mostly aimed for debugging purposes
0035 //!
0036 //! As an instance, envelopes the OSD_Timer to have it as Handle
0037 //!
0038 //! As a tool, supports static dictionary of timers
0039 //! and provides static methods to easily access them
0040 class MoniTool_Timer : public Standard_Transient
0041 {
0042 
0043 public:
0044 
0045   
0046   //! Create timer in empty state
0047     MoniTool_Timer();
0048   
0049     const OSD_Timer& Timer() const;
0050   
0051   //! Return reference to embedded OSD_Timer
0052     OSD_Timer& Timer();
0053   
0054     void Start();
0055   
0056     void Stop();
0057   
0058   //! Start, Stop and reset the timer
0059   //! In addition to doing that to embedded OSD_Timer,
0060   //! manage also counter of hits
0061     void Reset();
0062   
0063   //! Return value of hits counter (count of Start/Stop pairs)
0064     Standard_Integer Count() const;
0065   
0066   //! Returns value of nesting counter
0067     Standard_Integer IsRunning() const;
0068   
0069   //! Return value of CPU time minus accumulated amendment
0070     Standard_Real CPU();
0071   
0072   //! Return value of accumulated amendment on CPU time
0073     Standard_Real Amend() const;
0074   
0075   //! Dumps current state of a timer shortly (one-line output)
0076   Standard_EXPORT void Dump (Standard_OStream& ostr);
0077   
0078   //! Returns a timer from a dictionary by its name
0079   //! If timer not existed, creates a new one
0080   Standard_EXPORT static Handle(MoniTool_Timer) Timer (const Standard_CString name);
0081   
0082     static void Start (const Standard_CString name);
0083   
0084   //! Inline methods to conveniently start/stop timer by name
0085   //! Shortcut to Timer(name)->Start/Stop()
0086     static void Stop (const Standard_CString name);
0087   
0088   //! Returns map of timers
0089   Standard_EXPORT static MoniTool_DataMapOfTimer& Dictionary();
0090   
0091   //! Clears map of timers
0092   Standard_EXPORT static void ClearTimers();
0093   
0094   //! Dumps contents of the whole dictionary
0095   Standard_EXPORT static void DumpTimers (Standard_OStream& ostr);
0096   
0097   //! Computes and remembers amendments for times to
0098   //! access, start, and stop of timer, and estimates
0099   //! second-order error measured by 10 nested timers
0100   Standard_EXPORT static void ComputeAmendments();
0101   
0102   //! The computed amendmens are returned (for information only)
0103   Standard_EXPORT static void GetAmendments (Standard_Real& Access, Standard_Real& Internal, Standard_Real& External, Standard_Real& Error10);
0104 
0105 
0106 
0107 
0108   DEFINE_STANDARD_RTTIEXT(MoniTool_Timer,Standard_Transient)
0109 
0110 protected:
0111 
0112 
0113 
0114 
0115 private:
0116 
0117   
0118   Standard_EXPORT static void AmendAccess();
0119   
0120   Standard_EXPORT void AmendStart();
0121   
0122   //! Internal functions to amend other timers to avoid
0123   //! side effects of operations with current one
0124   Standard_EXPORT void AmendStop();
0125 
0126   OSD_Timer myTimer;
0127   Standard_Integer myCount;
0128   Standard_Integer myNesting;
0129   Standard_Real myAmend;
0130   Handle(MoniTool_Timer) myPrev;
0131   Handle(MoniTool_Timer) myNext;
0132 
0133 
0134 };
0135 
0136 
0137 #include <MoniTool_Timer.lxx>
0138 
0139 
0140 
0141 
0142 
0143 #endif // _MoniTool_Timer_HeaderFile