Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:03:48

0001 // Copyright (c) 2017 OPEN CASCADE SAS
0002 //
0003 // This file is part of Open CASCADE Technology software library.
0004 //
0005 // This library is free software; you can redistribute it and/or modify it under
0006 // the terms of the GNU Lesser General Public License version 2.1 as published
0007 // by the Free Software Foundation, with special exception defined in the file
0008 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0009 // distribution for complete text of the license and disclaimer of any warranty.
0010 //
0011 // Alternatively, this file may be used under the terms of Open CASCADE
0012 // commercial license or contractual agreement.
0013 
0014 #ifndef _Graphic3d_FrameStats_HeaderFile
0015 #define _Graphic3d_FrameStats_HeaderFile
0016 
0017 #include <Graphic3d_FrameStatsData.hxx>
0018 #include <Graphic3d_RenderingParams.hxx>
0019 #include <Standard_Type.hxx>
0020 #include <Standard_Transient.hxx>
0021 #include <TColStd_IndexedDataMapOfStringString.hxx>
0022 
0023 class Graphic3d_CView;
0024 
0025 //! Class storing the frame statistics.
0026 class Graphic3d_FrameStats : public Standard_Transient
0027 {
0028   DEFINE_STANDARD_RTTIEXT(Graphic3d_FrameStats, Standard_Transient)
0029 public:
0030 
0031   //! Default constructor.
0032   Standard_EXPORT Graphic3d_FrameStats();
0033 
0034   //! Destructor.
0035   Standard_EXPORT virtual ~Graphic3d_FrameStats();
0036 
0037   //! Returns interval in seconds for updating meters across several frames; 1 second by default.
0038   Standard_Real UpdateInterval() const { return myUpdateInterval; }
0039 
0040   //! Sets interval in seconds for updating values.
0041   void SetUpdateInterval (Standard_Real theInterval) { myUpdateInterval = theInterval; }
0042 
0043   //! Prefer longer lines over more greater of lines.
0044   Standard_Boolean IsLongLineFormat() const { return myIsLongLineFormat; }
0045 
0046   //! Set if format should prefer longer lines over greater number of lines.
0047   void SetLongLineFormat (Standard_Boolean theValue) { myIsLongLineFormat = theValue; }
0048 
0049   //! Frame redraw started.
0050   Standard_EXPORT virtual void FrameStart (const Handle(Graphic3d_CView)& theView,
0051                                            bool theIsImmediateOnly);
0052 
0053   //! Frame redraw finished.
0054   Standard_EXPORT virtual void FrameEnd (const Handle(Graphic3d_CView)& theView,
0055                                          bool theIsImmediateOnly);
0056 
0057 public:
0058 
0059   //! Returns formatted string.
0060   Standard_EXPORT virtual TCollection_AsciiString FormatStats (Graphic3d_RenderingParams::PerfCounters theFlags) const;
0061 
0062   //! Fill in the dictionary with formatted statistic info.
0063   Standard_EXPORT virtual void FormatStats (TColStd_IndexedDataMapOfStringString&   theDict,
0064                                             Graphic3d_RenderingParams::PerfCounters theFlags) const;
0065 
0066   //! Returns duration of the last frame in seconds.
0067   Standard_Real FrameDuration() const { return myFrameDuration; }
0068 
0069   //! Returns FPS (frames per seconds, elapsed time).
0070   //! This number indicates an actual frame rate averaged for several frames within UpdateInterval() duration,
0071   //! basing on a real elapsed time between updates.
0072   Standard_Real FrameRate() const { return LastDataFrame().FrameRate(); }
0073 
0074   //! Returns CPU FPS (frames per seconds, CPU time).
0075   //! This number indicates a PREDICTED frame rate,
0076   //! basing on CPU elapsed time between updates and NOT real elapsed time (which might include periods of CPU inactivity).
0077   //! Number is expected to be greater then actual frame rate returned by FrameRate().
0078   //! Values significantly greater actual frame rate indicate that rendering is limited by GPU performance (CPU is stalled in-between),
0079   //! while values around actual frame rate indicate rendering being limited by CPU performance (GPU is stalled in-between).
0080   Standard_Real FrameRateCpu() const { return LastDataFrame().FrameRateCpu(); }
0081 
0082   //! Returns value of specified counter, cached between stats updates.
0083   //! Should NOT be called between ::FrameStart() and ::FrameEnd() calls.
0084   Standard_Size CounterValue (Graphic3d_FrameStatsCounter theCounter) const { return LastDataFrame()[theCounter]; }
0085 
0086   //! Returns value of specified timer for modification, should be called between ::FrameStart() and ::FrameEnd() calls.
0087   //! Should NOT be called between ::FrameStart() and ::FrameEnd() calls.
0088   Standard_Real TimerValue (Graphic3d_FrameStatsTimer theTimer) const { return LastDataFrame()[theTimer]; }
0089 
0090   //! Returns TRUE if some Layers have been culled.
0091   Standard_Boolean HasCulledLayers() const { return LastDataFrame()[Graphic3d_FrameStatsCounter_NbLayersNotCulled] != LastDataFrame()[Graphic3d_FrameStatsCounter_NbLayers]; }
0092 
0093   //! Returns TRUE if some structures have been culled.
0094   Standard_Boolean HasCulledStructs() const { return LastDataFrame()[Graphic3d_FrameStatsCounter_NbStructsNotCulled] != LastDataFrame()[Graphic3d_FrameStatsCounter_NbStructs]; }
0095 
0096   //! Returns last data frame, cached between stats updates.
0097   //! Should NOT be called between ::FrameStart() and ::FrameEnd() calls.
0098   const Graphic3d_FrameStatsData& LastDataFrame() const { return myCounters.Value (myLastFrameIndex); }
0099 
0100   //! Returns last data frame index.
0101   Standard_Integer LastDataFrameIndex() const { return myLastFrameIndex; }
0102 
0103   //! Returns data frames.
0104   const NCollection_Array1<Graphic3d_FrameStatsData>& DataFrames() const { return myCounters; }
0105 
0106   //! Returns data frames.
0107   NCollection_Array1<Graphic3d_FrameStatsData>& ChangeDataFrames() { return myCounters; }
0108 
0109 public:
0110 
0111   //! Returns value of specified counter for modification, should be called between ::FrameStart() and ::FrameEnd() calls.
0112   Standard_Size& ChangeCounter (Graphic3d_FrameStatsCounter theCounter) { return ActiveDataFrame()[theCounter]; }
0113 
0114   //! Returns value of specified timer for modification, should be called between ::FrameStart() and ::FrameEnd() calls.
0115   Standard_Real& ChangeTimer (Graphic3d_FrameStatsTimer theTimer) { return ActiveDataFrame()[theTimer]; }
0116 
0117   //! Returns currently filling data frame for modification, should be called between ::FrameStart() and ::FrameEnd() calls.
0118   Graphic3d_FrameStatsDataTmp& ActiveDataFrame() { return myCountersTmp; }
0119 
0120 protected:
0121 
0122   //! Method to collect statistics from the View; called by FrameEnd().
0123   virtual void updateStatistics (const Handle(Graphic3d_CView)& theView,
0124                                  bool theIsImmediateOnly) = 0;
0125 
0126 protected:
0127 
0128   OSD_Timer        myFpsTimer;                //!< timer for FPS measurements
0129   Standard_Real    myFrameStartTime;          //!< time at the beginning of frame redraw
0130   Standard_Real    myFrameDuration;           //!< frame duration
0131   Standard_Real    myUpdateInterval;          //!< interval to update meters
0132   Standard_Size    myFpsFrameCount;           //!< FPS counter (within short measurement time slice)
0133   NCollection_Array1<Graphic3d_FrameStatsData> myCounters; //!< data frames history
0134   Graphic3d_FrameStatsDataTmp myCountersTmp;  //!< data frame values filled to be filled between FrameStart() and FrameEnd() calls
0135   Graphic3d_FrameStatsData    myCountersMax;  //!< data frame values with absolute maximum values in the history
0136   Standard_Integer myLastFrameIndex;          //!< last data frame index
0137   Standard_Boolean myIsLongLineFormat;        //!< prefer longer lines over greater number of lines
0138 
0139 };
0140 
0141 #endif // _Graphic3d_FrameStats_HeaderFile