Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-11 08:47:34

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   //! Default constructor.
0031   Standard_EXPORT Graphic3d_FrameStats();
0032 
0033   //! Destructor.
0034   Standard_EXPORT virtual ~Graphic3d_FrameStats();
0035 
0036   //! Returns interval in seconds for updating meters across several frames; 1 second by default.
0037   Standard_Real UpdateInterval() const { return myUpdateInterval; }
0038 
0039   //! Sets interval in seconds for updating values.
0040   void SetUpdateInterval(Standard_Real theInterval) { myUpdateInterval = theInterval; }
0041 
0042   //! Prefer longer lines over more greater of lines.
0043   Standard_Boolean IsLongLineFormat() const { return myIsLongLineFormat; }
0044 
0045   //! Set if format should prefer longer lines over greater number of lines.
0046   void SetLongLineFormat(Standard_Boolean theValue) { myIsLongLineFormat = theValue; }
0047 
0048   //! Frame redraw started.
0049   Standard_EXPORT virtual void FrameStart(const Handle(Graphic3d_CView)& theView,
0050                                           bool                           theIsImmediateOnly);
0051 
0052   //! Frame redraw finished.
0053   Standard_EXPORT virtual void FrameEnd(const Handle(Graphic3d_CView)& theView,
0054                                         bool                           theIsImmediateOnly);
0055 
0056 public:
0057   //! Returns formatted string.
0058   Standard_EXPORT virtual TCollection_AsciiString FormatStats(
0059     Graphic3d_RenderingParams::PerfCounters theFlags) const;
0060 
0061   //! Fill in the dictionary with formatted statistic info.
0062   Standard_EXPORT virtual void FormatStats(TColStd_IndexedDataMapOfStringString&   theDict,
0063                                            Graphic3d_RenderingParams::PerfCounters theFlags) const;
0064 
0065   //! Returns duration of the last frame in seconds.
0066   Standard_Real FrameDuration() const { return myFrameDuration; }
0067 
0068   //! Returns FPS (frames per seconds, elapsed time).
0069   //! This number indicates an actual frame rate averaged for several frames within UpdateInterval()
0070   //! duration, basing on a real elapsed time between updates.
0071   Standard_Real FrameRate() const { return LastDataFrame().FrameRate(); }
0072 
0073   //! Returns CPU FPS (frames per seconds, CPU time).
0074   //! This number indicates a PREDICTED frame rate,
0075   //! basing on CPU elapsed time between updates and NOT real elapsed time (which might include
0076   //! periods of CPU inactivity). Number is expected to be greater then actual frame rate returned
0077   //! by FrameRate(). Values significantly greater actual frame rate indicate that rendering is
0078   //! limited by GPU performance (CPU is stalled in-between), while values around actual frame rate
0079   //! 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
0085   {
0086     return LastDataFrame()[theCounter];
0087   }
0088 
0089   //! Returns value of specified timer for modification, should be called between ::FrameStart() and
0090   //! ::FrameEnd() calls. Should NOT be called between ::FrameStart() and ::FrameEnd() calls.
0091   Standard_Real TimerValue(Graphic3d_FrameStatsTimer theTimer) const
0092   {
0093     return LastDataFrame()[theTimer];
0094   }
0095 
0096   //! Returns TRUE if some Layers have been culled.
0097   Standard_Boolean HasCulledLayers() const
0098   {
0099     return LastDataFrame()[Graphic3d_FrameStatsCounter_NbLayersNotCulled]
0100            != LastDataFrame()[Graphic3d_FrameStatsCounter_NbLayers];
0101   }
0102 
0103   //! Returns TRUE if some structures have been culled.
0104   Standard_Boolean HasCulledStructs() const
0105   {
0106     return LastDataFrame()[Graphic3d_FrameStatsCounter_NbStructsNotCulled]
0107            != LastDataFrame()[Graphic3d_FrameStatsCounter_NbStructs];
0108   }
0109 
0110   //! Returns last data frame, cached between stats updates.
0111   //! Should NOT be called between ::FrameStart() and ::FrameEnd() calls.
0112   const Graphic3d_FrameStatsData& LastDataFrame() const
0113   {
0114     return myCounters.Value(myLastFrameIndex);
0115   }
0116 
0117   //! Returns last data frame index.
0118   Standard_Integer LastDataFrameIndex() const { return myLastFrameIndex; }
0119 
0120   //! Returns data frames.
0121   const NCollection_Array1<Graphic3d_FrameStatsData>& DataFrames() const { return myCounters; }
0122 
0123   //! Returns data frames.
0124   NCollection_Array1<Graphic3d_FrameStatsData>& ChangeDataFrames() { return myCounters; }
0125 
0126 public:
0127   //! Returns value of specified counter for modification, should be called between ::FrameStart()
0128   //! and ::FrameEnd() calls.
0129   Standard_Size& ChangeCounter(Graphic3d_FrameStatsCounter theCounter)
0130   {
0131     return ActiveDataFrame()[theCounter];
0132   }
0133 
0134   //! Returns value of specified timer for modification, should be called between ::FrameStart() and
0135   //! ::FrameEnd() calls.
0136   Standard_Real& ChangeTimer(Graphic3d_FrameStatsTimer theTimer)
0137   {
0138     return ActiveDataFrame()[theTimer];
0139   }
0140 
0141   //! Returns currently filling data frame for modification, should be called between ::FrameStart()
0142   //! and ::FrameEnd() calls.
0143   Graphic3d_FrameStatsDataTmp& ActiveDataFrame() { return myCountersTmp; }
0144 
0145 protected:
0146   //! Method to collect statistics from the View; called by FrameEnd().
0147   virtual void updateStatistics(const Handle(Graphic3d_CView)& theView,
0148                                 bool                           theIsImmediateOnly) = 0;
0149 
0150 protected:
0151   OSD_Timer     myFpsTimer;       //!< timer for FPS measurements
0152   Standard_Real myFrameStartTime; //!< time at the beginning of frame redraw
0153   Standard_Real myFrameDuration;  //!< frame duration
0154   Standard_Real myUpdateInterval; //!< interval to update meters
0155   // clang-format off
0156   Standard_Size    myFpsFrameCount;           //!< FPS counter (within short measurement time slice)
0157   NCollection_Array1<Graphic3d_FrameStatsData> myCounters; //!< data frames history
0158   Graphic3d_FrameStatsDataTmp myCountersTmp;  //!< data frame values filled to be filled between FrameStart() and FrameEnd() calls
0159   Graphic3d_FrameStatsData    myCountersMax;  //!< data frame values with absolute maximum values in the history
0160   Standard_Integer myLastFrameIndex;          //!< last data frame index
0161   Standard_Boolean myIsLongLineFormat;        //!< prefer longer lines over greater number of lines
0162   // clang-format on
0163 };
0164 
0165 #endif // _Graphic3d_FrameStats_HeaderFile