Example #1
0
int main(int argc, const char* argv[])
{
	// Getting input parameter
	if (argc > 2) {
		cerr << "Usage: ./aia-dpm [output_file]" << endl;
		return 1;
	}
	string filename;
	if (argc == 2)
		filename = argv[1];
	else
		filename = "output.txt";

	Scheduler* scheduler = NULL;
	try {
		// Initializing and executing the observation period
		timeval start, end;

		gettimeofday(&start, NULL);
		scheduler = new Scheduler();
		scheduler->initializePeriod();
		gettimeofday(&end, NULL);
		time_t initTime = getDiffMillisec(end, start);

		gettimeofday(&start, NULL);
		scheduler->runSchedule();
		gettimeofday(&end, NULL);
		time_t execTime = getDiffMillisec(end, start);

		// Getting execution data
		gettimeofday(&start, NULL);
		double throughput = scheduler->calculateTotalThroughput();
		double timeUsage = scheduler->calculateTotalTimeUsage();
		double totalSbs = scheduler->calculateExecutedSchedBlocks();
		double avgeNextSBTime = scheduler->getAvgeNextSBTime();
		double avgeExecuteTime = scheduler->getAvgeExecuteTime();
		double avgeNextTimeSlotTime = scheduler->getAvgeNextTimeSlotTime();
		unsigned int avgeShortTermSBListSize = scheduler->getAvgeShortTermSBListSize();
		unsigned int avgeLongTermSBListSize = scheduler->getAvgeLongTermSBListSize();
		map<time_t,SchedBlock*> executionOrder = scheduler->getExecutionOrder();
		gettimeofday(&end, NULL);
		time_t finalTime = getDiffMillisec(end, start);

		// Prepare output file
		ofstream outputFile;
		outputFile.open(filename.c_str(), ios::out);
		if (!outputFile.is_open()) {
			cerr << "Error opening output file " << filename << endl;
			if (scheduler != NULL)
				delete scheduler;
			return 1;
		}

		// Print statistics
		outputFile << "-------------------------------------------------------" << endl;
		outputFile << "Total scientific throughput rate: " << throughput << endl;
		outputFile << "Total time usage rate: " << timeUsage << endl;
		outputFile << "Total SBs execution rate: " << totalSbs << endl;
		outputFile << endl;
		outputFile << "Average initial short term SB list size: " << avgeShortTermSBListSize << endl;
		outputFile << "Average initial long term SB list size: " << avgeLongTermSBListSize << endl;
		outputFile << endl;
		outputFile << "Average next SB processing time: " << avgeNextSBTime << "[msec]" << endl;
		outputFile << "Average execute SB processing time: " << avgeExecuteTime << "[msec]" << endl;
		outputFile << "Average next time slot processing time: " << avgeNextTimeSlotTime << "[msec]" << endl;
		outputFile << endl;
		outputFile << "Initialization time: " << initTime/1000.0 << "[sec]" << endl;
		outputFile << "Period execution time: " << execTime/1000.0 << "[sec]" << endl;
		outputFile << "Finalization time: " << finalTime/1000.0 << "[sec]" << endl;
		outputFile << "-------------------------------------------------------" << endl;

		// Print execution order
		char buffer[80];
		map<time_t,SchedBlock*>::iterator it;
		for (it=executionOrder.begin(); it!=executionOrder.end(); it++) {
			//outputFile << it->first << " "
			strftime(buffer,80,"%Y-%m-%dT%H:%M:%S ",localtime(&(it->first)));
			outputFile << buffer
				<< it->second->getProject()->getIndex() << ","
				<< it->second->getIndex() << endl;
		}
		outputFile << "-------------------------------------------------------" << endl;

		// Print pending SBs
		list<Project*> pendingProj = scheduler->getPendingProjects();
		list<Project*>::iterator itProj;
		for (itProj=pendingProj.begin(); itProj!=pendingProj.end(); itProj++) {
			list<SchedBlock*> pendingSB = (*itProj)->getPendingSchedBlocks();
			list<SchedBlock*>::iterator itSB;
			for (itSB=pendingSB.begin(); itSB!=pendingSB.end(); itSB++)
				outputFile << (*itProj)->getIndex() << "," << (*itSB)->getIndex()
					<< " (" << (*itProj)->getSciGrade() << ")" << endl;
		}
		outputFile << "-------------------------------------------------------" << endl;

		// Cleanup
		outputFile.close();
		delete scheduler;
	} catch (...) {
		cerr << "ERROR: Something went wrong! Aborting." << endl;
		if (scheduler != NULL)
			delete scheduler;
		return 1;
	}
	return 0;
}