Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-23 09:18:18

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 <Standard_CStringHasher.hxx>
0028 #include <NCollection_DataMap.hxx>
0029 
0030 //! Provides convenient service on global timers
0031 //! accessed by string name, mostly aimed for debugging purposes
0032 //!
0033 //! As an instance, envelopes the OSD_Timer to have it as Handle
0034 //!
0035 //! As a tool, supports static dictionary of timers
0036 //! and provides static methods to easily access them
0037 class MoniTool_Timer : public Standard_Transient
0038 {
0039 
0040 public:
0041   //! Create timer in empty state
0042   MoniTool_Timer();
0043 
0044   const OSD_Timer& Timer() const;
0045 
0046   //! Return reference to embedded OSD_Timer
0047   OSD_Timer& Timer();
0048 
0049   void Start();
0050 
0051   void Stop();
0052 
0053   //! Start, Stop and reset the timer
0054   //! In addition to doing that to embedded OSD_Timer,
0055   //! manage also counter of hits
0056   void Reset();
0057 
0058   //! Return value of hits counter (count of Start/Stop pairs)
0059   int Count() const;
0060 
0061   //! Returns value of nesting counter
0062   int IsRunning() const;
0063 
0064   //! Return value of CPU time minus accumulated amendment
0065   double CPU();
0066 
0067   //! Return value of accumulated amendment on CPU time
0068   double Amend() const;
0069 
0070   //! Dumps current state of a timer shortly (one-line output)
0071   Standard_EXPORT void Dump(Standard_OStream& ostr);
0072 
0073   //! Returns a timer from a dictionary by its name
0074   //! If timer not existed, creates a new one
0075   Standard_EXPORT static occ::handle<MoniTool_Timer> Timer(const char* const name);
0076 
0077   static void Start(const char* const name);
0078 
0079   //! Inline methods to conveniently start/stop timer by name
0080   //! Shortcut to Timer(name)->Start/Stop()
0081   static void Stop(const char* const name);
0082 
0083   //! Returns map of timers
0084   Standard_EXPORT static NCollection_DataMap<const char*,
0085                                              occ::handle<MoniTool_Timer>,
0086                                              Standard_CStringHasher>&
0087     Dictionary();
0088 
0089   //! Clears map of timers
0090   Standard_EXPORT static void ClearTimers();
0091 
0092   //! Dumps contents of the whole dictionary
0093   Standard_EXPORT static void DumpTimers(Standard_OStream& ostr);
0094 
0095   //! Computes and remembers amendments for times to
0096   //! access, start, and stop of timer, and estimates
0097   //! second-order error measured by 10 nested timers
0098   Standard_EXPORT static void ComputeAmendments();
0099 
0100   //! The computed amendmens are returned (for information only)
0101   Standard_EXPORT static void GetAmendments(double& Access,
0102                                             double& Internal,
0103                                             double& External,
0104                                             double& Error10);
0105 
0106   DEFINE_STANDARD_RTTIEXT(MoniTool_Timer, Standard_Transient)
0107 
0108 private:
0109   Standard_EXPORT static void AmendAccess();
0110 
0111   Standard_EXPORT void AmendStart();
0112 
0113   //! Internal functions to amend other timers to avoid
0114   //! side effects of operations with current one
0115   Standard_EXPORT void AmendStop();
0116 
0117   OSD_Timer                   myTimer;
0118   int                         myCount;
0119   int                         myNesting;
0120   double                      myAmend;
0121   occ::handle<MoniTool_Timer> myPrev;
0122   occ::handle<MoniTool_Timer> myNext;
0123 };
0124 
0125 #include <MoniTool_Timer.lxx>
0126 class MoniTool_Timer;
0127 
0128 #endif // _MoniTool_Timer_HeaderFile