1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394
|
/*=========================================================================
Program: Visualization Toolkit
Module: vtkRenderTimings.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkRenderTimings.h"
//#include "vtkNew.h"
#include "vtkAxis.h"
#include "vtkChartLegend.h"
#include "vtkChartXY.h"
#include "vtkContextScene.h"
#include "vtkContextView.h"
#include "vtkDelimitedTextWriter.h"
#include "vtkDoubleArray.h"
#include "vtkPlot.h"
#include "vtkTable.h"
#include "vtkRenderWindow.h"
void vtkRTTestSequence::GetSequenceNumbers(int &xdim)
{
static int linearSequence[] = {1, 2, 3, 5};
xdim = 1;
int sc = this->SequenceCount;
while (sc >= 4)
{
xdim *= 10;
sc -= 4;
}
xdim *= linearSequence[sc];
}
void vtkRTTestSequence::GetSequenceNumbers(int &xdim, int &ydim)
{
static int squareSequenceX[] = {1, 2, 3, 5, 5, 5, 6, 10};
static int squareSequenceY[] = {1, 1, 1, 1, 2, 4, 5, 5};
xdim = 1;
ydim = 1;
int sc = this->SequenceCount;
while (sc >= 8)
{
xdim *= 10;
ydim *= 10;
sc -= 8;
}
xdim *= squareSequenceX[sc];
ydim *= squareSequenceY[sc];
}
void vtkRTTestSequence::GetSequenceNumbers(int &xdim, int &ydim, int &zdim)
{
static int cubeSequenceX[] = {1, 2, 3, 5, 5, 5, 5, 5, 5, 8, 10, 10};
static int cubeSequenceY[] = {1, 1, 1, 1, 2, 2, 3, 5, 5, 5, 6, 10};
static int cubeSequenceZ[] = {1, 1, 1, 1, 1, 2, 2, 2, 4, 5, 5, 5};
xdim = 1;
ydim = 1;
zdim = 1;
int sc = this->SequenceCount;
while (sc >= 12)
{
xdim *= 10;
ydim *= 10;
zdim *= 10;
sc -= 12;
}
xdim *= cubeSequenceX[sc];
ydim *= cubeSequenceY[sc];
zdim *= cubeSequenceZ[sc];
}
void vtkRTTestSequence::GetSequenceNumbers(int &xdim, int &ydim, int &zdim, int &wdim)
{
static int sequenceX[] = {1, 2, 3, 5, 5, 5, 5, 5, 5, 5, 5, 5, 8, 10, 10, 10};
static int sequenceY[] = {1, 1, 1, 1, 2, 2, 3, 5, 5, 5, 5, 5, 5, 8, 10, 10};
static int sequenceZ[] = {1, 1, 1, 1, 1, 2, 2, 2, 2, 4, 4, 5, 5, 5, 6, 10};
static int sequenceW[] = {1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 3, 4, 5, 5, 5, 5};
xdim = 1;
ydim = 1;
zdim = 1;
wdim = 1;
int sc = this->SequenceCount;
while (sc >= 16)
{
xdim *= 10;
ydim *= 10;
zdim *= 10;
wdim *= 10;
sc -= 16;
}
xdim *= sequenceX[sc];
ydim *= sequenceY[sc];
zdim *= sequenceZ[sc];
wdim *= sequenceW[sc];
}
void vtkRTTestSequence::Run()
{
this->SequenceCount = this->RenderTimings->GetSequenceStart();
int sequenceEnd = this->RenderTimings->GetSequenceEnd();
this->Test->SetRenderSize(
this->RenderTimings->GetRenderWidth(),
this->RenderTimings->GetRenderHeight());
vtkNew<vtkContextView> chartView;
vtkNew<vtkChartXY> chart;
vtkNew<vtkTable> results;
vtkNew<vtkDoubleArray> summary;
vtkNew<vtkDoubleArray> secondSummary;
if (this->ChartResults)
{
// Set up our results table, this will be used for our timings etc.
summary->SetName(this->Test->GetSummaryResultName());
secondSummary->SetName(this->Test->GetSecondSummaryResultName());
results->AddColumn(secondSummary.Get());
results->AddColumn(summary.Get());
// Set up a chart to show the data being generated in real time.
chartView->GetRenderWindow()->SetSize(700, 500);
chartView->GetRenderWindow()->SetPosition(700, 0);
chartView->GetScene()->AddItem(chart.Get());
vtkPlot *plot = chart->AddPlot(vtkChart::LINE);
plot->SetInputData(results.Get(), 0, 1);
chart->GetAxis(vtkAxis::LEFT)->SetTitle(this->Test->GetSummaryResultName());
chart->GetAxis(vtkAxis::LEFT)->LogScaleOn();
chart->GetAxis(vtkAxis::BOTTOM)->SetTitle(this->Test->GetSecondSummaryResultName());
chart->GetAxis(vtkAxis::BOTTOM)->LogScaleOn();
results->SetNumberOfRows(100); // have to initialze this or it fails
}
double remainingTime = this->TargetTime;
double lastRunTime = 0.0;
int argc;
char **argv;
this->RenderTimings->GetArguments().GetUnusedArguments(&argc, &argv);
// while we have enough time remaning to do a 50% longer run
double stepLimit = this->RenderTimings->GetSequenceStepTimeLimit();
while (remainingTime > 1.5 * lastRunTime &&
(sequenceEnd == 0 || this->SequenceCount <= sequenceEnd) &&
lastRunTime < stepLimit)
{
double targetTime = remainingTime > stepLimit ? stepLimit : remainingTime;
double startTime = vtkTimerLog::GetUniversalTime();
this->Test->SetTargetTime(targetTime);
vtkRTTestResult tr = this->Test->Run(this, argc, argv);
tr.SequenceNumber = this->SequenceCount;
this->TestResults.push_back(tr);
if (this->ChartResults)
{
int numRows = this->SequenceCount -
this->RenderTimings->GetSequenceStart() + 1;
results->SetNumberOfRows(numRows);
results->SetValue(numRows-1, 0,
tr.Results[this->Test->GetSecondSummaryResultName()]);
results->SetValue(numRows-1, 1,
tr.Results[this->Test->GetSummaryResultName()]);
results->Modified();
if (numRows > 1)
{
chart->RecalculateBounds();
chartView->Render();
}
}
lastRunTime = vtkTimerLog::GetUniversalTime() - startTime;
remainingTime -= lastRunTime;
this->SequenceCount++;
}
}
void vtkRTTestSequence::ReportSummaryResults(ostream &ost)
{
double result = 0.0;
vtkRTTestResult *bestTestResult = NULL;
bool initialized = false;
std::vector<vtkRTTestResult>::iterator trItr;
for (trItr = this->TestResults.begin(); trItr != this->TestResults.end(); trItr++)
{
if (!initialized)
{
result = trItr->Results[this->Test->GetSummaryResultName()];
bestTestResult = &(*trItr);
initialized = true;
}
else
{
if (this->Test->UseLargestSummaryResult())
{
if (trItr->Results[this->Test->GetSummaryResultName()] > result)
{
result = trItr->Results[this->Test->GetSummaryResultName()];
bestTestResult = &(*trItr);
}
}
else
{
if (trItr->Results[this->Test->GetSummaryResultName()] < result)
{
result = trItr->Results[this->Test->GetSummaryResultName()];
bestTestResult = &(*trItr);
}
}
}
}
ost << this->Test->GetName() << ":" << bestTestResult->SequenceNumber
<< ": " << result << " " << this->Test->GetSummaryResultName()
<< " and " << static_cast<vtkIdType>(bestTestResult->Results[this->Test->GetSecondSummaryResultName()])
<< " " << this->Test->GetSecondSummaryResultName() << endl;
}
void vtkRTTestSequence::ReportDetailedResults(ostream &ost)
{
std::vector<vtkRTTestResult>::iterator trItr;
for (trItr = this->TestResults.begin(); trItr != this->TestResults.end(); trItr++)
{
ost << this->RenderTimings->GetSystemName() << ", ";
trItr->ReportResults(this->Test, ost);
}
}
vtkRenderTimings::vtkRenderTimings()
{
this->TargetTime = 600.0; // 10 minutes
vtksys::SystemInformation si;
si.RunOSCheck();
this->SystemName = si.GetOSDescription();
this->DisplayHelp = false;
this->ListTests = false;
this->NoChartResults = false;
this->SequenceStart = 0;
this->SequenceEnd = 0;
this->SequenceStepTimeLimit = 15.0; // seconds
this->DetailedResultsFileName = "results.csv";
this->RenderWidth = 600;
this->RenderHeight = 600;
}
int vtkRenderTimings::RunTests()
{
// what tests to run?
bool useRegex = false;
vtksys::RegularExpression re;
if (this->Regex.size())
{
useRegex = true;
re.compile(this->Regex);
}
size_t testCount = this->TestsToRun.size();
std::vector<vtkRTTest *>::iterator testItr;
if (useRegex)
{
testCount = 0;
for (testItr = this->TestsToRun.begin(); testItr != this->TestsToRun.end(); testItr++)
{
if (re.find((*testItr)->GetName()))
{
testCount++;
}
}
}
for (testItr = this->TestsToRun.begin(); testItr != this->TestsToRun.end(); testItr++)
{
if (!useRegex || re.find((*testItr)->GetName()))
{
vtkRTTestSequence *ats = new vtkRTTestSequence(this);
ats->SetChartResults(!this->NoChartResults);
ats->TargetTime = this->TargetTime/testCount;
ats->Test = *testItr;
ats->Run();
this->TestSequences.push_back(ats);
}
}
return 0;
}
void vtkRenderTimings::ReportResults()
{
// report the summary results to cout
cout << "Summary results: (detailed results written to " << this->DetailedResultsFileName << ")" << endl;
std::vector<vtkRTTestSequence *>::iterator tsItr;
for (tsItr = this->TestSequences.begin(); tsItr != this->TestSequences.end(); tsItr++)
{
(*tsItr)->ReportSummaryResults(cout);
}
// then the detailed to a csv file
ofstream rfile;
rfile.open (this->DetailedResultsFileName.c_str());
for (tsItr = this->TestSequences.begin(); tsItr != this->TestSequences.end(); tsItr++)
{
(*tsItr)->ReportDetailedResults(rfile);
}
rfile.close();
}
int vtkRenderTimings::ParseCommandLineArguments( int argc, char *argv[] )
{
this->Arguments.Initialize(argc, argv);
this->Arguments.StoreUnusedArguments(true);
typedef vtksys::CommandLineArguments argT;
this->Arguments.AddArgument("-rn", argT::SPACE_ARGUMENT, &this->DetailedResultsFileName,
"Specify where to write the detailed results to. Defaults to results.csv.");
this->Arguments.AddArgument("-regex", argT::SPACE_ARGUMENT, &this->Regex,
"Specify a regular expression for what tests should be run.");
this->Arguments.AddArgument("-tls", argT::SPACE_ARGUMENT,
&this->SequenceStepTimeLimit,
"Specify a maximum time in seconds allow for a sequence step. Once exceeded "
"the test sequence will terminate.");
this->Arguments.AddArgument("-tl", argT::SPACE_ARGUMENT, &this->TargetTime,
"Specify a target total amount of time for the tests to run. ");
this->Arguments.AddArgument("-platform", argT::SPACE_ARGUMENT, &this->SystemName,
"Specify a name for this platform. This is included in the output.");
this->Arguments.AddBooleanArgument("--help", &this->DisplayHelp,
"Provide a listing of command line options.");
this->Arguments.AddBooleanArgument("-help", &this->DisplayHelp,
"Provide a listing of command line options.");
this->Arguments.AddArgument("-ss", argT::SPACE_ARGUMENT, &this->SequenceStart,
"Specify a starting index for test sequences. Tests are designed to start at "
"a scale that can run on even very small systems. If you have a more powerful "
"system, you can use this option to skip the first few steps in the test "
"sequence. The sequence starts at zero and increases an order of magnitude "
"for every four steps");
this->Arguments.AddArgument("-se", argT::SPACE_ARGUMENT, &this->SequenceEnd,
"Specify an ending index for test sequences. Even if there is time remaining "
"a test sequence will not go beyond this value. You can combine this option "
"with -ss to run just one iteration of a sequece. For example you can "
"use -ss 6 -se 6 to only run the 6th sequence. A value of 0 means that "
"there is no limit (the time limit will still stop the tests).");
this->Arguments.AddBooleanArgument("-list", &this->ListTests,
"Provide a listing of available tests.");
this->Arguments.AddBooleanArgument("-nochart", &this->NoChartResults,
"Suppress realtime charting of test performance.");
this->Arguments.AddArgument("-width", argT::SPACE_ARGUMENT, &this->RenderWidth,
"Width of benchmark rendering window.");
this->Arguments.AddArgument("-height", argT::SPACE_ARGUMENT, &this->RenderHeight,
"Height of benchmark rendering window.");
if ( !this->Arguments.Parse() )
{
cerr << "Problem parsing arguments" << endl;
return 1;
}
if (this->DisplayHelp)
{
cerr << "Usage" << endl << endl << " VTKRenderTimings [options]" << endl << endl << "Options" << endl;
cerr << this->Arguments.GetHelp();
return 0;
}
if (this->ListTests)
{
bool useRegex = false;
vtksys::RegularExpression re;
if (this->Regex.size())
{
useRegex = true;
re.compile(this->Regex);
}
std::vector<vtkRTTest *>::iterator testItr;
for (testItr = this->TestsToRun.begin(); testItr != this->TestsToRun.end(); testItr++)
{
if (!useRegex || re.find((*testItr)->GetName()))
{
cerr << (*testItr)->GetName() << endl;
}
}
return 0;
}
// run the tests
cout << "Starting tests, maximum time allowed is " << this->TargetTime << " seconds." << endl;
this->RunTests();
this->ReportResults();
return 0;
}
|