Skip to content

SteerSuiteProfiling

Neo-X edited this page Sep 18, 2015 · 1 revision

Profiling

Profiling function in SteerSuite for steering algorithms is a simple process. The class that is used is PerformanceProfiler. The constructor for the ProformanceProfile will start the clock and then when the destructor for the profile is called the profile will be stopped and the data will be stored. This can be done like so:

 Util::AutomaticFunctionProfiler profileThisFunction( &SocialForcesGlobals::gPhaseProfilers->aiProfiler );

You can look at how this is used in many of the steer algorithms.

How This Is Done

1. Create a Logger in the init function for the Steering Algorithm module. Looks something like

		_rvoLogger = LogManager::getInstance()->createLogger(logFilename,LoggerType::BASIC_WRITE);

		_rvoLogger->addDataField("number_of_times_executed",DataType::LongLong );
		_rvoLogger->addDataField("total_ticks_accumulated",DataType::LongLong );
		_rvoLogger->addDataField("shortest_execution",DataType::LongLong );
		_rvoLogger->addDataField("longest_execution",DataType::LongLong );
		_rvoLogger->addDataField("fastest_execution", DataType::Float);
		_rvoLogger->addDataField("slowest_execution", DataType::Float);
		_rvoLogger->addDataField("average_time_per_call", DataType::Float);
		_rvoLogger->addDataField("total_time_of_all_calls", DataType::Float);
		_rvoLogger->addDataField("tick_frequency", DataType::Float);

	if( logStats )
		{
		// LETS TRY TO WRITE THE LABELS OF EACH FIELD
		std::stringstream labelStream;
		unsigned int i;
		for (i=0; i < _rvoLogger->getNumberOfFields() - 1; i++)
			labelStream << _rvoLogger->getFieldName(i) << " ";
		labelStream << _rvoLogger->getFieldName(i);
		_data = labelStream.str() + "\n";

		_rvoLogger->writeData(labelStream.str());

	}

2. In the Module::initilizeSimulation create and reset the Profiler

gPhaseProfilers = new PhaseProfilers;
gPhaseProfilers->aiProfiler.reset();

3. Then in AgentInterface::updateAI() call the profiler

     Util::AutomaticFunctionProfiler profileThisFunction( &SocialForcesGlobals::gPhaseProfilers->aiProfiler );

4. Last in Module::cleanupSimulation() that data can be grabbed from the profiler and dumped out into a file.

                LogObject rvoLogObject;

		rvoLogObject.addLogData(gPhaseProfilers->aiProfiler.getNumTimesExecuted());
		rvoLogObject.addLogData(gPhaseProfilers->aiProfiler.getTotalTicksAccumulated());
		rvoLogObject.addLogData(gPhaseProfilers->aiProfiler.getMinTicks());
		rvoLogObject.addLogData(gPhaseProfilers->aiProfiler.getMaxTicks());
		rvoLogObject.addLogData(gPhaseProfilers->aiProfiler.getMinExecutionTimeMills());
		rvoLogObject.addLogData(gPhaseProfilers->aiProfiler.getMaxExecutionTimeMills());
		rvoLogObject.addLogData(gPhaseProfilers->aiProfiler.getAverageExecutionTimeMills());
		rvoLogObject.addLogData(gPhaseProfilers->aiProfiler.getTotalTime());
		rvoLogObject.addLogData(gPhaseProfilers->aiProfiler.getTickFrequency());

		_rvoLogger->writeLogObject(rvoLogObject);
		_data = _data + _rvoLogger->logObjectToString(rvoLogObject);
		_logData.push_back(rvoLogObject.copy());

		// cleanup profileing metrics for next simulation/scenario
		gPhaseProfilers->aiProfiler.reset();
		
	if ( logStats )
	{
		_rvoLogger->writeLogObject(rvoLogObject);
	}

This will write out a cvs like file with the columns being labeled by the dataFields in step 1. With rows for each time the data is pulled out of the profilers in step 4.