0027691: Remove dchrono from all test cases and move its to perf group
[occt.git] / src / OSD / OSD_Chronometer.hxx
CommitLineData
42cf5bc1 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
5//
6// This file is part of Open CASCADE Technology software library.
7//
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.
13//
14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
16
17#ifndef _OSD_Chronometer_HeaderFile
18#define _OSD_Chronometer_HeaderFile
19
20#include <Standard.hxx>
21#include <Standard_DefineAlloc.hxx>
22#include <Standard_Handle.hxx>
23
24#include <Standard_Boolean.hxx>
25#include <Standard_Real.hxx>
26#include <Standard_OStream.hxx>
27
28
29//! This class measures CPU time (both user and system) consumed
30//! by current process or thread. The chronometer can be started
31//! and stopped multiple times, and measures cumulative time.
32//!
33//! If only the thread is measured, calls to Stop() and Show()
34//! must occur from the same thread where Start() was called
35//! (unless chronometer is stopped); otherwise measurement will
36//! yield false values.
37class OSD_Chronometer
38{
39public:
40
41 DEFINE_STANDARD_ALLOC
42
43
44 //! Initializes a stopped Chronometer.
45 //!
46 //! If ThisThreadOnly is True, measured CPU time will account
47 //! time of the current thread only; otherwise CPU of the
48 //! process (all threads, and completed children) is measured.
49 Standard_EXPORT OSD_Chronometer(const Standard_Boolean ThisThreadOnly = Standard_False);
50 Standard_EXPORT virtual ~OSD_Chronometer();
1beb58d7 51
52 //! Return true if timer has been started.
53 Standard_Boolean IsStarted() const { return !Stopped; }
54
42cf5bc1 55 //! Stops and Reinitializes the Chronometer.
56 Standard_EXPORT virtual void Reset();
44fae8b1 57
58 //! Restarts the Chronometer.
59 Standard_EXPORT virtual void Restart();
60
42cf5bc1 61 //! Stops the Chronometer.
62 Standard_EXPORT virtual void Stop();
63
64 //! Starts (after Create or Reset) or restarts (after Stop)
65 //! the chronometer.
66 Standard_EXPORT virtual void Start();
67
68 //! Shows the current CPU user and system time on the
69 //! standard output stream <cout>.
70 //! The chronometer can be running (laps Time) or stopped.
71 Standard_EXPORT virtual void Show() const;
72
73 //! Shows the current CPU user and system time on the output
74 //! stream <os>.
75 //! The chronometer can be running (laps Time) or stopped.
76 Standard_EXPORT virtual void Show (Standard_OStream& os) const;
77
78 //! Returns the current CPU user time in a variable.
79 //! The chronometer can be running (laps Time) or stopped.
80 Standard_EXPORT void Show (Standard_Real& theUserSeconds) const;
81
82 //! Returns the current CPU user and system time in variables.
83 //! The chronometer can be running (laps Time) or stopped.
84 Standard_EXPORT void Show (Standard_Real& theUserSeconds, Standard_Real& theSystemSeconds) const;
85
86 //! Returns CPU time (user and system) consumed by the current
87 //! process since its start, in seconds. The actual precision of
88 //! the measurement depends on granularity provided by the system,
89 //! and is platform-specific.
90 Standard_EXPORT static void GetProcessCPU (Standard_Real& UserSeconds, Standard_Real& SystemSeconds);
91
92 //! Returns CPU time (user and system) consumed by the current
93 //! thread since its start. Note that this measurement is
94 //! platform-specific, as threads are implemented and managed
95 //! differently on different platforms and CPUs.
96 Standard_EXPORT static void GetThreadCPU (Standard_Real& UserSeconds, Standard_Real& SystemSeconds);
97
98
99
100
101protected:
102
103
104
105 Standard_Boolean Stopped;
106
107
108private:
109
110
111
112 Standard_Boolean ThreadOnly;
113 Standard_Real Start_user;
114 Standard_Real Start_sys;
115 Standard_Real Cumul_user;
116 Standard_Real Cumul_sys;
117
118
119};
120
121
122
123
124
125
126
127#endif // _OSD_Chronometer_HeaderFile