1 // Copyright (c) 2018 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 #ifndef _Graphic3d_FrameStatsData_HeaderFile
15 #define _Graphic3d_FrameStatsData_HeaderFile
17 #include <NCollection_Array1.hxx>
18 #include <Graphic3d_FrameStatsCounter.hxx>
19 #include <Graphic3d_FrameStatsTimer.hxx>
20 #include <OSD_Timer.hxx>
24 //! Data frame definition.
25 class Graphic3d_FrameStatsData
30 //! Returns FPS (frames per seconds, elapsed time).
31 //! This number indicates an actual frame rate averaged for several frames within UpdateInterval() duration,
32 //! basing on a real elapsed time between updates.
33 Standard_Real FrameRate() const { return myFps; }
35 //! Returns CPU FPS (frames per seconds, CPU time).
36 //! This number indicates a PREDICTED frame rate,
37 //! basing on CPU elapsed time between updates and NOT real elapsed time (which might include periods of CPU inactivity).
38 //! Number is expected to be greater then actual frame rate returned by FrameRate().
39 //! Values significantly greater actual frame rate indicate that rendering is limited by GPU performance (CPU is stalled in-between),
40 //! while values around actual frame rate indicate rendering being limited by CPU performance (GPU is stalled in-between).
41 Standard_Real FrameRateCpu() const { return myFpsCpu; }
43 //! Returns FPS for immediate redraws.
44 Standard_Real ImmediateFrameRate() const { return myFpsImmediate; }
46 //! Returns CPU FPS for immediate redraws.
47 Standard_Real ImmediateFrameRateCpu() const { return myFpsCpuImmediate; }
49 //! Get counter value.
50 Standard_Size CounterValue (Graphic3d_FrameStatsCounter theIndex) const { return myCounters[theIndex]; }
52 //! Get counter value.
53 Standard_Size operator[] (Graphic3d_FrameStatsCounter theIndex) const { return CounterValue (theIndex); }
56 Standard_Real TimerValue (Graphic3d_FrameStatsTimer theIndex) const { return myTimers[theIndex]; }
59 Standard_Real operator[] (Graphic3d_FrameStatsTimer theIndex) const { return TimerValue (theIndex); }
61 //! Empty constructor.
62 Standard_EXPORT Graphic3d_FrameStatsData();
65 Standard_EXPORT Graphic3d_FrameStatsData(const Graphic3d_FrameStatsData& theOther);
68 Standard_EXPORT Graphic3d_FrameStatsData(Graphic3d_FrameStatsData&& theOther) noexcept;
70 //! Assignment operator.
71 Standard_EXPORT Graphic3d_FrameStatsData& operator= (const Graphic3d_FrameStatsData& theOther);
73 //! Assignment with move operator.
74 Standard_EXPORT Graphic3d_FrameStatsData& operator= (Graphic3d_FrameStatsData&& theOther) noexcept;
77 Standard_EXPORT void Reset();
79 //! Fill with maximum values.
80 Standard_EXPORT void FillMax (const Graphic3d_FrameStatsData& theOther);
83 std::vector<Standard_Size> myCounters; //!< counters
84 std::vector<Standard_Real> myTimers; //!< timers
85 std::vector<Standard_Real> myTimersMin; //!< minimal values of timers
86 std::vector<Standard_Real> myTimersMax; //!< maximum values of timers
87 Standard_Real myFps; //!< FPS meter (frames per seconds, elapsed time)
88 Standard_Real myFpsCpu; //!< CPU FPS meter (frames per seconds, CPU time)
89 Standard_Real myFpsImmediate; //!< FPS meter for immediate redraws
90 Standard_Real myFpsCpuImmediate; //!< CPU FPS meter for immediate redraws
93 //! Temporary data frame definition.
94 class Graphic3d_FrameStatsDataTmp : public Graphic3d_FrameStatsData
97 //! Empty constructor.
98 Standard_EXPORT Graphic3d_FrameStatsDataTmp();
100 //! Compute average data considering the amount of rendered frames.
101 Standard_EXPORT void FlushTimers (Standard_Size theNbFrames, bool theIsFinal);
104 Standard_EXPORT void Reset();
106 //! Assignment operator (skip copying irrelevant properties).
107 void operator= (const Graphic3d_FrameStatsData& theOther) { Graphic3d_FrameStatsData::operator= (theOther); }
109 //! Returns FPS (frames per seconds, elapsed time).
110 Standard_Real& ChangeFrameRate() { return myFps; }
112 //! Returns CPU FPS (frames per seconds, CPU time).
113 Standard_Real& ChangeFrameRateCpu() { return myFpsCpu; }
115 //! Returns FPS for immediate redraws.
116 Standard_Real& ChangeImmediateFrameRate() { return myFpsImmediate; }
118 //! Returns CPU FPS for immediate redraws.
119 Standard_Real& ChangeImmediateFrameRateCpu() { return myFpsCpuImmediate; }
121 //! Return a timer object for time measurements.
122 OSD_Timer& ChangeTimer (Graphic3d_FrameStatsTimer theTimer) { return myOsdTimers[theTimer]; }
124 //! Get counter value.
125 Standard_Size& ChangeCounterValue (Graphic3d_FrameStatsCounter theIndex) { return myCounters[theIndex]; }
127 //! Modify counter value.
128 Standard_Size& operator[] (Graphic3d_FrameStatsCounter theIndex) { return ChangeCounterValue (theIndex); }
130 //! Modify timer value.
131 Standard_Real& ChangeTimerValue (Graphic3d_FrameStatsTimer theIndex) { return myTimers[theIndex]; }
133 //! Modify timer value.
134 Standard_Real& operator[] (Graphic3d_FrameStatsTimer theIndex) { return ChangeTimerValue (theIndex); }
137 std::vector<OSD_Timer> myOsdTimers; //!< precise timers for time measurements
138 std::vector<Standard_Real> myTimersPrev; //!< previous timers values
141 #endif // _Graphic3d_FrameStatsData_HeaderFile