From 4c4d29af8a6b1bbb26363df63be0ab675f452255 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Radovan=20=C4=8Cerven=C3=BD?= <radovan.cerveny@gmail.com> Date: Sun, 20 Mar 2016 16:03:57 +0100 Subject: [PATCH] working aggregation, aggregating only time for now --- .../src/measurements/MeasurementFrame.cpp | 12 +++++++++++ .../src/measurements/MeasurementFrame.hpp | 2 ++ .../src/measurements/MeasurementResults.cpp | 17 ++++++++++++++++ .../src/measurements/MeasurementResults.hpp | 2 ++ .../measurements/frames/CounterDataFrame.cpp | 5 +++++ .../measurements/frames/CounterDataFrame.hpp | 2 ++ .../measurements/frames/MemoryDataFrame.cpp | 5 +++++ .../measurements/frames/MemoryDataFrame.hpp | 4 +++- .../src/measurements/frames/TimeDataFrame.cpp | 15 ++++++++++++++ .../src/measurements/frames/TimeDataFrame.hpp | 2 ++ .../provisioner/MeasurementProvisioner.cpp | 20 +++++++++++-------- .../provisioner/MeasurementProvisioner.hpp | 19 +++++++----------- 12 files changed, 84 insertions(+), 21 deletions(-) diff --git a/alib2common/src/measurements/MeasurementFrame.cpp b/alib2common/src/measurements/MeasurementFrame.cpp index d78f5646ba..b79de7a4e4 100644 --- a/alib2common/src/measurements/MeasurementFrame.cpp +++ b/alib2common/src/measurements/MeasurementFrame.cpp @@ -20,4 +20,16 @@ std::ostream & operator <<( std::ostream & os, const MeasurementFrame & frame ) return os; } +MeasurementFrame MeasurementFrame::aggregate ( const std::vector < MeasurementFrame > & framesToAggregate ) { + MeasurementFrame aggregatedFrame ( framesToAggregate[0].name, framesToAggregate[0].type, framesToAggregate[0].parent_idx ); + + aggregatedFrame.sub_idxs = framesToAggregate[0].sub_idxs; + + aggregatedFrame.time = TimeDataFrame::aggregate ( framesToAggregate ); + aggregatedFrame.memory = MemoryDataFrame::aggregate ( framesToAggregate ); + aggregatedFrame.counter = CounterDataFrame::aggregate ( framesToAggregate ); + + return aggregatedFrame; +} + } diff --git a/alib2common/src/measurements/MeasurementFrame.hpp b/alib2common/src/measurements/MeasurementFrame.hpp index 79b8852088..5998f89403 100644 --- a/alib2common/src/measurements/MeasurementFrame.hpp +++ b/alib2common/src/measurements/MeasurementFrame.hpp @@ -28,6 +28,8 @@ struct MeasurementFrame { CounterDataFrame counter; MeasurementFrame ( measurements::stealth_string, measurements::Type, unsigned ); + + static MeasurementFrame aggregate ( const std::vector < MeasurementFrame > & ); }; std::ostream & operator <<( std::ostream &, const MeasurementFrame & ); diff --git a/alib2common/src/measurements/MeasurementResults.cpp b/alib2common/src/measurements/MeasurementResults.cpp index ae5ad56ae0..df4444896d 100644 --- a/alib2common/src/measurements/MeasurementResults.cpp +++ b/alib2common/src/measurements/MeasurementResults.cpp @@ -97,6 +97,23 @@ void MeasurementResults::print_as_tree ( std::ostream & os, unsigned idx, std::s } } +MeasurementResults MeasurementResults::aggregate ( const std::vector < MeasurementResults > & resultsToAggregate ) { + MeasurementResults aggregatedResults; + + size_t frameCount = resultsToAggregate[0].frames.size ( ); + + for ( size_t frameIdx = 0; frameIdx < frameCount; ++frameIdx ) { + std::vector < MeasurementFrame > framesToAggregate; + + for ( const MeasurementResults & measurementResults : resultsToAggregate ) + framesToAggregate.push_back ( measurementResults.frames[frameIdx] ); + + aggregatedResults.frames.push_back ( MeasurementFrame::aggregate ( framesToAggregate ) ); + } + + return aggregatedResults; +} + const int MeasurementXalloc::FORMAT = std::ios::xalloc ( ); std::ostream & operator <<( std::ostream & os, const MeasurementResults & mr ) { diff --git a/alib2common/src/measurements/MeasurementResults.hpp b/alib2common/src/measurements/MeasurementResults.hpp index 618834b24d..62a4088b03 100644 --- a/alib2common/src/measurements/MeasurementResults.hpp +++ b/alib2common/src/measurements/MeasurementResults.hpp @@ -29,6 +29,8 @@ struct MeasurementResults { void print_as_list ( std::ostream & ) const; void print_as_tree ( std::ostream & ) const; + static MeasurementResults aggregate ( const std::vector < MeasurementResults > & ); + private: void print_as_list ( std::ostream &, unsigned ) const; void print_as_tree ( std::ostream &, unsigned, std::string &, bool ) const; diff --git a/alib2common/src/measurements/frames/CounterDataFrame.cpp b/alib2common/src/measurements/frames/CounterDataFrame.cpp index 4541f95b22..e148a8c90d 100644 --- a/alib2common/src/measurements/frames/CounterDataFrame.cpp +++ b/alib2common/src/measurements/frames/CounterDataFrame.cpp @@ -47,6 +47,11 @@ void CounterDataFrame::hint ( unsigned frame_idx, measurements::stealth_vector < } } +CounterDataFrame CounterDataFrame::aggregate ( const std::vector < MeasurementFrame > & framesToAggregate ) { + // dummmy aggregation + return framesToAggregate[0].counter; +} + std::ostream & operator <<( std::ostream & os, const CounterDataFrame & cdf ) { os << "cnts: ("; diff --git a/alib2common/src/measurements/frames/CounterDataFrame.hpp b/alib2common/src/measurements/frames/CounterDataFrame.hpp index 287930a299..10896db9c9 100644 --- a/alib2common/src/measurements/frames/CounterDataFrame.hpp +++ b/alib2common/src/measurements/frames/CounterDataFrame.hpp @@ -33,6 +33,8 @@ struct CounterDataFrame { static void init ( unsigned, measurements::stealth_vector < MeasurementFrame > & ); static void update ( unsigned, measurements::stealth_vector < MeasurementFrame > & ); static void hint ( unsigned, measurements::stealth_vector < MeasurementFrame > &, CounterHint ); + + static CounterDataFrame aggregate ( const std::vector < MeasurementFrame > & ); }; std::ostream & operator <<( std::ostream &, const CounterDataFrame & ); diff --git a/alib2common/src/measurements/frames/MemoryDataFrame.cpp b/alib2common/src/measurements/frames/MemoryDataFrame.cpp index dd1bd8cb10..302b872b12 100644 --- a/alib2common/src/measurements/frames/MemoryDataFrame.cpp +++ b/alib2common/src/measurements/frames/MemoryDataFrame.cpp @@ -64,6 +64,11 @@ void MemoryDataFrame::hint ( unsigned frame_idx, measurements::stealth_vector < } } +MemoryDataFrame MemoryDataFrame::aggregate ( const std::vector < MeasurementFrame > & framesToAggregate ) { + // dummmy aggregation + return framesToAggregate[0].memory; +} + std::ostream & operator <<( std::ostream & os, const MemoryDataFrame & mdf ) { os << mdf.start_heap_usage << "B shu, " << mdf.end_heap_usage << "B ehu, " << mdf.high_watermark << "B hw, " << mdf.in_frame_high_watermark << "B if_hw"; return os; diff --git a/alib2common/src/measurements/frames/MemoryDataFrame.hpp b/alib2common/src/measurements/frames/MemoryDataFrame.hpp index 4fdb5eec03..f0a4672491 100644 --- a/alib2common/src/measurements/frames/MemoryDataFrame.hpp +++ b/alib2common/src/measurements/frames/MemoryDataFrame.hpp @@ -21,7 +21,7 @@ struct MemoryHint { NEW, DELETE }; - Type type; + Type type; value_type size; }; @@ -39,6 +39,8 @@ struct MemoryDataFrame { static void init ( unsigned, measurements::stealth_vector < MeasurementFrame > & ); static void update ( unsigned, measurements::stealth_vector < MeasurementFrame > & ); static void hint ( unsigned, measurements::stealth_vector < MeasurementFrame > &, MemoryHint ); + + static MemoryDataFrame aggregate ( const std::vector < MeasurementFrame > & ); }; std::ostream & operator <<( std::ostream &, const MemoryDataFrame & ); diff --git a/alib2common/src/measurements/frames/TimeDataFrame.cpp b/alib2common/src/measurements/frames/TimeDataFrame.cpp index c641a5f2a1..43f5f1c8bb 100644 --- a/alib2common/src/measurements/frames/TimeDataFrame.cpp +++ b/alib2common/src/measurements/frames/TimeDataFrame.cpp @@ -4,6 +4,7 @@ #include <sstream> #include "../MeasurementFrame.hpp" +#include <iostream> using namespace std::chrono; @@ -26,6 +27,20 @@ void TimeDataFrame::update ( unsigned frame_idx, measurements::stealth_vector < parent_frame.time.in_frame_duration -= current_frame.time.duration; } +TimeDataFrame TimeDataFrame::aggregate ( const std::vector < MeasurementFrame > & framesToAggregate ) { + TimeDataFrame aggregatedTimeDataFrame { }; + + for ( const MeasurementFrame & frame : framesToAggregate ) { + aggregatedTimeDataFrame.duration += frame.time.duration; + aggregatedTimeDataFrame.in_frame_duration += frame.time.in_frame_duration; + } + + aggregatedTimeDataFrame.duration /= framesToAggregate.size ( ); + aggregatedTimeDataFrame.in_frame_duration /= framesToAggregate.size ( ); + + return aggregatedTimeDataFrame; +} + std::ostream & operator <<( std::ostream & os, const TimeDataFrame & tdf ) { os << tdf.duration << " dur, " << tdf.in_frame_duration << " if_dur"; return os; diff --git a/alib2common/src/measurements/frames/TimeDataFrame.hpp b/alib2common/src/measurements/frames/TimeDataFrame.hpp index efb0664ab3..99e7f5a09b 100644 --- a/alib2common/src/measurements/frames/TimeDataFrame.hpp +++ b/alib2common/src/measurements/frames/TimeDataFrame.hpp @@ -24,6 +24,8 @@ struct TimeDataFrame { static void init ( unsigned, measurements::stealth_vector < MeasurementFrame > & ); static void update ( unsigned, measurements::stealth_vector < MeasurementFrame > & ); + + static TimeDataFrame aggregate ( const std::vector < MeasurementFrame > & ); }; std::ostream & operator <<( std::ostream &, const std::chrono::microseconds & ); diff --git a/alib2measurepp/src/provisioner/MeasurementProvisioner.cpp b/alib2measurepp/src/provisioner/MeasurementProvisioner.cpp index bd3723379a..74c36f510b 100644 --- a/alib2measurepp/src/provisioner/MeasurementProvisioner.cpp +++ b/alib2measurepp/src/provisioner/MeasurementProvisioner.cpp @@ -96,7 +96,7 @@ MPRPipelineResults MeasurementProvisioner::runPipeline ( const MPPipeline & pipe ofdstream ofdlog ( pre.stderrFd ); - vector < vector < MeasurementResults > > pipelineMeasurementSubResults; + vector < vector < MeasurementResults > > commandMeasurementSubResults; MPRPipelineResults pipelineFinalResults { }; @@ -138,20 +138,24 @@ MPRPipelineResults MeasurementProvisioner::runPipeline ( const MPPipeline & pipe if ( pipelineFinalResults.pipelineStatus.exitCode != 0 ) break; - pipelineMeasurementSubResults.push_back ( std::move ( pipelineMeasurementResults ) ); + commandMeasurementSubResults.push_back ( std::move ( pipelineMeasurementResults ) ); } // if everything went smoothly, we aggregate the results if ( pipelineFinalResults.pipelineStatus.exitCode == 0 ) { - // FIXME we need proper aggregation - vector < MeasurementResults > aggregatedMeasurementResults = pipelineMeasurementSubResults[0]; + // FIXME we need proper aggregation - vector < MeasurementResults >::iterator amrIter = aggregatedMeasurementResults.begin ( ); + vector < vector < MeasurementResults > > transposedCommandMeasurementSubResults ( pipeline.size ( ) ); + + for ( vector < MeasurementResults > & commandResults : commandMeasurementSubResults ) + for ( size_t i = 0; i < commandResults.size ( ); ++i ) + transposedCommandMeasurementSubResults[i].push_back ( std::move ( commandResults[i] ) ); + + vector < vector < MeasurementResults > >::iterator tcmsIter = transposedCommandMeasurementSubResults.begin ( ); MPPipeline::const_iterator mppcIter = pipeline.cbegin ( ); - for ( ; mppcIter != pipeline.cend ( ); ++mppcIter, ++amrIter ) { - pipelineFinalResults.commandResults.push_back ( { mppcIter->getRawCommand ( ), std::move ( * amrIter ) } ); - } + for ( ; mppcIter != pipeline.cend ( ); ++mppcIter, ++tcmsIter ) + pipelineFinalResults.commandResults.push_back ( { mppcIter->getRawCommand ( ), MeasurementResults::aggregate ( * tcmsIter ) } ); ofdlog << "| \tpipeline: \tOK" << endl; } else { diff --git a/alib2measurepp/src/provisioner/MeasurementProvisioner.hpp b/alib2measurepp/src/provisioner/MeasurementProvisioner.hpp index 98beda6659..2ef9a15552 100644 --- a/alib2measurepp/src/provisioner/MeasurementProvisioner.hpp +++ b/alib2measurepp/src/provisioner/MeasurementProvisioner.hpp @@ -21,32 +21,27 @@ class MeasurementProvisioner { static void prepareEnvironment ( const MeasurementProvisionerConfiguration & ); static MPRPipelineResults runPipeline ( const MPPipeline &, const MPSubstitutionMap &, const MeasurementProvisionerConfiguration & ); - - struct PipelineRunnerEnvironment { MPUtils::ShmFileHandle measurementsTmpfile, inputTmpfile, outputTmpfile, errorTmpfile; int measurementsFd, stdinFd, stdoutFd, stderrFd; public: + PipelineRunnerEnvironment ( ); + ~PipelineRunnerEnvironment ( ); - PipelineRunnerEnvironment(); - ~PipelineRunnerEnvironment(); - - void commandFdInit(); - void commandFdSwap(); - void commandFdEnd(); + void commandFdInit ( ); + void commandFdSwap ( ); + void commandFdEnd ( ); - std::string retrievePipelineError(); - MeasurementResults retrieveMeasurementResults(); + std::string retrievePipelineError ( ); + MeasurementResults retrieveMeasurementResults ( ); }; public: static MeasurementProvisionerResults runConfiguration ( const MeasurementProvisionerConfiguration & ); }; - - } #endif /* MEASUREMENT_PROVISIONER_HPP_ */ -- GitLab