VTK
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 
49 #ifndef vtkRenderTimerLog_h
50 #define vtkRenderTimerLog_h
51 
52 #include "vtkObject.h"
53 #include "vtkRenderingCoreModule.h" // For export macro
54 #include "vtkType.h" // For vtkTypeUint64, etc
55 #include <sstream> // for std::ostringstream
56 #include <string> // for std::string
57 #include <vector> // for std::vector
58 
63 #define VTK_SCOPED_RENDER_EVENT(eventName, timer) \
64  VTK_SCOPED_RENDER_EVENT2(eventName, timer, _event)
65 
71 #define VTK_SCOPED_RENDER_EVENT2(eventName, timer, identifier) \
72  vtkRenderTimerLog::ScopedEventLogger identifier; \
73  do \
74  { \
75  std::ostringstream _eventNameStream; \
76  _eventNameStream << eventName; \
77  identifier = timer->StartScopedEvent(_eventNameStream.str()); \
78  (void)identifier; /* Prevent set-but-not-used var warnings */ \
79  } while (false) /* Do-while loop prevents duplicate semicolon warnings */
80 
81 class VTKRENDERINGCORE_EXPORT vtkRenderTimerLog : public vtkObject
82 {
83 public:
84  struct Frame;
85 
87  struct VTKRENDERINGCORE_EXPORT Event
88  {
91 
93  vtkTypeUInt64 StartTime;
94  vtkTypeUInt64 EndTime;
98  float ElapsedTimeSeconds() const
99  { return this->ElapsedTimeNanoseconds() * 1e-9f; }
101  { return this->ElapsedTimeNanoseconds() * 1e-6f; }
102  vtkTypeUInt64 ElapsedTimeNanoseconds() const
103  { return this->EndTime - this->StartTime; }
104 
106  std::vector<Event> Events;
107 
113  void Print(std::ostream &os, float threshMs = 0.f,
114  vtkIndent indent = vtkIndent())
115  {
116  this->Print(os, 0.f, threshMs, indent);
117  }
118 
120 
121  protected:
122  void Print(std::ostream &os, float parentTime, float threshMs,
123  vtkIndent indent);
124  };
125 
127  struct VTKRENDERINGCORE_EXPORT Frame
128  {
129  std::vector<Event> Events;
130 
135  void Print(std::ostream &os, float threshMs = 0.f);
136  };
137 
143  struct VTKRENDERINGCORE_EXPORT ScopedEventLogger
144  {
145  ScopedEventLogger() : Log(nullptr) {}
147  ScopedEventLogger& operator=(ScopedEventLogger &&other);
148  ~ScopedEventLogger() { this->Stop(); }
149  void Stop();
150  friend class vtkRenderTimerLog;
151  protected:
153  private:
154  void operator=(const ScopedEventLogger&) = delete;
155  ScopedEventLogger(const ScopedEventLogger &other) = delete;
156  vtkRenderTimerLog *Log;
157  };
158 
159  static vtkRenderTimerLog* New();
161  void PrintSelf(ostream &os, vtkIndent indent) override;
162 
167  virtual bool IsSupported();
168 
173  virtual void MarkFrame();
174 
179 
183  virtual void MarkStartEvent(const std::string &name);
184  virtual void MarkEndEvent();
190  virtual bool FrameReady();
191 
196  virtual Frame PopFirstReadyFrame();
197 
199  vtkSetMacro(LoggingEnabled, bool)
200  vtkGetMacro(LoggingEnabled, bool)
201  vtkBooleanMacro(LoggingEnabled, bool)
209  vtkSetMacro(FrameLimit, unsigned int)
210  vtkGetMacro(FrameLimit, unsigned int)
216  virtual void ReleaseGraphicsResources();
217 
218 protected:
220  ~vtkRenderTimerLog() override;
221 
223  unsigned int FrameLimit;
224 
225 private:
226  vtkRenderTimerLog(const vtkRenderTimerLog&) = delete;
227  void operator=(const vtkRenderTimerLog&) = delete;
228 };
229 
230 #endif // vtkRenderTimerLog_h
vtkRenderTimerLog::Event::StartTime
vtkTypeUInt64 StartTime
Times are in nanoseconds.
Definition: vtkRenderTimerLog.h:93
vtkRenderTimerLog::Frame::Events
std::vector< Event > Events
Definition: vtkRenderTimerLog.h:129
vtkRenderTimerLog::Event::Name
std::string Name
Event name.
Definition: vtkRenderTimerLog.h:90
vtkRenderTimerLog::Event::ElapsedTimeSeconds
float ElapsedTimeSeconds() const
Convenience methods to compute times.
Definition: vtkRenderTimerLog.h:98
vtkRenderTimerLog::Event::ElapsedTimeNanoseconds
vtkTypeUInt64 ElapsedTimeNanoseconds() const
Definition: vtkRenderTimerLog.h:102
vtkRenderTimerLog::MarkFrame
virtual void MarkFrame()
Call to mark the start of a new frame, or the end of an old one.
vtkRenderTimerLog::Event::ElapsedTimeMilliseconds
float ElapsedTimeMilliseconds() const
Definition: vtkRenderTimerLog.h:100
vtkRenderTimerLog::ScopedEventLogger::~ScopedEventLogger
~ScopedEventLogger()
Definition: vtkRenderTimerLog.h:148
vtkRenderTimerLog::StartScopedEvent
ScopedEventLogger StartScopedEvent(const std::string &name)
Create a RAII scoped event.
vtkObject
abstract base class for most VTK objects
Definition: vtkObject.h:59
vtkRenderTimerLog::Event::Print
void Print(std::ostream &os, float threshMs=0.f, vtkIndent indent=vtkIndent())
Print details of the event to a stream.
Definition: vtkRenderTimerLog.h:113
vtkRenderTimerLog::Frame::Print
void Print(std::ostream &os, float threshMs=0.f)
Print details of all events in this frame to a stream.
vtkRenderTimerLog::LoggingEnabled
bool LoggingEnabled
Definition: vtkRenderTimerLog.h:222
vtkType.h
vtkRenderTimerLog::New
static vtkRenderTimerLog * New()
vtkRenderTimerLog::vtkRenderTimerLog
vtkRenderTimerLog()
vtkRenderTimerLog::IsSupported
virtual bool IsSupported()
Returns true if stream timings are implemented for the current graphics backend.
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:39
vtkRenderTimerLog::MarkEndEvent
virtual void MarkEndEvent()
Mark the beginning or end of an event.
vtkRenderTimerLog::ScopedEventLogger::ScopedEventLogger
ScopedEventLogger(vtkRenderTimerLog *log)
Definition: vtkRenderTimerLog.h:152
vtkRenderTimerLog::ReleaseGraphicsResources
virtual void ReleaseGraphicsResources()
Releases any resources allocated on the graphics device.
vtkRenderTimerLog::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkRenderTimerLog::MarkStartEvent
virtual void MarkStartEvent(const std::string &name)
Mark the beginning or end of an event.
vtkX3D::name
Definition: vtkX3D.h:219
vtkObject.h
vtkRenderTimerLog::Frame
Container for a frame's events.
Definition: vtkRenderTimerLog.h:127
vtkRenderTimerLog::Event::EndTime
vtkTypeUInt64 EndTime
Times are in nanoseconds.
Definition: vtkRenderTimerLog.h:94
vtkRenderTimerLog
Asynchronously measures GPU execution times for a series of events.
Definition: vtkRenderTimerLog.h:81
vtkRenderTimerLog::PopFirstReadyFrame
virtual Frame PopFirstReadyFrame()
Retrieve the first available frame's timing info.
vtkRenderTimerLog::ScopedEventLogger::ScopedEventLogger
ScopedEventLogger()
Definition: vtkRenderTimerLog.h:145
vtkX3D::string
Definition: vtkX3D.h:490
vtkRenderTimerLog::FrameReady
virtual bool FrameReady()
Returns true if there are any frames ready with complete timing info.
vtkRenderTimerLog::ScopedEventLogger
RAII struct for logging events.
Definition: vtkRenderTimerLog.h:143
vtkRenderTimerLog::Event
Container for a single timed event.
Definition: vtkRenderTimerLog.h:87
vtkRenderTimerLog::Event::Events
std::vector< Event > Events
Child events that occurred while this event was running.
Definition: vtkRenderTimerLog.h:106
vtkRenderTimerLog::FrameLimit
unsigned int FrameLimit
Definition: vtkRenderTimerLog.h:223
vtkRenderTimerLog::~vtkRenderTimerLog
~vtkRenderTimerLog() override