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 
178  ScopedEventLogger StartScopedEvent(const std::string &name);
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 
222  bool LoggingEnabled;
223  unsigned int FrameLimit;
224 
225 private:
226  vtkRenderTimerLog(const vtkRenderTimerLog&) = delete;
227  void operator=(const vtkRenderTimerLog&) = delete;
228 };
229 
230 #endif // vtkRenderTimerLog_h
float ElapsedTimeMilliseconds() const
abstract base class for most VTK objects
Definition: vtkObject.h:59
std::vector< Event > Events
vtkTypeUInt64 EndTime
Times are in nanoseconds.
ScopedEventLogger(vtkRenderTimerLog *log)
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 Print(std::ostream &os, float threshMs=0.f)
Print details of all events in this frame to a stream.
virtual bool IsSupported()
Returns true if stream timings are implemented for the current graphics backend.
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&#39;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 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&#39;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.