Back to home page

EIC code displayed by LXR

 
 

    


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

0001 // Created on: 2018-03-15
0002 // Created by: Stephan GARNAUD (ARM)
0003 // Copyright (c) 1998-1999 Matra Datavision
0004 // Copyright (c) 1999-2014 OPEN CASCADE SAS
0005 //
0006 // This file is part of Open CASCADE Technology software library.
0007 //
0008 // This library is free software; you can redistribute it and/or modify it under
0009 // the terms of the GNU Lesser General Public License version 2.1 as published
0010 // by the Free Software Foundation, with special exception defined in the file
0011 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0012 // distribution for complete text of the license and disclaimer of any warranty.
0013 //
0014 // Alternatively, this file may be used under the terms of Open CASCADE
0015 // commercial license or contractual agreement.
0016 
0017 #ifndef _OSD_Chronometer_HeaderFile
0018 #define _OSD_Chronometer_HeaderFile
0019 
0020 #include <Standard.hxx>
0021 #include <Standard_DefineAlloc.hxx>
0022 #include <Standard_Handle.hxx>
0023 #include <Standard_Real.hxx>
0024 #include <Standard_OStream.hxx>
0025 
0026 //! This class measures CPU time (both user and system) consumed
0027 //! by current process or thread. The chronometer can be started
0028 //! and stopped multiple times, and measures cumulative time.
0029 //!
0030 //! If only the thread is measured, calls to Stop() and Show()
0031 //! must occur from the same thread where Start() was called
0032 //! (unless chronometer is stopped); otherwise measurement will
0033 //! yield false values.
0034 class OSD_Chronometer 
0035 {
0036 public:
0037 
0038   DEFINE_STANDARD_ALLOC
0039 
0040   //! Initializes a stopped Chronometer.
0041   //!
0042   //! If ThisThreadOnly is True, measured CPU time will account
0043   //! time of the current thread only; otherwise CPU of the
0044   //! process (all threads, and completed children) is measured.
0045   Standard_EXPORT OSD_Chronometer (Standard_Boolean theThisThreadOnly = Standard_False);
0046 
0047   //! Destructor.
0048   Standard_EXPORT virtual ~OSD_Chronometer();
0049 
0050   //! Return true if timer has been started.
0051   Standard_Boolean IsStarted() const { return !myIsStopped; }
0052 
0053   //! Stops and Reinitializes the Chronometer.
0054   Standard_EXPORT virtual void Reset();
0055 
0056   //! Restarts the Chronometer.
0057   Standard_EXPORT virtual void Restart();
0058 
0059   //! Stops the Chronometer.
0060   Standard_EXPORT virtual void Stop();
0061   
0062   //! Starts (after Create or Reset) or restarts (after Stop)
0063   //! the chronometer.
0064   Standard_EXPORT virtual void Start();
0065   
0066   //! Shows the current CPU user and system time on the
0067   //! standard output stream <cout>.
0068   //! The chronometer can be running (laps Time) or stopped.
0069   Standard_EXPORT virtual void Show() const;
0070   
0071   //! Shows the current CPU user and system time on the output
0072   //! stream <os>.
0073   //! The chronometer can be running (laps Time) or stopped.
0074   Standard_EXPORT virtual void Show (Standard_OStream& theOStream) const;
0075 
0076   //! Returns the current CPU user time in seconds.
0077   //! The chronometer can be running (laps Time) or stopped.
0078   Standard_Real UserTimeCPU() const
0079   {
0080     Standard_Real aUserTime = 0.0, aSysTime = 0.0;
0081     Show (aUserTime, aSysTime);
0082     return aUserTime;
0083   }
0084 
0085   //! Returns the current CPU system time in seconds.
0086   //! The chronometer can be running (laps Time) or stopped.
0087   Standard_Real SystemTimeCPU() const
0088   {
0089     Standard_Real aUserTime = 0.0, aSysTime = 0.0;
0090     Show (aUserTime, aSysTime);
0091     return aSysTime;
0092   }
0093 
0094   //! Return TRUE if current thread CPU time should be measured,
0095   //! and FALSE to measure all threads CPU time; FALSE by default,
0096   Standard_Boolean IsThisThreadOnly() const { return myIsThreadOnly; }
0097 
0098   //! Set if current thread (TRUE) or all threads (FALSE) CPU time should be measured.
0099   //! Will raise exception if Timer is in started state.
0100   Standard_EXPORT void SetThisThreadOnly (Standard_Boolean theIsThreadOnly);
0101 
0102   //! Returns the current CPU user time in a variable.
0103   //! The chronometer can be running (laps Time) or stopped.
0104   void Show (Standard_Real& theUserSeconds) const { theUserSeconds = UserTimeCPU(); }
0105   
0106   //! Returns the current CPU user and system time in variables.
0107   //! The chronometer can be running (laps Time) or stopped.
0108   Standard_EXPORT void Show (Standard_Real& theUserSec, Standard_Real& theSystemSec) const;
0109 
0110 public:
0111 
0112   //! Returns CPU time (user and system) consumed by the current
0113   //! process since its start, in seconds. The actual precision of
0114   //! the measurement depends on granularity provided by the system,
0115   //! and is platform-specific.
0116   Standard_EXPORT static void GetProcessCPU (Standard_Real& UserSeconds, Standard_Real& SystemSeconds);
0117   
0118   //! Returns CPU time (user and system) consumed by the current
0119   //! thread since its start. Note that this measurement is
0120   //! platform-specific, as threads are implemented and managed
0121   //! differently on different platforms and CPUs.
0122   Standard_EXPORT static void GetThreadCPU (Standard_Real& UserSeconds, Standard_Real& SystemSeconds);
0123 
0124 protected:
0125 
0126   Standard_Real    myStartCpuUser;
0127   Standard_Real    myStartCpuSys;
0128   Standard_Real    myCumulCpuUser;
0129   Standard_Real    myCumulCpuSys;
0130   Standard_Boolean myIsStopped;
0131   Standard_Boolean myIsThreadOnly;
0132 
0133 };
0134 
0135 #endif // _OSD_Chronometer_HeaderFile