VTK  9.2.6
vtkRenderTimerLog.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkRenderTimerLog.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
15 
52 #ifndef vtkRenderTimerLog_h
53 #define vtkRenderTimerLog_h
54 
55 #include "vtkObject.h"
56 #include "vtkRenderingCoreModule.h" // For export macro
57 #include "vtkType.h" // For vtkTypeUint64, etc
58 #include <sstream> // for std::ostringstream
59 #include <string> // for std::string
60 #include <vector> // for std::vector
61 
66 #define VTK_SCOPED_RENDER_EVENT(eventName, timer) VTK_SCOPED_RENDER_EVENT2(eventName, timer, _event)
67 
73 #define VTK_SCOPED_RENDER_EVENT2(eventName, timer, identifier) \
74  vtkRenderTimerLog::ScopedEventLogger identifier; \
75  do \
76  { \
77  std::ostringstream _eventNameStream; \
78  _eventNameStream << eventName; \
79  identifier = timer->StartScopedEvent(_eventNameStream.str()); \
80  (void)identifier; /* Prevent set-but-not-used var warnings */ \
81  } while (false) /* Do-while loop prevents duplicate semicolon warnings */
82 
83 class VTKRENDERINGCORE_EXPORT vtkRenderTimerLog : public vtkObject
84 {
85 public:
86  struct Frame;
87 
89  struct VTKRENDERINGCORE_EXPORT Event
90  {
93 
95  vtkTypeUInt64 StartTime;
96  vtkTypeUInt64 EndTime;
100  float ElapsedTimeSeconds() const { return this->ElapsedTimeNanoseconds() * 1e-9f; }
101  float ElapsedTimeMilliseconds() const { return this->ElapsedTimeNanoseconds() * 1e-6f; }
102  vtkTypeUInt64 ElapsedTimeNanoseconds() const { return this->EndTime - this->StartTime; }
103 
105  std::vector<Event> Events;
106 
112  void Print(std::ostream& os, float threshMs = 0.f, vtkIndent indent = vtkIndent())
113  {
114  this->Print(os, 0.f, threshMs, indent);
115  }
116 
118 
119  protected:
120  void Print(std::ostream& os, float parentTime, float threshMs, vtkIndent indent);
121  };
122 
124  struct VTKRENDERINGCORE_EXPORT Frame
125  {
126  std::vector<Event> Events;
127 
132  void Print(std::ostream& os, float threshMs = 0.f);
133  };
134 
140  struct VTKRENDERINGCORE_EXPORT ScopedEventLogger
141  {
143  : Log(nullptr)
144  {
145  }
146  ScopedEventLogger(ScopedEventLogger&& other) noexcept;
147  ScopedEventLogger& operator=(ScopedEventLogger&& other) noexcept;
148  ~ScopedEventLogger() { this->Stop(); }
149  void Stop();
150  friend class vtkRenderTimerLog;
151 
152  protected:
154  : Log(log)
155  {
156  }
157 
158  private:
159  void operator=(const ScopedEventLogger&) = delete;
160  ScopedEventLogger(const ScopedEventLogger& other) = delete;
161  vtkRenderTimerLog* Log;
162  };
163 
164  static vtkRenderTimerLog* New();
165  vtkTypeMacro(vtkRenderTimerLog, vtkObject);
166  void PrintSelf(ostream& os, vtkIndent indent) override;
167 
172  virtual bool IsSupported() VTK_FUTURE_CONST;
173 
178  virtual void MarkFrame();
179 
183  ScopedEventLogger StartScopedEvent(const std::string& name);
184 
188  virtual void MarkStartEvent(const std::string& name);
189  virtual void MarkEndEvent();
195  virtual bool FrameReady();
196 
201  virtual Frame PopFirstReadyFrame();
202 
204  vtkSetMacro(LoggingEnabled, bool);
205  vtkGetMacro(LoggingEnabled, bool);
206  vtkBooleanMacro(LoggingEnabled, bool);
214  vtkSetMacro(FrameLimit, unsigned int);
215  vtkGetMacro(FrameLimit, unsigned int);
221  virtual void ReleaseGraphicsResources();
222 
223 protected:
225  ~vtkRenderTimerLog() override;
226 
227  mutable bool LoggingEnabled;
228  unsigned int FrameLimit;
229 
230 private:
231  vtkRenderTimerLog(const vtkRenderTimerLog&) = delete;
232  void operator=(const vtkRenderTimerLog&) = delete;
233 };
234 
235 #endif // vtkRenderTimerLog_h
float ElapsedTimeMilliseconds() const
abstract base class for most VTK objects
Definition: vtkObject.h:62
std::vector< Event > Events
vtkTypeUInt64 EndTime
Times are in nanoseconds.
ScopedEventLogger(vtkRenderTimerLog *log)
void Print(const std::vector< T > &input, const std::string &name)
Print a vector with an associated name.
virtual void MarkFrame()
Call to mark the start of a new frame, or the end of an old one.
ScopedEventLogger StartScopedEvent(const std::string &name)
Create a RAII scoped event.
static vtkRenderTimerLog * New()
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
a simple class to control print indentation
Definition: vtkIndent.h:39
void Print(std::ostream &os, float threshMs=0.f, vtkIndent indent=vtkIndent())
Print details of the event to a stream.
Container for a frame's events.
virtual void MarkStartEvent(const std::string &name)
Mark the beginning or end of an event.
vtkTypeUInt64 ElapsedTimeNanoseconds() const
virtual void MarkEndEvent()
Mark the beginning or end of an event.
vtkTypeUInt64 StartTime
Times are in nanoseconds.
virtual bool IsSupported() VTK_FUTURE_CONST
Returns true if stream timings are implemented for the current graphics backend.
virtual bool FrameReady()
Returns true if there are any frames ready with complete timing info.
RAII struct for logging events.
virtual void ReleaseGraphicsResources()
Releases any resources allocated on the graphics device.
float ElapsedTimeSeconds() const
Convenience methods to compute times.
std::string Name
Event name.
virtual Frame PopFirstReadyFrame()
Retrieve the first available frame's timing info.
Container for a single timed event.
std::vector< Event > Events
Child events that occurred while this event was running.
unsigned int FrameLimit
Asynchronously measures GPU execution times for a series of events.