Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-22 08:59:06

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