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 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425
|
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Base header file. Must be first.
#include <xalanc/Include/PlatformDefinitions.hpp>
#include <cstdio>
#include <ctime>
#include <iostream>
#include <xercesc/util/PlatformUtils.hpp>
#include <xalanc/PlatformSupport/DOMStringHelper.hpp>
#include <xalanc/XalanTransformer/XalanTransformer.hpp>
#include <xalanc/Harness/XalanXMLFileReporter.hpp>
#include <xalanc/Harness/XalanFileUtility.hpp>
// This is here for memory leak testing.
#if !defined(NDEBUG) && defined(_MSC_VER)
#include <crtdbg.h>
#endif
using std::cerr;
using std::cout;
using std::endl;
const char* const excludeStylesheets[] =
{
"large-evans_large.xsl",
0
};
inline bool
checkForExclusion(const xalanc::XalanDOMString& currentFile)
{
for (int i=0; excludeStylesheets[i] != 0; i++)
{
if (currentFile == xalanc::XalanDOMString(excludeStylesheets[i]))
{
return true;
}
}
return false;
}
inline double
calculateElapsedTime(
clock_t theStartTime,
clock_t theEndTime)
{
return double(theEndTime - theStartTime) / CLOCKS_PER_SEC * 1000.0;
}
inline double
calculateAvgTime(
clock_t accTime,
long theIterationCount)
{
assert(theIterationCount > 1);
return double(accTime) / theIterationCount;
}
void
setHelp(xalanc::XalanFileUtility& h)
{
h.args.getHelpStream() << endl
<< "Perft dir [-out -sub -i -iter]"
<< endl
<< endl
<< "dir ( base directory for testcases)"
<< endl
<< "-out dir ( base directory for output)"
<< endl
<< "-sub dir ( run files only from a specific directory)"
<< endl
<< "-i ( include all testcases )"
<< endl
<< "-iter num (specifies number of iterations; must be > 0)"
<< endl;
}
int
runTests(
int argc,
char* argv[])
{
// Just hoist everything...
using namespace xalanc;
MemoryManager& theManager = XalanMemMgrs::getDefaultXercesMemMgr();
XalanFileUtility h(theManager);
// Set the program help string, then get the command line parameters.
//
setHelp(h);
bool setGold = false;
const XalanDOMString processorType("XalanC");
if (h.getParams(argc, argv, "PERFT-RESULTS", setGold) == true)
{
XalanTransformer xalan;
// Generate Unique Run id and processor info
XalanDOMString UniqRunid;
h.generateUniqRunid(UniqRunid);
// Defined basic constants for file manipulation and open results file
const XalanDOMString resultFilePrefix("cpp");
XalanDOMString resultsFile= h.args.output;
resultsFile += resultFilePrefix;
resultsFile += UniqRunid;
resultsFile += XalanFileUtility::s_xmlSuffix;
XalanXMLFileReporter logFile(theManager, resultsFile);
logFile.logTestFileInit("Performance Testing - Reports various performance metrics using the Transformer");
// Get the list of sub-directories below "base" and iterate through them
bool foundDir = false; // Flag indicates directory found. Used in conjunction with -sub cmd-line arg.
typedef XalanFileUtility::FileNameVectorType FileNameVectorType;
FileNameVectorType dirs;
h.getDirectoryNames(h.args.base, dirs);
for(FileNameVectorType::size_type j = 0; j < dirs.size(); j++)
{
// Run specific category of files from given directory
if (length(h.args.sub) > 0 && !equals(dirs[j], h.args.sub))
{
continue;
}
cout << "Processing files in Directory: " << dirs[j] << endl;
// Check that output directory is there.
XalanDOMString theOutputDir = h.args.output;
theOutputDir += dirs[j];
h.checkAndCreateDir(theOutputDir);
// Indicate that directory was processed and get test files from the directory
foundDir = true;
FileNameVectorType files;
h.getTestFileNames(h.args.base, dirs[j], false, files);
XalanDOMString logEntry;
logEntry = "Performance Directory: ";
logEntry += dirs[j];
logFile.logTestCaseInit(logEntry);
const long iterCount = h.args.iters;
for(FileNameVectorType::size_type i = 0; i < files.size(); i++)
{
// Define variables used for timing and reporting ...
clock_t startTime, endTime, accmTime, avgEtoe;
double timeinMilliseconds = 0, theAverage =0;
int transformResult = 0;
typedef XalanXMLFileReporter::Hashtable Hashtable;
Hashtable attrs(theManager);
attrs.insert(Hashtable::value_type(XalanDOMString("idref"), files[i]));
attrs.insert(Hashtable::value_type(XalanDOMString("UniqRunid"),UniqRunid));
attrs.insert(Hashtable::value_type(XalanDOMString("processor"),processorType));
logFile.addMetricToAttrs("Iterations",iterCount, attrs);
if (h.args.skip)
{
if (checkForExclusion(files[i]))
continue;
}
XalanDOMString theXSLFile = h.args.base;
theXSLFile += dirs[j];
theXSLFile += XalanFileUtility::s_pathSep;
theXSLFile += files[i];
XalanDOMString theXMLFile;
h.generateFileName(theXSLFile,"xml", theXMLFile);
XalanDOMString outbase = h.args.output;
outbase += dirs[j];
outbase += XalanFileUtility::s_pathSep;
outbase += files[i];
XalanDOMString theOutputFile;
h.generateFileName(outbase, "out", theOutputFile);
const XSLTInputSource xslInputSource(theXSLFile);
const XSLTInputSource xmlInputSource(theXMLFile);
const XSLTResultTarget theResultTarget(theOutputFile);
attrs.insert(Hashtable::value_type(XalanDOMString("href"), theXSLFile));
cout << endl << files[i] << endl;
// Time the parsing(compile) of the XSL stylesheet and report the results..
//
startTime = clock();
const XalanCompiledStylesheet* compiledSS = 0;
xalan.compileStylesheet(xslInputSource, compiledSS);
endTime = clock();
if (compiledSS == 0)
{
continue;
}
timeinMilliseconds = calculateElapsedTime(startTime, endTime);
cout << " XSL: " << timeinMilliseconds << " milliseconds, Parse" << endl;
logFile.addMetricToAttrs("parsexsl",timeinMilliseconds, attrs);
// Time the parsing of the input XML and report the results..
//
startTime = clock();
const XalanParsedSource* parsedSource = 0;
xalan.parseSource(xmlInputSource, parsedSource);
endTime = clock();
if (parsedSource == 0)
{
continue;
}
timeinMilliseconds = calculateElapsedTime(startTime, endTime);
cout << " XML: " << timeinMilliseconds << " milliseconds, Parse" <<endl;
logFile.addMetricToAttrs("parsexml",timeinMilliseconds, attrs);
// Perform One transform using parsed stylesheet and unparsed xml source, report results...
//
startTime = clock();
transformResult = xalan.transform(xmlInputSource, compiledSS, theResultTarget);
endTime = clock();
if(!transformResult)
{
timeinMilliseconds = calculateElapsedTime(startTime, endTime);
cout << endl << " One: " << timeinMilliseconds << " w/Parsed XSL." << endl;
logFile.addMetricToAttrs("single", timeinMilliseconds, attrs);
}
else
{
cout << xalan.getLastError();
return -1;
}
// Do One eTOe transform with no pre parsing of either xsl or xml files.
// And output metrics to console and result log
startTime = clock();
transformResult = xalan.transform(xmlInputSource, xslInputSource, theResultTarget);
endTime = clock();
if(!transformResult)
{
timeinMilliseconds = calculateElapsedTime(startTime, endTime);
cout << " One: " << timeinMilliseconds << " eTOe." << endl;
logFile.addMetricToAttrs("etoe", timeinMilliseconds, attrs);
}
else
{
cout << xalan.getLastError();
return -1;
}
// Perform multiple transforms and calculate the average time ..
// These are done 3 different ways.
//
// FIRST: Parsed XSL Stylesheet and Parsed XML Source.
//
accmTime = 0;
for(int j = 0; j < iterCount; ++j)
{
startTime = clock();
transformResult = xalan.transform(*parsedSource, compiledSS, theResultTarget);
endTime = clock();
accmTime += endTime - startTime;
}
theAverage = calculateAvgTime(accmTime, iterCount);
cout << endl << " Avg: " << theAverage << " for " << iterCount << " iter's w/Parsed files" << endl;
logFile.addMetricToAttrs("avgparsedxml",theAverage, attrs);
// SECOND: Parsed Stylesheet and UnParsed XML Source.
// This is currently how the XalanJ 2.0 is performing transforms
//
accmTime = 0;
for(int k = 0; k < iterCount; ++k)
{
startTime = clock();
transformResult = xalan.transform(xmlInputSource, compiledSS, theResultTarget);
endTime = clock();
accmTime += endTime - startTime;
}
theAverage = calculateAvgTime(accmTime, iterCount);
cout << " Avg: " << theAverage << " for " << iterCount << " iter's w/UnParsed XML" << endl;
logFile.addMetricToAttrs("avgunparsedxml",theAverage, attrs);
// THIRD: Neither Stylesheet nor XML Source are parsed.
// Perform multiple etoe transforms and calculate the average ...
//
avgEtoe = 0;
for(int jj = 0; jj < iterCount; ++jj)
{
startTime = clock();
transformResult = xalan.transform(xmlInputSource, xslInputSource, theResultTarget);
endTime = clock();
avgEtoe += endTime - startTime;
}
theAverage = calculateAvgTime(avgEtoe,iterCount);
// Output average transform time to console and result log
cout << " Avg: " << theAverage << " for " << iterCount << " iter's of eToe" << endl;
logFile.addMetricToAttrs("avgetoe",theAverage, attrs);
logFile.logElementWAttrs(10, "perf", attrs, "xxx");
xalan.destroyParsedSource(parsedSource);
xalan.destroyStylesheet(compiledSS);
}
logEntry = "Performance Directory: ";
logEntry += dirs[j];
logFile.logTestCaseClose(logEntry, XalanDOMString("Done"));
}
// Check to see if -sub cmd-line directory was processed correctly.
if (!foundDir)
{
cout << "Specified test directory: \"" << c_str(TranscodeToLocalCodePage(h.args.sub)) << "\" not found" << endl;
}
h.reportPassFail(logFile, UniqRunid);
logFile.logTestFileClose("Performance", "Done");
logFile.close();
}
return 0;
}
int
main(
int argc,
char* argv[])
{
#if !defined(NDEBUG) && defined(_MSC_VER)
_CrtSetDbgFlag(_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG) | _CRTDBG_LEAK_CHECK_DF);
_CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);
_CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
#endif
int theResult = 0;
try
{
using xercesc::XMLPlatformUtils;
using xalanc::XalanTransformer;
// Call the static initializers for xerces and xalan, and create a transformer
//
XMLPlatformUtils::Initialize();
XalanTransformer::initialize();
theResult = runTests(argc, argv);
XalanTransformer::terminate();
XMLPlatformUtils::Terminate();
XalanTransformer::ICUCleanUp();
}
catch(...)
{
cerr << "Initialization failed!" << endl << endl;
theResult = -1;
}
return theResult;
}
|