DS_ElapsedTime::DS_ElapsedTime() { stop(); calculateElapsedTime(); connect (DS_Timers::getInstance(), SIGNAL (timeout100()), this, SLOT (calculateElapsedTime())); }
int DeviceDriver::checkForTimerEvents(ClientReporter *r) { int status; int result = ESUCCESS; for (int lun = 0; lun < logicalUnitCount; lun++) { LogicalUnitInfo *currentUnit = logicalUnits[lun]; if (currentUnit != 0) { for (int timer = 0; timer < 2; timer++) { if (currentUnit->intervalTime[timer] > 0) { currentUnit->deltaTime[timer] = calculateElapsedTime(currentUnit, timer); if (currentUnit->deltaTime[timer] >= currentUnit->intervalTime[timer]) { status = this->processTimerEvent(lun, timer, r); currentUnit->previousTime[timer] = currentUnit->currentTime[timer]; result = (status == ESUCCESS) ? result : status; } } } } } return result; }
int runTests( int argc, char* argv[]) { // Just hoist everything... XALAN_CPP_NAMESPACE_USE MemoryManagerType& 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(XALAN_STATIC_UCODE_STRING("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; }
void vehicle() { //calculate interval between vehicle spawns, in seconds float nextVehicleSpawnTime = (rand() % maxTimeBetweenArrivals) / 1000.f; struct timeval timeOfLastVehicleSpawn; gettimeofday(&timeOfLastVehicleSpawn, 0); int vehicleId = 1; while(1) { if(msgrcv(idMessageFromCaptain, &message, messageLength, EXIT, IPC_NOWAIT) != -1) { printf("Terminated\n"); //captain says kill program, send acknowledgement msgsnd(idMessageVehicleToCaptain, &message, messageLength, 0); return; } float elapsedTimeSinceLastSpawn = calculateElapsedTime(timeOfLastVehicleSpawn); //check if its time to spawn a vehicle if(elapsedTimeSinceLastSpawn > nextVehicleSpawnTime) { //determine whether we should spawn a truck or a car int spawnNumber = rand() % 100 + 1; message.vehicleId = vehicleId++; //spawn a truck if(spawnNumber <= probabiltyOfTruckArriving) { //place truck in arrival lane message.mtype = TRUCK_IN_ARRIVAL_QUEUE; msgsnd(idMessageVehicleArrivalQueue, &message, messageLength, 0); printf("Truck number %d has arrived at the dock.\n", message.vehicleId); } else {//spawn a car message.mtype = CAR_IN_ARRIVAL_QUEUE; msgsnd(idMessageVehicleArrivalQueue, &message, messageLength, 0); printf("Car number %d has arrived at the dock.\n", message.vehicleId); } nextVehicleSpawnTime = (rand() % maxTimeBetweenArrivals) / 1000.f; gettimeofday(&timeOfLastVehicleSpawn, 0); } //check if captain wants ferry to load if(msgrcv(idMessageFromCaptain, &message, messageLength, FERRY_READY_TO_LOAD, IPC_NOWAIT) != -1) { //move all vehicles to loading queue while(msgrcv(idMessageVehicleArrivalQueue, &message, messageLength, TRUCK_IN_ARRIVAL_QUEUE, IPC_NOWAIT) != -1) { message.mtype = TRUCK_READY_TO_LOAD; msgsnd(idMessageVehicleLoadingQueue, &message, messageLength, 0); printf("Truck number %d is ready for loading.\n", message.vehicleId); } while(msgrcv(idMessageVehicleArrivalQueue, &message, messageLength, CAR_IN_ARRIVAL_QUEUE, IPC_NOWAIT) != -1) { message.mtype = CAR_READY_TO_LOAD; msgsnd(idMessageVehicleLoadingQueue, &message, messageLength, 0); printf("Car number %d is ready for loading.\n", message.vehicleId); } printf("Swapping arrival queue and late arrival queue.\n"); /*swap the arrival queue and the late arrival queue. the queues are swaped here, instead of after the ferry finishes loading because if a vehicle arrives while the ferry is loading it needs to go to the late arrival queue, which means a separate flag needs to be checked when a vehicle arrives in order to determine if the vehicle should be placed into the arrival queue, or the late arrival queue. if we swap the queues here then we can always put new vehicles in the arrival queue since late arrivals automatically end up in an empty queue*/ int temp = idMessageVehicleArrivalQueue; idMessageVehicleArrivalQueue = idMessageVehicleLateArrivalQueue; idMessageVehicleLateArrivalQueue = temp; //tell captain vehicles are ready for loading message.mtype = FERRY_READY_TO_LOAD_ACK; msgsnd(idMessageVehicleToCaptain, &message, messageLength, 0); } //if captain calls a vehicle to load, then send a confirmation if(msgrcv(idMessageFromCaptain, &message, messageLength, START_LOADING_TRUCK, IPC_NOWAIT) != -1) { message.mtype = FINISH_LOADING_TRUCK; msgsnd(idMessageVehicleToCaptain, &message, messageLength, 0); printf("Loaded truck number %d into the ferry.\n", message.vehicleId); } if(msgrcv(idMessageFromCaptain, &message, messageLength, START_LOADING_CAR, IPC_NOWAIT) != -1) { message.mtype = FINISH_LOADING_CAR; msgsnd(idMessageVehicleToCaptain, &message, messageLength, 0); printf("Loaded Car number %d into the ferry.\n", message.vehicleId); } if(msgrcv(idMessageFromCaptain, &message, messageLength, FERRY_FINISHED_LOADING, IPC_NOWAIT) != -1) { printf("Confirming ferry finished loading\n"); message.mtype = FERRY_FINISHED_LOADING_ACK; msgsnd(idMessageVehicleToCaptain, &message, messageLength, 0); } if(msgrcv(idMessageFromCaptain, &message, messageLength, FERRY_ARRIVED_AT_DESTINATION, IPC_NOWAIT) != -1) { printf("confirming ferry arrived at destination\n"); message.mtype = FERRY_ARRIVED_AT_DESTINATION_ACK; msgsnd(idMessageVehicleToCaptain, &message, messageLength, 0); } //received request to unload a vehicle, send confirmation if(msgrcv(idMessageFromCaptain, &message, messageLength, START_UNLOADING_TRUCK, IPC_NOWAIT) != -1) { message.mtype = FINISH_UNLOADING_TRUCK; msgsnd(idMessageVehicleToCaptain, &message, messageLength, 0); printf("Unloaded a truck\n"); } if(msgrcv(idMessageFromCaptain, &message, messageLength, START_UNLOADING_CAR, IPC_NOWAIT) != -1) { message.mtype = FINISH_UNLOADING_CAR; msgsnd(idMessageVehicleToCaptain, &message, messageLength, 0); printf("Unloaded a car\n"); } if(msgrcv(idMessageFromCaptain, &message, messageLength, FERRY_FINISHED_UNLOADING, IPC_NOWAIT) != -1) { printf("Confirming ferry finished unloading.\n"); message.mtype = FERRY_FINISHED_UNLOADING_ACK; msgsnd(idMessageVehicleToCaptain, &message, messageLength, 0); } if(msgrcv(idMessageFromCaptain, &message, messageLength, FERRY_RETURNED, IPC_NOWAIT) != -1) { printf("Confirming ferry has returned.\n"); message.mtype = FERRY_RETURNED_ACK; msgsnd(idMessageVehicleToCaptain, &message, messageLength, 0); } } /* create a timer while(forever) { if captain sends terminate message send acknowledgement exit if its time to spawn a vehicle determine what type of vehicle to spawn spawn vechicle by sending message to vechileArrivalQueue reset spawn timer if captain says ferry is ready to load move vehicles from arrivalQueue to loading queue swap the arrival queue and the late arrival queue the queues are swaped here, instead of after the ferry finishes loading because if a vehicle arrives while the ferry is loading it needs to go to the late arrival queue, which means a separate flag needs to be checked when a vehicle arrives in order to determine if the vechile should be placed into the arrival queue, or the late arrival queue. if we swap the queues here then we can always put new vehicles in the arrival queue since late arrivals automatically end up in an empty queue tell captain the vehicles are ready to load if a message to load a vechile arrives send a confirmation indicating the vehicle finished loading if captain says the ferry finished loading send a confirmation that message was received if captin says ferry arrived at destination send a confirmation that message was received if captain says to unload a vechile send a confirmation indicating the vehicle unloaded if captain says ferry finished unloading send confirmation if captain says the ferry has returned send confirmation } */ }