1 // Created on: 2018-03-15
2 // Created by: Stephan GARNAUD (ARM)
3 // Copyright (c) 1998-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #ifndef _OSD_Timer_HeaderFile
18 #define _OSD_Timer_HeaderFile
20 #include <Standard.hxx>
21 #include <Standard_DefineAlloc.hxx>
22 #include <Standard_Handle.hxx>
24 #include <Standard_Real.hxx>
25 #include <OSD_Chronometer.hxx>
26 #include <Standard_OStream.hxx>
27 #include <Standard_Integer.hxx>
30 //! Working on heterogeneous platforms
31 //! we need to use the system call gettimeofday.
32 //! This function is portable and it measures ELAPSED
33 //! time and CPU time in seconds and microseconds.
34 //! Example: OSD_Timer aTimer;
35 //! aTimer.Start(); // Start the timers (t1).
36 //! ..... // Do something.
37 //! aTimer.Stop(); // Stop the timers (t2).
38 //! aTimer.Show(); // Give the elapsed time between t1 and t2.
39 //! // Give also the process CPU time between
41 class OSD_Timer : public OSD_Chronometer
47 //! Builds a Chronometer initialized and stopped.
48 Standard_EXPORT OSD_Timer();
50 //! Stops and reinitializes the timer with specified elapsed time.
51 Standard_EXPORT void Reset (const Standard_Real theTimeElapsedSec);
53 //! Stops and reinitializes the timer with zero elapsed time.
54 Standard_EXPORT virtual void Reset() Standard_OVERRIDE;
56 //! Restarts the Timer.
57 Standard_EXPORT virtual void Restart() Standard_OVERRIDE;
59 //! Shows both the elapsed time and CPU time on the standard output
60 //! stream <cout>.The chronometer can be running (Lap Time) or
62 Standard_EXPORT virtual void Show() const Standard_OVERRIDE;
64 //! Shows both the elapsed time and CPU time on the
65 //! output stream <OS>.
66 Standard_EXPORT virtual void Show (Standard_OStream& os) const Standard_OVERRIDE;
68 //! returns both the elapsed time(seconds,minutes,hours)
70 Standard_EXPORT void Show (Standard_Real& theSeconds, Standard_Integer& theMinutes, Standard_Integer& theHours, Standard_Real& theCPUtime) const;
73 Standard_EXPORT virtual void Stop() Standard_OVERRIDE;
75 //! Starts (after Create or Reset) or restarts (after Stop)
77 Standard_EXPORT virtual void Start() Standard_OVERRIDE;
79 //! Returns elapsed time in seconds.
80 Standard_EXPORT Standard_Real ElapsedTime() const;
84 Standard_Real TimeStart;
85 Standard_Real TimeCumul;
89 #endif // _OSD_Timer_HeaderFile