Commit cde4f2d1 authored by Pascal Palenda's avatar Pascal Palenda
Browse files

Increase timestamp precision of profile

parent 67d79140
......@@ -293,8 +293,8 @@ namespace ITA
/// \param mThreadNames map, containing the names of the threads.
/// \return a JSON Node with the data of the given eventCount pair.
///
static JSONNode profileEventCountToJSON ( const std::pair<ProfilerKey, ProfileEventCount>& eventCountPair,
const std::unordered_map<std::thread::id, std::string>& mThreadNames )
JSONNode profileEventCountToJSON ( const std::pair<ProfilerKey, ProfileEventCount>& eventCountPair,
const std::unordered_map<std::thread::id, std::string>& mThreadNames )
{
std::string sThreadName;
......@@ -324,9 +324,9 @@ namespace ITA
std::transform ( eventCountPair.second.vTimeStamps.begin ( ),
eventCountPair.second.vTimeStamps.end ( ),
vdTimeStamps.begin ( ),
[] ( const double& time ) -> double
[&] ( const double& time ) -> double
{
return time * 1e6;
return time - m_dStartTime;
} );
/*JSONNode jnTimeStampArray ( JSON_ARRAY );
......@@ -342,7 +342,9 @@ namespace ITA
jnRoot.push_back ( jnTimeStampArray );*/
jnRoot.push_back ( JSONNode ( "Time Stamps", utils::DataTypeUtils::convertToString ( vdTimeStamps, 8, "," ) ) );
const int precision = 1 + std::ceil(std::log10(ITAClock::getDefaultClock()->getFrequency()));
jnRoot.push_back ( JSONNode ( "Time Stamps", utils::DataTypeUtils::convertToString ( vdTimeStamps, precision, "," ) ) );
return jnRoot;
}
......@@ -355,7 +357,7 @@ namespace ITA
/// \param mThreadNames map, containing the names of the threads.
/// \return a JSON Node with the data of the given section pair.
///
static JSONNode profileSectionToJSON ( const std::pair<ProfilerKey, ProfileSection>& sectionPair,
JSONNode profileSectionToJSON ( const std::pair<ProfilerKey, ProfileSection>& sectionPair,
const std::unordered_map<std::thread::id, std::string>& mThreadNames )
{
std::string sThreadName;
......@@ -381,40 +383,25 @@ namespace ITA
jnRoot.push_back ( JSONNode ( "Count", sectionPair.second.vpStartEndTimes.size ( ) ) );
std::vector<double> vdDeltaTime ( sectionPair.second.vpStartEndTimes.size ( ) );
std::vector<double> vdStartTime ( sectionPair.second.vpStartEndTimes.size ( ) );
std::vector<double> vdEndTime ( sectionPair.second.vpStartEndTimes.size ( ) );
std::transform ( sectionPair.second.vpStartEndTimes.begin ( ),
sectionPair.second.vpStartEndTimes.end ( ),
vdDeltaTime.begin ( ),
[] ( const std::pair<double, double>& interval ) -> double
{
return ( interval.second - interval.first ) * 1e6;
} );
std::transform ( sectionPair.second.vpStartEndTimes.begin ( ),
sectionPair.second.vpStartEndTimes.end ( ),
vdStartTime.begin ( ),
[] ( const std::pair<double, double>& interval ) -> double
[&] ( const std::pair<double, double>& interval ) -> double
{
return interval.first * 1e6;
return interval.first - m_dStartTime;
} );
std::transform ( sectionPair.second.vpStartEndTimes.begin ( ),
sectionPair.second.vpStartEndTimes.end ( ),
vdEndTime.begin ( ),
[] ( const std::pair<double, double>& interval ) -> double
[&] ( const std::pair<double, double>& interval ) -> double
{
return interval.second * 1e6;
return interval.second - m_dStartTime;
} );
jnRoot.push_back ( JSONNode ( "Min", *std::min_element ( vdDeltaTime.begin ( ), vdDeltaTime.end ( ) ) ) );
jnRoot.push_back ( JSONNode ( "Max", *std::max_element ( vdDeltaTime.begin ( ), vdDeltaTime.end ( ) ) ) );
jnRoot.push_back ( JSONNode ( "Mean", utils::Statistics::calculateMean ( vdDeltaTime ) ) );
jnRoot.push_back ( JSONNode ( "Variance", utils::Statistics::calculateVariance ( vdDeltaTime ) ) );
jnRoot.push_back ( JSONNode ( "StdDeviation", utils::Statistics::calculateStandardDeviation ( vdDeltaTime ) ) );
/*JSONNode jnStartTimeArray ( JSON_ARRAY );
jnStartTimeArray.set_name ( "Start Times" );
jnStartTimeArray.reserve ( vdStartTime.size ( ) );
......@@ -440,8 +427,10 @@ namespace ITA
jnRoot.push_back ( jnEndTimeArray );*/
jnRoot.push_back ( JSONNode ( "Start Times", utils::DataTypeUtils::convertToString ( vdStartTime, 8, "," ) ) );
jnRoot.push_back ( JSONNode ( "End Times", utils::DataTypeUtils::convertToString ( vdEndTime, 8, "," ) ) );
const int precision = 1 + std::ceil ( std::log10 ( ITAClock::getDefaultClock ( )->getFrequency ( ) ) );
jnRoot.push_back ( JSONNode ( "Start Times", utils::DataTypeUtils::convertToString ( vdStartTime, precision, "," ) ) );
jnRoot.push_back ( JSONNode ( "End Times", utils::DataTypeUtils::convertToString ( vdEndTime, precision, "," ) ) );
return jnRoot;
}
......@@ -452,7 +441,7 @@ namespace ITA
/// \param mThreadNames map, containing the names of the threads.
/// \return a JSON Node with the data of the given ProfileValue pair.
///
static JSONNode profileValuesToJSON ( const std::pair<ProfilerKey, ProfileValue>& valuePair,
JSONNode profileValuesToJSON ( const std::pair<ProfilerKey, ProfileValue>& valuePair,
const std::unordered_map<std::thread::id, std::string>& mThreadNames )
{
std::string sThreadName;
......@@ -521,9 +510,9 @@ namespace ITA
/// \return returns a tuple with the JSONNode for the time stamp and data.
///
template<class T>
static std::tuple<JSONNode, JSONNode> valueDataToJSON ( const ProfileValue& oProfileValue )
std::tuple<JSONNode, JSONNode> valueDataToJSON ( const ProfileValue& oProfileValue )
{
std::vector<std::pair<T, double>> dataVector = oProfileValue.getData<T> ( );
std::vector<std::pair<T, double>> dataVector = oProfileValue.getData<T> ( m_dStartTime );
/*JSONNode jnTimeStampArray ( JSON_ARRAY );
jnTimeStampArray.set_name ( "TimeStamps" );
......@@ -560,7 +549,9 @@ namespace ITA
return p.second;
} );
JSONNode jnTimeStampArray ( "Time Stamps", utils::DataTypeUtils::convertToString ( vdTimeStamps, 8, "," ) );
const int precision = 1 + std::ceil ( std::log10 ( ITAClock::getDefaultClock ( )->getFrequency ( ) ) );
JSONNode jnTimeStampArray ( "Time Stamps", utils::DataTypeUtils::convertToString ( vdTimeStamps, precision, "," ) );
JSONNode jnDataArray ( "Data", utils::DataTypeUtils::convertToString ( vTData, 8, "," ) );
return std::make_pair ( jnTimeStampArray, jnDataArray );
......@@ -572,7 +563,10 @@ namespace ITA
friend ProfilerInstance;
#endif
CProfiler ( ) = default;
CProfiler ( )
{
m_dStartTime = ITAClock::getDefaultClock ( )->getTime ( );
}
~CProfiler ( ) = default;
......@@ -580,6 +574,8 @@ namespace ITA
CProfiler& operator=( const CProfiler& other ) = delete;
double m_dStartTime = 0;
///
/// \brief Map, storing the thread storage.
///
......@@ -617,7 +613,7 @@ namespace ITA
#else
return PROFILE_MANAGER.instance;
#endif
}
}
void CSection::start ( )
{
......@@ -677,7 +673,7 @@ namespace ITA
{
return CProfiler::getInstance ( ).profilerToJSON ( );
}
} // namespace profiler
} // namespace profiler
void storeProfilerData ( const std::string& sProfilerFileName )
{
......@@ -690,7 +686,7 @@ namespace ITA
myProfile.close ( );
#endif
}
} // namespace simulation_scheduler
} // namespace simulation_scheduler
} // namespace ITA
#endif
......
......@@ -77,20 +77,20 @@ namespace ITA
/// \return the data of ProfileValue.
///
template<class T>
std::vector<std::pair<T, double>> getData ( ) const
std::vector<std::pair<T, double>> getData ( double sStartTime ) const
{
std::vector<std::pair<T, double>> vData ( voValueData.size ( ) );
std::transform ( voValueData.begin ( ),
voValueData.end ( ),
vData.begin ( ),
[] ( const ValueData& data ) -> std::pair<T, double>
[&] ( const ValueData& data ) -> std::pair<T, double>
{
assert ( data.getType ( ) == StdToDataType<T>::eDataType );
std::pair<T, double> returnData;
returnData.first = *std::static_pointer_cast< T >( data.getValue ( ) );
returnData.second = data.getTimeStamp ( ) * 1e6;
returnData.second = data.getTimeStamp ( ) - sStartTime;
return returnData;
} );
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment