Back to home page

EIC code displayed by LXR

 
 

    


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

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_Timer_HeaderFile
0018 #define _OSD_Timer_HeaderFile
0019 
0020 #include <Standard.hxx>
0021 #include <Standard_DefineAlloc.hxx>
0022 #include <Standard_Handle.hxx>
0023 
0024 #include <Standard_Real.hxx>
0025 #include <OSD_Chronometer.hxx>
0026 #include <Standard_OStream.hxx>
0027 
0028 
0029 //! Working on heterogeneous platforms
0030 //! we need to use the system call gettimeofday.
0031 //! This function is portable and it measures ELAPSED
0032 //! time and CPU time in seconds and microseconds.
0033 //! Example: OSD_Timer aTimer;
0034 //! aTimer.Start();   // Start  the timers (t1).
0035 //! .....            // Do something.
0036 //! aTimer.Stop();    // Stop the timers (t2).
0037 //! aTimer.Show();    // Give the elapsed time between t1 and t2.
0038 //! // Give also the process CPU time between
0039 //! // t1 and t2.
0040 class OSD_Timer  : public OSD_Chronometer
0041 {
0042 public:
0043 
0044   //! Returns current time in seconds with system-defined precision.
0045   //! The could be a system uptime or a time from some date.
0046   //! Returned value is intended for precise elapsed time measurements as a delta between timestamps.
0047   //! On Windows implemented via QueryPerformanceCounter(), on other systems via gettimeofday().
0048   Standard_EXPORT static Standard_Real GetWallClockTime();
0049 
0050 public:
0051 
0052   DEFINE_STANDARD_ALLOC
0053 
0054   //! Builds a Chronometer initialized and stopped.
0055   //! @param theThisThreadOnly when TRUE, measured CPU time will account time of the current thread only;
0056   //!                          otherwise CPU of the process (all threads, and completed children) is measured;
0057   //!                          this flag does NOT affect ElapsedTime() value, only values returned by OSD_Chronometer
0058   Standard_EXPORT OSD_Timer (Standard_Boolean theThisThreadOnly = Standard_False);
0059 
0060   //! Stops and reinitializes the timer with specified elapsed time.
0061   Standard_EXPORT void Reset (const Standard_Real theTimeElapsedSec);
0062 
0063   //! Stops and reinitializes the timer with zero elapsed time.
0064   Standard_EXPORT virtual void Reset() Standard_OVERRIDE;
0065 
0066   //! Restarts the Timer.
0067   Standard_EXPORT virtual void Restart() Standard_OVERRIDE;
0068 
0069   //! Shows both the elapsed time and CPU time on the standard output
0070   //! stream <cout>.The chronometer can be running (Lap Time) or
0071   //! stopped.
0072   Standard_EXPORT virtual void Show() const Standard_OVERRIDE;
0073   
0074   //! Shows both the elapsed time and CPU  time on the
0075   //! output stream <OS>.
0076   Standard_EXPORT virtual void Show (Standard_OStream& os) const Standard_OVERRIDE;
0077   
0078   //! returns both the elapsed time(seconds,minutes,hours)
0079   //! and CPU  time.
0080   Standard_EXPORT void Show (Standard_Real& theSeconds, Standard_Integer& theMinutes, Standard_Integer& theHours, Standard_Real& theCPUtime) const;
0081   
0082   //! Stops the Timer.
0083   Standard_EXPORT virtual void Stop() Standard_OVERRIDE;
0084   
0085   //! Starts (after Create or Reset) or restarts (after Stop)
0086   //! the Timer.
0087   Standard_EXPORT virtual void Start() Standard_OVERRIDE;
0088   
0089   //! Returns elapsed time in seconds.
0090   Standard_EXPORT Standard_Real ElapsedTime() const;
0091 
0092 private:
0093 
0094   Standard_Real myTimeStart;
0095   Standard_Real myTimeCumul;
0096 
0097 };
0098 
0099 #endif // _OSD_Timer_HeaderFile