5e30547b |
1 | // Copyright (c) 2018 OPEN CASCADE SAS |
2 | // |
3 | // This file is part of Open CASCADE Technology software library. |
4 | // |
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. |
10 | // |
11 | // Alternatively, this file may be used under the terms of Open CASCADE |
12 | // commercial license or contractual agreement. |
13 | |
14 | #ifndef _Graphic3d_FrameStatsData_HeaderFile |
15 | #define _Graphic3d_FrameStatsData_HeaderFile |
16 | |
17 | #include <NCollection_Array1.hxx> |
18 | #include <Graphic3d_FrameStatsCounter.hxx> |
19 | #include <Graphic3d_FrameStatsTimer.hxx> |
20 | #include <OSD_Timer.hxx> |
21 | |
22 | #include <vector> |
23 | |
24 | //! Data frame definition. |
25 | class Graphic3d_FrameStatsData |
26 | { |
27 | public: |
28 | DEFINE_STANDARD_ALLOC |
29 | |
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; } |
34 | |
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; } |
42 | |
43 | //! Get counter value. |
44 | Standard_Size CounterValue (Graphic3d_FrameStatsCounter theIndex) const { return myCounters[theIndex]; } |
45 | |
46 | //! Get counter value. |
47 | Standard_Size operator[] (Graphic3d_FrameStatsCounter theIndex) const { return CounterValue (theIndex); } |
48 | |
49 | //! Get timer value. |
50 | Standard_Real TimerValue (Graphic3d_FrameStatsTimer theIndex) const { return myTimers[theIndex]; } |
51 | |
52 | //! Get timer value. |
53 | Standard_Real operator[] (Graphic3d_FrameStatsTimer theIndex) const { return TimerValue (theIndex); } |
54 | |
55 | //! Empty constructor. |
56 | Standard_EXPORT Graphic3d_FrameStatsData(); |
57 | |
58 | //! Assignment operator. |
59 | Standard_EXPORT Graphic3d_FrameStatsData& operator= (const Graphic3d_FrameStatsData& theOther); |
60 | |
61 | //! Reset data. |
62 | Standard_EXPORT void Reset(); |
63 | |
64 | //! Fill with maximum values. |
65 | Standard_EXPORT void FillMax (const Graphic3d_FrameStatsData& theOther); |
66 | |
67 | protected: |
68 | std::vector<Standard_Size> myCounters; //!< counters |
69 | std::vector<Standard_Real> myTimers; //!< timers |
70 | std::vector<Standard_Real> myTimersMin; //!< minimal values of timers |
71 | std::vector<Standard_Real> myTimersMax; //!< maximum values of timers |
72 | Standard_Real myFps; //!< FPS meter (frames per seconds, elapsed time) |
73 | Standard_Real myFpsCpu; //!< CPU FPS meter (frames per seconds, CPU time) |
74 | }; |
75 | |
76 | //! Temporary data frame definition. |
77 | class Graphic3d_FrameStatsDataTmp : public Graphic3d_FrameStatsData |
78 | { |
79 | public: |
80 | //! Empty constructor. |
81 | Standard_EXPORT Graphic3d_FrameStatsDataTmp(); |
82 | |
83 | //! Compute average data considering the amount of rendered frames. |
84 | Standard_EXPORT void FlushTimers (Standard_Size theNbFrames, bool theIsFinal); |
85 | |
86 | //! Reset data. |
87 | Standard_EXPORT void Reset(); |
88 | |
89 | //! Assignment operator (skip copying irrelevant properties). |
90 | void operator= (const Graphic3d_FrameStatsData& theOther) { Graphic3d_FrameStatsData::operator= (theOther); } |
91 | |
92 | //! Returns FPS (frames per seconds, elapsed time). |
93 | Standard_Real& ChangeFrameRate() { return myFps; } |
94 | |
95 | //! Returns CPU FPS (frames per seconds, CPU time). |
96 | Standard_Real& ChangeFrameRateCpu() { return myFpsCpu; } |
97 | |
98 | //! Return a timer object for time measurements. |
99 | OSD_Timer& ChangeTimer (Graphic3d_FrameStatsTimer theTimer) { return myOsdTimers[theTimer]; } |
100 | |
101 | //! Get counter value. |
102 | Standard_Size& ChangeCounterValue (Graphic3d_FrameStatsCounter theIndex) { return myCounters[theIndex]; } |
103 | |
104 | //! Modify counter value. |
105 | Standard_Size& operator[] (Graphic3d_FrameStatsCounter theIndex) { return ChangeCounterValue (theIndex); } |
106 | |
107 | //! Modify timer value. |
108 | Standard_Real& ChangeTimerValue (Graphic3d_FrameStatsTimer theIndex) { return myTimers[theIndex]; } |
109 | |
110 | //! Modify timer value. |
111 | Standard_Real& operator[] (Graphic3d_FrameStatsTimer theIndex) { return ChangeTimerValue (theIndex); } |
112 | |
113 | protected: |
114 | std::vector<OSD_Timer> myOsdTimers; //!< precise timers for time measurements |
115 | std::vector<Standard_Real> myTimersPrev; //!< previous timers values |
116 | }; |
117 | |
118 | #endif // _Graphic3d_FrameStatsData_HeaderFile |