1 /*=========================================================================
2 
3   Program:   Visualization Toolkit
4   Module:    VTKRenderTimings.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 
16 #ifndef vtkRenderTimings_h
17 #define vtkRenderTimings_h
18 
19 /**
20  * Define the classes we use for running timing benchmarks
21  */
22 
23 #include "vtkTimerLog.h"
24 #include "vtkUtilitiesBenchmarksModule.h"
25 #include <map>
26 #include <vtksys/CommandLineArguments.hxx>
27 
28 class vtkRTTestResult;
29 class vtkRTTestSequence;
30 class vtkRenderTimings;
31 
32 class VTKUTILITIESBENCHMARKS_EXPORT vtkRTTest
33 {
34 public:
35   // what is the name of this test
GetName()36   std::string GetName() { return this->Name; }
37 
38   // when reporting a summary result use this key to
39   // determine the amount of triangles rendered
40   virtual const char* GetSecondSummaryResultName() = 0;
41 
42   // when reporting a summary result this is the
43   // field that should be reported.
44   virtual const char* GetSummaryResultName() = 0;
45 
46   // when reporting a summary result should we use the
47   // largest value or smallest?
UseLargestSummaryResult()48   virtual bool UseLargestSummaryResult() { return true; }
49 
50   // Set/Get the time allowed for this test
51   // Tests should check if they are going more than 50%
52   // beyond this number they should short circuit if
53   // they can gracefully.
SetTargetTime(float tt)54   virtual void SetTargetTime(float tt) { this->TargetTime = tt; }
GetTargetTime()55   virtual float GetTargetTime() { return this->TargetTime; }
56 
SetRenderSize(int width,int height)57   void SetRenderSize(int width, int height)
58   {
59     this->RenderWidth = width;
60     this->RenderHeight = height;
61   }
GetRenderWidth()62   int GetRenderWidth() { return this->RenderWidth; }
GetRenderHeight()63   int GetRenderHeight() { return this->RenderHeight; }
64 
65   // run the test, argc and argv are extra arguments that the test might
66   // use.
67   virtual vtkRTTestResult Run(vtkRTTestSequence* ats, int argc, char* argv[]) = 0;
68 
vtkRTTest(const char * name)69   vtkRTTest(const char* name)
70   {
71     this->TargetTime = 1.0;
72     this->Name = name;
73     RenderWidth = RenderHeight = 600;
74   }
75 
~vtkRTTest()76   virtual ~vtkRTTest() {}
77 
78 protected:
79   float TargetTime;
80   std::string Name;
81   int RenderWidth, RenderHeight;
82 };
83 
84 class VTKUTILITIESBENCHMARKS_EXPORT vtkRTTestResult
85 {
86 public:
87   std::map<std::string, double> Results;
88   int SequenceNumber;
ReportResults(vtkRTTest * test,ostream & ost)89   void ReportResults(vtkRTTest* test, ostream& ost)
90   {
91     ost << test->GetName();
92     std::map<std::string, double>::iterator rItr;
93     for (rItr = this->Results.begin(); rItr != this->Results.end(); ++rItr)
94     {
95       ost << ", " << rItr->first << ", " << rItr->second;
96     }
97     ost << "\n";
98   }
99 };
100 
101 class VTKUTILITIESBENCHMARKS_EXPORT vtkRTTestSequence
102 {
103 public:
104   virtual void Run();
105   virtual void ReportSummaryResults(ostream& ost);
106   virtual void ReportDetailedResults(ostream& ost);
107 
108   // tests should use these functions to determine what resolution
109   // to use in scaling their test. The functions will always return
110   // numbers then when multiplied will result in 1, 2, 3, or 5
111   // times 10 to some power. These functions use the SequenceCount
112   // to determine what number to return. When the dimensions
113   // are not equal, we guarantee that the larger dimensions
114   // come first
115   void GetSequenceNumbers(int& xdim);
116   void GetSequenceNumbers(int& xdim, int& ydim);
117   void GetSequenceNumbers(int& xdim, int& ydim, int& zdim);
118   void GetSequenceNumbers(int& xdim, int& ydim, int& zdim, int& wdim);
119 
120   // display the results in realtime using VTK charting
SetChartResults(bool v)121   void SetChartResults(bool v) { this->ChartResults = v; }
122 
123   vtkRTTest* Test;
124   float TargetTime;
125 
vtkRTTestSequence(vtkRenderTimings * rt)126   vtkRTTestSequence(vtkRenderTimings* rt)
127   {
128     this->Test = NULL;
129     this->TargetTime = 10.0;
130     this->RenderTimings = rt;
131     this->ChartResults = true;
132   }
133 
~vtkRTTestSequence()134   virtual ~vtkRTTestSequence() {}
135 
136 protected:
137   std::vector<vtkRTTestResult> TestResults;
138   int SequenceCount;
139   vtkRenderTimings* RenderTimings;
140   bool ChartResults;
141 };
142 
143 // a class to run a bunch of timing tests and
144 // report the results
145 class VTKUTILITIESBENCHMARKS_EXPORT vtkRenderTimings
146 {
147 public:
148   vtkRenderTimings();
149 
150   // get the sequence start and end values
GetSequenceStart()151   int GetSequenceStart() { return this->SequenceStart; }
GetSequenceEnd()152   int GetSequenceEnd() { return this->SequenceEnd; }
153 
154   // get the maxmimum time allowed per step
GetSequenceStepTimeLimit()155   double GetSequenceStepTimeLimit() { return this->SequenceStepTimeLimit; }
156 
157   // get the render size
GetRenderWidth()158   int GetRenderWidth() { return this->RenderWidth; }
GetRenderHeight()159   int GetRenderHeight() { return this->RenderHeight; }
160 
161   // parse and act on the command line arguments
162   int ParseCommandLineArguments(int argc, char* argv[]);
163 
164   // get the arguments
GetArguments()165   vtksys::CommandLineArguments& GetArguments() { return this->Arguments; }
166 
GetSystemName()167   std::string GetSystemName() { return this->SystemName; }
168 
169   std::vector<vtkRTTest*> TestsToRun;
170   std::vector<vtkRTTestSequence*> TestSequences;
171 
172 protected:
173   int RunTests();
174   void ReportResults();
175 
176 private:
177   std::string Regex; // regular expression for tests
178   double TargetTime;
179   std::string SystemName;
180   vtksys::CommandLineArguments Arguments;
181   bool DisplayHelp;
182   bool ListTests;
183   bool NoChartResults;
184   int SequenceStart;
185   int SequenceEnd;
186   double SequenceStepTimeLimit;
187   std::string DetailedResultsFileName;
188   int RenderWidth;
189   int RenderHeight;
190 };
191 
192 #endif
193 // VTK-HeaderTest-Exclude: vtkRenderTimings.h
194