VTK
vtkParallelTimer.h
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: vtkParallelTimer.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//
38#ifndef vtkParallelTimer_h
39#define vtkParallelTimer_h
40
41#define vtkParallelTimerDEBUG -1
42
43#include "vtkObject.h"
44#include "vtkRenderingParallelLICModule.h" // for export
45
46#include <vector> // for vector
47#include <string> // for string
48#include <sstream> // for sstream
49#if vtkParallelTimerDEBUG > 0
50#include <iostream> // for cerr
51#endif
52
53class vtkParallelTimerBuffer;
54
55class VTKRENDERINGPARALLELLIC_EXPORT vtkParallelTimer : public vtkObject
56{
57public:
60 void PrintSelf(ostream& os, vtkIndent indent);
61
63
68 {
69 public:
70 template<typename T> LogHeaderType &operator<<(const T& s);
71 };
73
75
80 {
81 public:
82 template<typename T> LogBodyType &operator<<(const T& s);
83 };
85
87
90 vtkSetMacro(WriterRank,int);
91 vtkGetMacro(WriterRank,int);
93
95
100 vtkSetStringMacro(FileName);
103
104 void SetFileName(const std::string &fileName)
105 { this->SetFileName(fileName.c_str()); }
106
108
116 void StartEvent(const char *event);
117 void StartEvent(int rank, const char *event);
118 void EndEvent(const char *event);
119 void EndEvent(int rank, const char *event);
120 void EndEventSynch(const char *event);
121 void EndEventSynch(int rank, const char *event);
123
127 template<typename T>
128 vtkParallelTimer &operator<<(const T& s);
129
135
141
145 void Clear();
146
155 void Update();
156
160 int Write();
161
170
174 static void DeleteGlobalInstance();
175
177
181 vtkSetMacro(WriteOnClose, int);
182 vtkGetMacro(WriteOnClose, int);
184
186
190 vtkSetMacro(GlobalLevel, int);
191 vtkGetMacro(GlobalLevel, int);
193
194protected:
197
198private:
199 vtkParallelTimer(const vtkParallelTimer&) VTK_DELETE_FUNCTION;
200 void operator=(const vtkParallelTimer&) VTK_DELETE_FUNCTION;
201
205 class VTKRENDERINGPARALLELLIC_EXPORT vtkParallelTimerDestructor
206 {
207 public:
208 vtkParallelTimerDestructor() : Log(0) {}
209 ~vtkParallelTimerDestructor();
210
211 void SetLog(vtkParallelTimer *log){ this->Log = log; }
212
213 private:
214 vtkParallelTimer *Log;
215 };
216
217private:
218 int GlobalLevel;
219 int Initialized;
220 int WorldRank;
221 int WriterRank;
222 char *FileName;
223 int WriteOnClose;
224 std::vector<double> StartTime;
225 #if vtkParallelTimerDEBUG < 0
226 std::vector<std::string> EventId;
227 #endif
228
229 vtkParallelTimerBuffer *Log;
230
231 static vtkParallelTimer *GlobalInstance;
232 static vtkParallelTimerDestructor GlobalInstanceDestructor;
233
234 std::ostringstream HeaderBuffer;
235
236 friend class LogHeaderType;
237 friend class LogBodyType;
238};
239
240//-----------------------------------------------------------------------------
241template<typename T>
243{
244 if (this->WorldRank == this->WriterRank)
245 {
246 this->HeaderBuffer << s;
247 #if vtkParallelTimerDEBUG > 0
248 std::cerr << s;
249 #endif
250 }
251 return *this;
252}
253
254//-----------------------------------------------------------------------------
255template<typename T>
257{
259
260 if (log->WorldRank == log->WriterRank)
261 {
262 log->HeaderBuffer << s;
263 #if vtkParallelTimerDEBUG > 0
264 std::cerr << s;
265 #endif
266 }
267
268 return *this;
269}
270
271//-----------------------------------------------------------------------------
272template<typename T>
274{
276
277 *(log->Log) << s;
278 #if vtkParallelTimerDEBUG > 0
279 std::cerr << s;
280 #endif
281
282 return *this;
283}
284
285#endif
a simple class to control print indentation
Definition: vtkIndent.h:40
friend VTKCOMMONCORE_EXPORT ostream & operator<<(ostream &os, vtkObjectBase &o)
abstract base class for most VTK objects
Definition: vtkObject.h:60
Type used to direct an output stream into the log's body.
LogBodyType & operator<<(const T &s)
Type used to direct an output stream into the log's header.
LogHeaderType & operator<<(const T &s)
Provides ditributed log functionality.
friend class LogBodyType
void Update()
When an object is finished writing data to the log object it must call Update to send the data to the...
int Write()
Write the log contents to a file.
void EndEventSynch(int rank, const char *event)
static vtkParallelTimer * GetGlobalInstance()
The log class implements the singleton patern so that it may be shared accross class boundaries.
void Clear()
Clear the log.
void EndEvent(int rank, const char *event)
static void DeleteGlobalInstance()
Explicitly delete the singleton.
void EndEventSynch(const char *event)
void StartEvent(int rank, const char *event)
void EndEvent(const char *event)
void SetFileName(const std::string &fileName)
vtkParallelTimer::LogBodyType GetBody()
stream output to log body(all ranks).
void PrintSelf(ostream &os, vtkIndent indent)
Methods invoked by print to print information about the object including superclasses.
static vtkParallelTimer * New()
virtual ~vtkParallelTimer()
friend class LogHeaderType
vtkParallelTimer::LogHeaderType GetHeader()
stream output to the log's header(root rank only).
void StartEvent(const char *event)
The log works as an event stack.
vtkParallelTimer & operator<<(const T &s)
Insert text into the log header on the writer rank.
@ string
Definition: vtkX3D.h:490
vtkSetMacro(IgnoreDriverBugs, bool)
Updates the extensions string.
vtkGetStringMacro(ExtensionsString)
Returns a string listing all available extensions.