Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-10-08 09:32:13

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