|
|
|||
File indexing completed on 2026-09-13 09:17:33
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 DEFINE_STANDARD_ALLOC 0038 0039 //! Initializes a stopped Chronometer. 0040 //! 0041 //! If ThisThreadOnly is True, measured CPU time will account 0042 //! time of the current thread only; otherwise CPU of the 0043 //! process (all threads, and completed children) is measured. 0044 Standard_EXPORT OSD_Chronometer(bool theThisThreadOnly = false); 0045 0046 //! Destructor. 0047 Standard_EXPORT virtual ~OSD_Chronometer(); 0048 0049 //! Return true if timer has been started. 0050 bool IsStarted() const { return !myIsStopped; } 0051 0052 //! Stops and Reinitializes the Chronometer. 0053 Standard_EXPORT virtual void Reset(); 0054 0055 //! Restarts the Chronometer. 0056 Standard_EXPORT virtual void Restart(); 0057 0058 //! Stops the Chronometer. 0059 Standard_EXPORT virtual void Stop(); 0060 0061 //! Starts (after Create or Reset) or restarts (after Stop) 0062 //! the chronometer. 0063 Standard_EXPORT virtual void Start(); 0064 0065 //! Shows the current CPU user and system time on the 0066 //! standard output stream <cout>. 0067 //! The chronometer can be running (laps Time) or stopped. 0068 Standard_EXPORT virtual void Show() const; 0069 0070 //! Shows the current CPU user and system time on the output 0071 //! stream <os>. 0072 //! The chronometer can be running (laps Time) or stopped. 0073 Standard_EXPORT virtual void Show(Standard_OStream& theOStream) const; 0074 0075 //! Returns the current CPU user time in seconds. 0076 //! The chronometer can be running (laps Time) or stopped. 0077 double UserTimeCPU() const 0078 { 0079 double aUserTime = 0.0, aSysTime = 0.0; 0080 Show(aUserTime, aSysTime); 0081 return aUserTime; 0082 } 0083 0084 //! Returns the current CPU system time in seconds. 0085 //! The chronometer can be running (laps Time) or stopped. 0086 double SystemTimeCPU() const 0087 { 0088 double aUserTime = 0.0, aSysTime = 0.0; 0089 Show(aUserTime, aSysTime); 0090 return aSysTime; 0091 } 0092 0093 //! Return TRUE if current thread CPU time should be measured, 0094 //! and FALSE to measure all threads CPU time; FALSE by default, 0095 bool IsThisThreadOnly() const { return myIsThreadOnly; } 0096 0097 //! Set if current thread (TRUE) or all threads (FALSE) CPU time should be measured. 0098 //! Will raise exception if Timer is in started state. 0099 Standard_EXPORT void SetThisThreadOnly(bool theIsThreadOnly); 0100 0101 //! Returns the current CPU user time in a variable. 0102 //! The chronometer can be running (laps Time) or stopped. 0103 void Show(double& theUserSeconds) const { theUserSeconds = UserTimeCPU(); } 0104 0105 //! Returns the current CPU user and system time in variables. 0106 //! The chronometer can be running (laps Time) or stopped. 0107 Standard_EXPORT void Show(double& theUserSec, double& theSystemSec) const; 0108 0109 public: 0110 //! Returns CPU time (user and system) consumed by the current 0111 //! process since its start, in seconds. The actual precision of 0112 //! the measurement depends on granularity provided by the system, 0113 //! and is platform-specific. 0114 Standard_EXPORT static void GetProcessCPU(double& UserSeconds, double& SystemSeconds); 0115 0116 //! Returns CPU time (user and system) consumed by the current 0117 //! thread since its start. Note that this measurement is 0118 //! platform-specific, as threads are implemented and managed 0119 //! differently on different platforms and CPUs. 0120 Standard_EXPORT static void GetThreadCPU(double& UserSeconds, double& SystemSeconds); 0121 0122 protected: 0123 double myStartCpuUser; 0124 double myStartCpuSys; 0125 double myCumulCpuUser; 0126 double myCumulCpuSys; 0127 bool myIsStopped; 0128 bool myIsThreadOnly; 0129 }; 0130 0131 #endif // _OSD_Chronometer_HeaderFile
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|