1 // Copyright (c) 2017 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 #include <Graphic3d_FrameStats.hxx>
16 #include <Graphic3d_CView.hxx>
18 IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_FrameStats, Standard_Transient)
23 static std::ostream& formatCounter (std::ostream& theStream,
24 Standard_Integer theWidth,
25 const char* thePrefix,
26 Standard_Size theValue,
27 const char* thePostfix = NULL)
29 if (thePrefix != NULL)
31 theStream << thePrefix;
33 theStream << std::setfill(' ') << std::setw (theWidth);
34 if (theValue >= 1000000000)
36 Standard_Real aValM = Standard_Real(theValue) / 1000000000.0;
37 theStream << std::fixed << std::setprecision (1) << aValM << "G";
39 else if (theValue >= 1000000)
41 Standard_Real aValM = Standard_Real(theValue) / 1000000.0;
42 theStream << std::fixed << std::setprecision (1) << aValM << "M";
44 else if (theValue >= 1000)
46 Standard_Real aValK = Standard_Real(theValue) / 1000.0;
47 theStream << std::fixed << std::setprecision (1) << aValK << "k";
51 theStream << theValue;
52 if (thePostfix == NULL)
57 if (thePostfix != NULL)
59 theStream << thePostfix;
64 //! Format a pair of counters.
65 static std::ostream& formatCounterPair (std::ostream& theStream,
66 Standard_Integer theWidth,
67 const char* thePrefix,
68 Standard_Size theValue,
69 Standard_Size theImmValue,
70 bool theToShowImmediate)
72 formatCounter (theStream, theWidth, thePrefix, theValue, NULL);
73 if (theToShowImmediate)
75 formatCounter (theStream, 1, "(", theImmValue, ")");
81 //! Format memory counter.
82 static std::ostream& formatBytes (std::ostream& theStream,
83 Standard_Integer theWidth,
84 const char* thePrefix,
85 Standard_Size theValue,
86 const char* thePostfix = NULL)
88 if (thePrefix != NULL)
90 theStream << thePrefix;
92 theStream << std::setfill(' ') << std::setw (theWidth);
93 if (theValue >= 1024 * 1024 * 1024)
95 Standard_Real aValM = Standard_Real(theValue) / (1024.0 * 1024.0 * 1024.0);
96 theStream << std::fixed << std::setprecision (1) << aValM << " GiB";
98 else if (theValue >= 1024 * 1024)
100 Standard_Real aValM = Standard_Real(theValue) / (1024.0 * 1024.0);
101 theStream << std::fixed << std::setprecision (1) << aValM << " MiB";
103 else if (theValue >= 1024)
105 Standard_Real aValK = Standard_Real(theValue) / 1024.0;
106 theStream << std::fixed << std::setprecision (1) << aValK << " KiB";
110 theStream << theValue << " B";
112 if (thePostfix != NULL)
114 theStream << thePostfix;
119 static const Standard_Real THE_SECONDS_IN_HOUR = 3600.0;
120 static const Standard_Real THE_SECONDS_IN_MINUTE = 60.0;
121 static const Standard_Real THE_SECOND_IN_HOUR = 1.0 / THE_SECONDS_IN_HOUR;
122 static const Standard_Real THE_SECOND_IN_MINUTE = 1.0 / THE_SECONDS_IN_MINUTE;
125 static std::ostream& formatTime (std::ostream& theStream,
126 Standard_Integer theWidth,
127 const char* thePrefix,
128 Standard_Real theSeconds,
129 const char* thePostfix = NULL)
131 if (thePrefix != NULL)
133 theStream << thePrefix;
136 Standard_Real aSecIn = theSeconds;
137 unsigned int aHours = (unsigned int )(aSecIn * THE_SECOND_IN_HOUR);
138 aSecIn -= Standard_Real(aHours) * THE_SECONDS_IN_HOUR;
139 unsigned int aMinutes = (unsigned int )(aSecIn * THE_SECOND_IN_MINUTE);
140 aSecIn -= Standard_Real(aMinutes) * THE_SECONDS_IN_MINUTE;
141 unsigned int aSeconds = (unsigned int )aSecIn;
142 aSecIn -= Standard_Real(aSeconds);
143 Standard_Real aMilliSeconds = 1000.0 * aSecIn;
146 theStream << std::setfill(' ') << std::setw (theWidth);
149 Sprintf (aBuffer, "%02u:%02u:%02u", aHours, aMinutes, aSeconds);
150 theStream << aBuffer;
152 else if (aMinutes > 0)
154 Sprintf (aBuffer, "%02u:%02u", aMinutes, aSeconds);
155 theStream << aBuffer;
157 else if (aSeconds > 0)
159 Sprintf (aBuffer, "%2u s", aSeconds);
160 theStream << aBuffer;
164 theStream << std::fixed << std::setprecision (1) << aMilliSeconds << " ms";
167 if (thePostfix != NULL)
169 theStream << thePostfix;
174 //! Add key-value pair to the dictionary.
175 static void addInfo (TColStd_IndexedDataMapOfStringString& theDict,
176 const TCollection_AsciiString& theKey,
177 const char* theValue)
179 TCollection_AsciiString aValue (theValue != NULL ? theValue : "");
180 theDict.ChangeFromIndex (theDict.Add (theKey, aValue)) = aValue;
183 //! Add key-value pair to the dictionary.
184 static void addInfo (TColStd_IndexedDataMapOfStringString& theDict,
185 const TCollection_AsciiString& theKey,
186 const Standard_Real theValue)
189 Sprintf (aTmp, "%.1g", theValue);
190 addInfo (theDict, theKey, aTmp);
193 //! Add key-value pair to the dictionary.
194 static void addInfo (TColStd_IndexedDataMapOfStringString& theDict,
195 const TCollection_AsciiString& theKey,
196 const Standard_Size theValue)
199 Sprintf (aTmp, "%zu", theValue);
200 addInfo (theDict, theKey, aTmp);
204 static void addTimeInfo (TColStd_IndexedDataMapOfStringString& theDict,
205 const TCollection_AsciiString& theKey,
206 Standard_Real theSeconds)
208 Standard_Real aSecIn = theSeconds;
209 unsigned int aHours = (unsigned int )(aSecIn * THE_SECOND_IN_HOUR);
210 aSecIn -= Standard_Real(aHours) * THE_SECONDS_IN_HOUR;
211 unsigned int aMinutes = (unsigned int )(aSecIn * THE_SECOND_IN_MINUTE);
212 aSecIn -= Standard_Real(aMinutes) * THE_SECONDS_IN_MINUTE;
213 unsigned int aSeconds = (unsigned int )aSecIn;
214 aSecIn -= Standard_Real(aSeconds);
215 Standard_Real aMilliSeconds = 1000.0 * aSecIn;
220 Sprintf (aBuffer, "%02u:%02u:%02u", aHours, aMinutes, aSeconds);
222 else if (aMinutes > 0)
224 Sprintf (aBuffer, "%02u:%02u", aMinutes, aSeconds);
226 else if (aSeconds > 0)
228 Sprintf (aBuffer, "%2u", aSeconds);
232 addInfo (theDict, theKey, aMilliSeconds);
236 addInfo (theDict, theKey, aBuffer);
240 // =======================================================================
241 // function : Graphic3d_FrameStats
243 // =======================================================================
244 Graphic3d_FrameStats::Graphic3d_FrameStats()
245 : myFpsTimer (Standard_True),
246 myFrameStartTime (0.0),
247 myFrameDuration (0.0),
248 myUpdateInterval (1.0),
251 myLastFrameIndex (0),
252 myIsLongLineFormat (Standard_False)
257 // =======================================================================
258 // function : ~Graphic3d_FrameStats
260 // =======================================================================
261 Graphic3d_FrameStats::~Graphic3d_FrameStats()
266 // =======================================================================
267 // function : FormatStats
269 // =======================================================================
270 TCollection_AsciiString Graphic3d_FrameStats::FormatStats (Graphic3d_RenderingParams::PerfCounters theFlags) const
272 const Standard_Integer aValWidth = 5;
273 std::stringstream aBuf;
274 const Standard_Boolean isCompact = theFlags == Graphic3d_RenderingParams::PerfCounters_FrameRate; // only FPS is displayed
275 const Graphic3d_FrameStatsData& aStats = LastDataFrame();
276 if (myIsLongLineFormat
277 && (theFlags & Graphic3d_RenderingParams::PerfCounters_FrameRate) != 0
278 && (theFlags & Graphic3d_RenderingParams::PerfCounters_CPU) != 0)
280 aBuf << "FPS: " << std::setfill(' ') << std::setw (isCompact ? aValWidth : 9) << std::fixed << std::setprecision (1) << aStats.FrameRate()
281 << " [CPU: " << std::setfill(' ') << std::setw (isCompact ? aValWidth : 10) << std::fixed << std::setprecision (1) << aStats.FrameRateCpu() << "]\n";
285 if ((theFlags & Graphic3d_RenderingParams::PerfCounters_FrameRate) != 0)
287 aBuf << "FPS: " << std::setfill(' ') << std::setw (isCompact ? aValWidth : aValWidth + 3) << std::fixed << std::setprecision (1) << aStats.FrameRate();
288 if (aStats.ImmediateFrameRate() > 0.0)
290 aBuf << " (" << std::fixed << std::setprecision (1) << aStats.ImmediateFrameRate() << ")";
294 if ((theFlags & Graphic3d_RenderingParams::PerfCounters_CPU) != 0)
296 aBuf << "CPU FPS: " << std::setfill(' ') << std::setw (isCompact ? aValWidth : aValWidth + 3) << std::fixed << std::setprecision (1) << aStats.FrameRateCpu();
297 if (aStats.ImmediateFrameRateCpu() > 0.0)
299 aBuf << " (" << std::fixed << std::setprecision (1) << aStats.ImmediateFrameRateCpu() << ")";
304 if ((theFlags & Graphic3d_RenderingParams::PerfCounters_Layers) != 0)
306 if (myIsLongLineFormat)
308 formatCounter (aBuf, aValWidth, "Layers: ", aStats[Graphic3d_FrameStatsCounter_NbLayers]);
309 if (HasCulledLayers())
311 formatCounter (aBuf, aValWidth, " [rendered: ", aStats[Graphic3d_FrameStatsCounter_NbLayersNotCulled], "]");
317 formatCounter (aBuf, aValWidth + 3, "Layers: ", aStats[Graphic3d_FrameStatsCounter_NbLayers], "\n");
320 if ((theFlags & Graphic3d_RenderingParams::PerfCounters_Structures) != 0)
322 if (myIsLongLineFormat)
324 formatCounter (aBuf, aValWidth, "Structs: ", aStats[Graphic3d_FrameStatsCounter_NbStructs]);
325 if (HasCulledStructs())
327 formatCounter (aBuf, aValWidth, " [rendered: ", aStats[Graphic3d_FrameStatsCounter_NbStructsNotCulled], "]");
333 formatCounter (aBuf, aValWidth + 3, "Structs: ", aStats[Graphic3d_FrameStatsCounter_NbStructs], "\n");
337 const bool hasImmediate = aStats[Graphic3d_FrameStatsCounter_NbLayersImmediate] != 0 || aStats.ImmediateFrameRate() > 0.0;
338 if ((theFlags & Graphic3d_RenderingParams::PerfCounters_Groups) != 0
339 || (theFlags & Graphic3d_RenderingParams::PerfCounters_GroupArrays) != 0
340 || (theFlags & Graphic3d_RenderingParams::PerfCounters_Triangles) != 0
341 || (theFlags & Graphic3d_RenderingParams::PerfCounters_Lines) != 0
342 || (theFlags & Graphic3d_RenderingParams::PerfCounters_Points) != 0
343 || (!myIsLongLineFormat
344 && ((theFlags & Graphic3d_RenderingParams::PerfCounters_Structures) != 0
345 || (theFlags & Graphic3d_RenderingParams::PerfCounters_Layers) != 0)))
349 aBuf << "Rendered (imm.)\n";
353 aBuf << "Rendered\n";
356 if (!myIsLongLineFormat
357 && (theFlags & Graphic3d_RenderingParams::PerfCounters_Layers) != 0)
359 formatCounterPair (aBuf, aValWidth, " Layers: ",
360 aStats[Graphic3d_FrameStatsCounter_NbLayersNotCulled],
361 aStats[Graphic3d_FrameStatsCounter_NbLayersImmediate], hasImmediate);
363 if (!myIsLongLineFormat
364 && (theFlags & Graphic3d_RenderingParams::PerfCounters_Structures) != 0)
366 formatCounterPair (aBuf, aValWidth, " Structs: ",
367 aStats[Graphic3d_FrameStatsCounter_NbStructsNotCulled],
368 aStats[Graphic3d_FrameStatsCounter_NbStructsImmediate], hasImmediate);
370 if ((theFlags & Graphic3d_RenderingParams::PerfCounters_Groups) != 0)
372 formatCounterPair (aBuf, aValWidth, " Groups: ",
373 aStats[Graphic3d_FrameStatsCounter_NbGroupsNotCulled],
374 aStats[Graphic3d_FrameStatsCounter_NbGroupsImmediate], hasImmediate);
376 if ((theFlags & Graphic3d_RenderingParams::PerfCounters_GroupArrays) != 0)
378 formatCounterPair (aBuf, aValWidth, " Arrays: ",
379 aStats[Graphic3d_FrameStatsCounter_NbElemsNotCulled],
380 aStats[Graphic3d_FrameStatsCounter_NbElemsImmediate], hasImmediate);
381 formatCounterPair (aBuf, aValWidth, " [fill]: ",
382 aStats[Graphic3d_FrameStatsCounter_NbElemsFillNotCulled],
383 aStats[Graphic3d_FrameStatsCounter_NbElemsFillImmediate], hasImmediate);
384 formatCounterPair (aBuf, aValWidth, " [line]: ",
385 aStats[Graphic3d_FrameStatsCounter_NbElemsLineNotCulled],
386 aStats[Graphic3d_FrameStatsCounter_NbElemsLineImmediate], hasImmediate);
387 formatCounterPair (aBuf, aValWidth, " [point]: ",
388 aStats[Graphic3d_FrameStatsCounter_NbElemsPointNotCulled],
389 aStats[Graphic3d_FrameStatsCounter_NbElemsPointImmediate], hasImmediate);
390 formatCounterPair (aBuf, aValWidth, " [text]: ",
391 aStats[Graphic3d_FrameStatsCounter_NbElemsTextNotCulled],
392 aStats[Graphic3d_FrameStatsCounter_NbElemsTextImmediate], hasImmediate);
394 if ((theFlags & Graphic3d_RenderingParams::PerfCounters_Triangles) != 0)
396 formatCounterPair (aBuf, aValWidth, " Triangles: ",
397 aStats[Graphic3d_FrameStatsCounter_NbTrianglesNotCulled],
398 aStats[Graphic3d_FrameStatsCounter_NbTrianglesImmediate], hasImmediate);
400 if ((theFlags & Graphic3d_RenderingParams::PerfCounters_Lines) != 0)
402 formatCounterPair (aBuf, aValWidth, " Lines: ",
403 aStats[Graphic3d_FrameStatsCounter_NbLinesNotCulled],
404 aStats[Graphic3d_FrameStatsCounter_NbLinesImmediate], hasImmediate);
406 if ((theFlags & Graphic3d_RenderingParams::PerfCounters_Points) != 0)
408 formatCounterPair (aBuf, aValWidth, " Points: ",
409 aStats[Graphic3d_FrameStatsCounter_NbPointsNotCulled],
410 aStats[Graphic3d_FrameStatsCounter_NbPointsImmediate], hasImmediate);
412 if ((theFlags & Graphic3d_RenderingParams::PerfCounters_EstimMem) != 0)
414 aBuf << "GPU Memory\n";
415 formatBytes (aBuf, aValWidth, " Geometry: ", aStats[Graphic3d_FrameStatsCounter_EstimatedBytesGeom], "\n");
416 formatBytes (aBuf, aValWidth, " Textures: ", aStats[Graphic3d_FrameStatsCounter_EstimatedBytesTextures], "\n");
417 formatBytes (aBuf, aValWidth, " Frames: ", aStats[Graphic3d_FrameStatsCounter_EstimatedBytesFbos], "\n");
420 if ((theFlags & Graphic3d_RenderingParams::PerfCounters_FrameTime) != 0)
422 aBuf << "Timers Average\n";
423 formatTime (aBuf, aValWidth, " Elapsed Frame: ", aStats[Graphic3d_FrameStatsTimer_ElapsedFrame], "\n");
424 formatTime (aBuf, aValWidth, " CPU Frame: ", aStats[Graphic3d_FrameStatsTimer_CpuFrame], "\n");
425 if (myCountersMax[Graphic3d_FrameStatsTimer_CpuPicking] > 0.0)
427 formatTime (aBuf, aValWidth, " CPU Picking: ", aStats[Graphic3d_FrameStatsTimer_CpuPicking], "\n");
429 if (myCountersMax[Graphic3d_FrameStatsTimer_CpuCulling] > 0.0)
431 formatTime (aBuf, aValWidth, " CPU Culling: ", aStats[Graphic3d_FrameStatsTimer_CpuCulling], "\n");
433 if (myCountersMax[Graphic3d_FrameStatsTimer_CpuDynamics])
435 formatTime (aBuf, aValWidth, " CPU Dynamics: ", aStats[Graphic3d_FrameStatsTimer_CpuDynamics], "\n");
437 if ((theFlags & Graphic3d_RenderingParams::PerfCounters_FrameTimeMax) != 0)
439 aBuf << "Timers Max\n";
440 formatTime (aBuf, aValWidth, " CPU Frame: ", myCountersMax[Graphic3d_FrameStatsTimer_CpuFrame], "\n");
441 if (myCountersMax[Graphic3d_FrameStatsTimer_CpuPicking] > 0.0)
443 formatTime (aBuf, aValWidth, " CPU Picking: ", myCountersMax[Graphic3d_FrameStatsTimer_CpuPicking], "\n");
445 if (myCountersMax[Graphic3d_FrameStatsTimer_CpuCulling] > 0.0)
447 formatTime (aBuf, aValWidth, " CPU Culling: ", myCountersMax[Graphic3d_FrameStatsTimer_CpuCulling], "\n");
449 if (myCountersMax[Graphic3d_FrameStatsTimer_CpuDynamics])
451 formatTime (aBuf, aValWidth, " CPU Dynamics: ", myCountersMax[Graphic3d_FrameStatsTimer_CpuDynamics], "\n");
456 return TCollection_AsciiString (aBuf.str().c_str());
459 // =======================================================================
460 // function : FormatStats
462 // =======================================================================
463 void Graphic3d_FrameStats::FormatStats (TColStd_IndexedDataMapOfStringString& theDict,
464 Graphic3d_RenderingParams::PerfCounters theFlags) const
466 const Graphic3d_FrameStatsData& aStats = LastDataFrame();
467 if ((theFlags & Graphic3d_RenderingParams::PerfCounters_FrameRate) != 0)
469 addInfo (theDict, "FPS", aStats.FrameRate());
471 if ((theFlags & Graphic3d_RenderingParams::PerfCounters_CPU) != 0)
473 addInfo (theDict, "CPU FPS", aStats.FrameRateCpu());
475 if ((theFlags & Graphic3d_RenderingParams::PerfCounters_Layers) != 0)
477 addInfo (theDict, "Layers", aStats[Graphic3d_FrameStatsCounter_NbLayers]);
478 if (HasCulledLayers())
480 addInfo (theDict, "Rendered layers", aStats[Graphic3d_FrameStatsCounter_NbLayersNotCulled]);
483 if ((theFlags & Graphic3d_RenderingParams::PerfCounters_Structures) != 0)
485 addInfo (theDict, "Structs", aStats[Graphic3d_FrameStatsCounter_NbStructs]);
486 if (HasCulledStructs())
488 addInfo (theDict, "Rendered structs", aStats[Graphic3d_FrameStatsCounter_NbStructsNotCulled]);
491 if ((theFlags & Graphic3d_RenderingParams::PerfCounters_Groups) != 0)
493 addInfo (theDict, "Rendered groups", aStats[Graphic3d_FrameStatsCounter_NbGroupsNotCulled]);
495 if ((theFlags & Graphic3d_RenderingParams::PerfCounters_GroupArrays) != 0)
497 addInfo (theDict, "Rendered arrays", aStats[Graphic3d_FrameStatsCounter_NbElemsNotCulled]);
498 addInfo (theDict, "Rendered [fill] arrays", aStats[Graphic3d_FrameStatsCounter_NbElemsFillNotCulled]);
499 addInfo (theDict, "Rendered [line] arrays", aStats[Graphic3d_FrameStatsCounter_NbElemsLineNotCulled]);
500 addInfo (theDict, "Rendered [point] arrays", aStats[Graphic3d_FrameStatsCounter_NbElemsPointNotCulled]);
501 addInfo (theDict, "Rendered [text] arrays", aStats[Graphic3d_FrameStatsCounter_NbElemsTextNotCulled]);
503 if ((theFlags & Graphic3d_RenderingParams::PerfCounters_Triangles) != 0)
505 addInfo (theDict, "Rendered triangles", aStats[Graphic3d_FrameStatsCounter_NbTrianglesNotCulled]);
507 if ((theFlags & Graphic3d_RenderingParams::PerfCounters_Lines) != 0)
509 addInfo (theDict, "Rendered lines", aStats[Graphic3d_FrameStatsCounter_NbLinesNotCulled]);
511 if ((theFlags & Graphic3d_RenderingParams::PerfCounters_Points) != 0)
513 addInfo (theDict, "Rendered points", aStats[Graphic3d_FrameStatsCounter_NbPointsNotCulled]);
515 if ((theFlags & Graphic3d_RenderingParams::PerfCounters_EstimMem) != 0)
517 addInfo (theDict, "GPU Memory [geometry]", aStats[Graphic3d_FrameStatsCounter_EstimatedBytesGeom]);
518 addInfo (theDict, "GPU Memory [textures]", aStats[Graphic3d_FrameStatsCounter_EstimatedBytesTextures]);
519 addInfo (theDict, "GPU Memory [frames]", aStats[Graphic3d_FrameStatsCounter_EstimatedBytesFbos]);
522 if ((theFlags & Graphic3d_RenderingParams::PerfCounters_FrameTime) != 0)
524 addTimeInfo (theDict, "Elapsed Frame (average)", aStats[Graphic3d_FrameStatsTimer_ElapsedFrame]);
525 addTimeInfo (theDict, "CPU Frame (average)", aStats[Graphic3d_FrameStatsTimer_CpuFrame]);
526 if (myCountersMax[Graphic3d_FrameStatsTimer_CpuPicking] > 0.0)
528 addTimeInfo (theDict, "CPU Picking (average)", aStats[Graphic3d_FrameStatsTimer_CpuPicking]);
530 if (myCountersMax[Graphic3d_FrameStatsTimer_CpuCulling] > 0.0)
532 addTimeInfo (theDict, "CPU Culling (average)", aStats[Graphic3d_FrameStatsTimer_CpuCulling]);
534 if (myCountersMax[Graphic3d_FrameStatsTimer_CpuDynamics])
536 addTimeInfo (theDict, "CPU Dynamics (average)", aStats[Graphic3d_FrameStatsTimer_CpuDynamics]);
538 if ((theFlags & Graphic3d_RenderingParams::PerfCounters_FrameTimeMax) != 0)
540 addTimeInfo (theDict, "CPU Frame (max)", myCountersMax[Graphic3d_FrameStatsTimer_CpuFrame]);
541 if (myCountersMax[Graphic3d_FrameStatsTimer_CpuPicking] > 0.0)
543 addTimeInfo (theDict, "CPU Picking (max)", myCountersMax[Graphic3d_FrameStatsTimer_CpuPicking]);
545 if (myCountersMax[Graphic3d_FrameStatsTimer_CpuCulling] > 0.0)
547 addTimeInfo (theDict, "CPU Culling (max)", myCountersMax[Graphic3d_FrameStatsTimer_CpuCulling]);
549 if (myCountersMax[Graphic3d_FrameStatsTimer_CpuDynamics])
551 addTimeInfo (theDict, "CPU Dynamics (max)", myCountersMax[Graphic3d_FrameStatsTimer_CpuDynamics]);
557 // =======================================================================
558 // function : FrameStart
560 // =======================================================================
561 void Graphic3d_FrameStats::FrameStart (const Handle(Graphic3d_CView)& theView,
562 bool theIsImmediateOnly)
564 const Graphic3d_RenderingParams::PerfCounters aBits = !theView.IsNull()
565 ? theView->RenderingParams().CollectedStats
566 : Graphic3d_RenderingParams::PerfCounters_NONE;
567 if (theIsImmediateOnly
568 && (aBits & Graphic3d_RenderingParams::PerfCounters_SkipImmediate) != 0)
573 const Standard_Integer aNbFrames = Max (!theView.IsNull()
574 ? theView->RenderingParams().StatsNbFrames
576 if (myCounters.Size() != aNbFrames)
578 myCounters.Resize (0, aNbFrames - 1, false);
579 myCounters.Init (Graphic3d_FrameStatsData());
580 myLastFrameIndex = myCounters.Upper();
583 // reset values at the end of frame (after data has been flushed),
584 // so that application can put some counters (like picking time) before FrameStart().
585 //myCountersTmp.Reset();
587 myFrameStartTime = myFpsTimer.ElapsedTime();
588 if (!myFpsTimer.IsStarted())
596 // =======================================================================
597 // function : FrameEnd
599 // =======================================================================
600 void Graphic3d_FrameStats::FrameEnd (const Handle(Graphic3d_CView)& theView,
601 bool theIsImmediateOnly)
603 const Graphic3d_RenderingParams::PerfCounters aBits = !theView.IsNull()
604 ? theView->RenderingParams().CollectedStats
605 : Graphic3d_RenderingParams::PerfCounters_NONE;
606 if (theIsImmediateOnly
607 && (aBits & Graphic3d_RenderingParams::PerfCounters_SkipImmediate) != 0)
612 const double aTime = myFpsTimer.ElapsedTime();
613 myFrameDuration = aTime - myFrameStartTime;
615 if (!theView.IsNull())
617 myUpdateInterval = theView->RenderingParams().StatsUpdateInterval;
620 if (aTime < myUpdateInterval)
622 myCountersTmp.FlushTimers (myFpsFrameCount, false);
626 const Graphic3d_FrameStatsData& aPrevFrame = myCounters.Value (myLastFrameIndex);
627 if (aTime > gp::Resolution())
631 const double aCpuSec = myFpsTimer.UserTimeCPU();
632 myCountersTmp[Graphic3d_FrameStatsTimer_ElapsedFrame] = aTime;
633 myCountersTmp[Graphic3d_FrameStatsTimer_CpuFrame] = aCpuSec;
635 if (theIsImmediateOnly)
637 myCountersTmp.ChangeImmediateFrameRate() = double(myFpsFrameCount) / aTime;
638 myCountersTmp.ChangeImmediateFrameRateCpu() = aCpuSec > gp::Resolution()
639 ? double(myFpsFrameCount) / aCpuSec
641 myCountersTmp.ChangeFrameRate() = aPrevFrame.FrameRate();
642 myCountersTmp.ChangeFrameRateCpu() = aPrevFrame.FrameRateCpu();
646 myCountersTmp.ChangeImmediateFrameRate() = -1.0;
647 myCountersTmp.ChangeImmediateFrameRateCpu() = -1.0;
648 myCountersTmp.ChangeFrameRate() = double(myFpsFrameCount) / aTime;
649 myCountersTmp.ChangeFrameRateCpu() = aCpuSec > gp::Resolution()
650 ? double(myFpsFrameCount) / aCpuSec
653 myCountersTmp.FlushTimers (myFpsFrameCount, true);
654 myCountersMax.FillMax (myCountersTmp);
660 // update structure counters
661 if (theView.IsNull())
663 myCounters.SetValue (myLastFrameIndex, myCountersTmp);
664 myCountersTmp.Reset();
668 updateStatistics (theView, theIsImmediateOnly);
670 if (++myLastFrameIndex > myCounters.Upper())
672 myLastFrameIndex = myCounters.Lower();
674 if (theIsImmediateOnly)
676 // copy rendered counters collected for immediate layers
677 const Standard_Integer anImmShift = Graphic3d_FrameStatsCounter_IMMEDIATE_LOWER - Graphic3d_FrameStatsCounter_RENDERED_LOWER;
678 Standard_STATIC_ASSERT((Graphic3d_FrameStatsCounter_RENDERED_UPPER - Graphic3d_FrameStatsCounter_RENDERED_LOWER) == (Graphic3d_FrameStatsCounter_IMMEDIATE_UPPER - Graphic3d_FrameStatsCounter_IMMEDIATE_LOWER))
679 for (Standard_Integer aCntIter = Graphic3d_FrameStatsCounter_RENDERED_LOWER; aCntIter <= Graphic3d_FrameStatsCounter_RENDERED_UPPER; ++aCntIter)
681 myCountersTmp.ChangeCounterValue ((Graphic3d_FrameStatsCounter )(aCntIter + anImmShift)) = myCountersTmp.CounterValue ((Graphic3d_FrameStatsCounter )aCntIter);
684 // copy main rendered counters from previous non-immediate frame
685 for (Standard_Integer aCntIter = Graphic3d_FrameStatsCounter_RENDERED_LOWER; aCntIter <= Graphic3d_FrameStatsCounter_RENDERED_UPPER; ++aCntIter)
687 myCountersTmp.ChangeCounterValue ((Graphic3d_FrameStatsCounter )aCntIter) = aPrevFrame.CounterValue ((Graphic3d_FrameStatsCounter )aCntIter);
689 myCountersTmp.ChangeCounterValue (Graphic3d_FrameStatsCounter_EstimatedBytesGeom) = aPrevFrame.CounterValue (Graphic3d_FrameStatsCounter_EstimatedBytesGeom);
691 myCounters.SetValue (myLastFrameIndex, myCountersTmp);
692 myCountersTmp.Reset();