diff --git a/alib2measurepp/src/processor/MeasurementProcessorOutput.cpp b/alib2measurepp/src/processor/MeasurementProcessorOutput.cpp index d882df5037aa740355a20c0de7b69ff8d6a0dfe5..164ef54a2eeb495ea2b972863d3e99e5a304d2b4 100644 --- a/alib2measurepp/src/processor/MeasurementProcessorOutput.cpp +++ b/alib2measurepp/src/processor/MeasurementProcessorOutput.cpp @@ -3,6 +3,7 @@ */ #include "MeasurementProcessorOutput.hpp" +#include "sax/SaxComposeInterface.h" #include <set> #include <iostream> @@ -49,18 +50,88 @@ void MeasurementProcessorOutput::outputStats ( std::ostream & os, const Measurem } void MeasurementProcessorOutput::outputCsv ( std::ostream & os, const MeasurementProvisionerResults & mpr, const MeasurementProcessorOutput & mpo ) { + for ( const Table & table : MeasurementProcessorOutput::getTableRepresentation ( mpr, mpo ) ) { + os << "# " << table.description << std::endl; - struct Row { - std::string input; - std::vector < std::string > data; - }; + for ( auto it = table.header.begin ( ); it != table.header.end ( ); ++it ) { + if ( it != table.header.begin ( ) ) os << ","; - struct Table { - std::string description; - std::vector < std::string > header; - std::vector < Row > rows; - }; + os << * it; + } + + os << std::endl; + + for ( const Row & row : table.rows ) { + os << row.input; + + for ( const std::string & datum : row.data ) + os << "," << datum; + + os << std::endl; + } + } +} + +void MeasurementProcessorOutput::outputHtml ( std::ostream & os, const MeasurementProvisionerResults & mpr, const MeasurementProcessorOutput & mpo ) { + std::deque < sax::Token > tokens; + + tokens.emplace_back ( "html", sax::Token::TokenType::START_ELEMENT ); + tokens.emplace_back ( "head", sax::Token::TokenType::START_ELEMENT ); + tokens.emplace_back ( "style", sax::Token::TokenType::START_ELEMENT ); + tokens.emplace_back ( "table { border-collapse: collapse; background-color: #aaa } th, td { padding: 0.25rem; text-align: left; border: 1px solid #ccc; } tbody tr:nth-child(odd) { background: #ddd; }", sax::Token::TokenType::CHARACTER ); + tokens.emplace_back ( "style", sax::Token::TokenType::END_ELEMENT ); + tokens.emplace_back ( "title", sax::Token::TokenType::START_ELEMENT ); + tokens.emplace_back ( "Measurement results", sax::Token::TokenType::CHARACTER ); + tokens.emplace_back ( "title", sax::Token::TokenType::END_ELEMENT ); + tokens.emplace_back ( "head", sax::Token::TokenType::END_ELEMENT ); + tokens.emplace_back ( "body", sax::Token::TokenType::START_ELEMENT ); + + for ( const Table & table : MeasurementProcessorOutput::getTableRepresentation ( mpr, mpo ) ) { + + tokens.emplace_back ( "div", sax::Token::TokenType::START_ELEMENT ); + tokens.emplace_back ( "h3", sax::Token::TokenType::START_ELEMENT ); + tokens.emplace_back ( table.description, sax::Token::TokenType::CHARACTER ); + tokens.emplace_back ( "h3", sax::Token::TokenType::END_ELEMENT ); + + tokens.emplace_back ( "table", sax::Token::TokenType::START_ELEMENT ); + + tokens.emplace_back ( "tr", sax::Token::TokenType::START_ELEMENT ); + + for ( const std::string & head : table.header ) { + tokens.emplace_back ( "th", sax::Token::TokenType::START_ELEMENT ); + tokens.emplace_back ( head, sax::Token::TokenType::CHARACTER ); + tokens.emplace_back ( "th", sax::Token::TokenType::END_ELEMENT ); + } + + tokens.emplace_back ( "tr", sax::Token::TokenType::END_ELEMENT ); + + for ( const Row & row : table.rows ) { + tokens.emplace_back ( "tr", sax::Token::TokenType::START_ELEMENT ); + + tokens.emplace_back ( "td", sax::Token::TokenType::START_ELEMENT ); + tokens.emplace_back ( row.input, sax::Token::TokenType::CHARACTER ); + tokens.emplace_back ( "td", sax::Token::TokenType::END_ELEMENT ); + for ( const std::string & datum : row.data ) { + tokens.emplace_back ( "td", sax::Token::TokenType::START_ELEMENT ); + tokens.emplace_back ( datum, sax::Token::TokenType::CHARACTER ); + tokens.emplace_back ( "td", sax::Token::TokenType::END_ELEMENT ); + } + + tokens.emplace_back ( "tr", sax::Token::TokenType::END_ELEMENT ); + } + + tokens.emplace_back ( "table", sax::Token::TokenType::END_ELEMENT ); + tokens.emplace_back ( "div", sax::Token::TokenType::END_ELEMENT ); + } + + tokens.emplace_back ( "body", sax::Token::TokenType::END_ELEMENT ); + tokens.emplace_back ( "html", sax::Token::TokenType::END_ELEMENT ); + + sax::SaxComposeInterface::printStream ( os, tokens ); +} + +std::vector < MeasurementProcessorOutput::Table > MeasurementProcessorOutput::getTableRepresentation ( const MeasurementProvisionerResults & mpr, const MeasurementProcessorOutput & mpo ) { // this starts to get ugly std::vector < std::string > masterHeader { "input" @@ -96,29 +167,7 @@ void MeasurementProcessorOutput::outputCsv ( std::ostream & os, const Measuremen } } - for ( const Table & table : tables ) { - os << "# " << table.description << std::endl; - - for ( auto it = table.header.begin ( ); it != table.header.end ( ); ++it ) { - if ( it != table.header.begin ( ) ) os << ","; - - os << * it; - } - - os << std::endl; - - for ( const Row & row : table.rows ) { - os << row.input; - - for ( const std::string & datum : row.data ) - os << "," << datum; - - os << std::endl; - } - } -} - -void MeasurementProcessorOutput::outputHtml ( std::ostream &, const MeasurementProvisionerResults &, const MeasurementProcessorOutput & ) { + return tables; } std::string MeasurementProcessorOutput::getData ( const MeasurementFrame & frame, const MeasurementProcessorOutput & mpo ) { @@ -132,11 +181,10 @@ std::string MeasurementProcessorOutput::getData ( const MeasurementFrame & frame return std::to_string ( frame.memory.highWatermark - frame.memory.startHeapUsage ); case OutputEngine::COUNTER: + // FIXME return ""; } - - return ""; } } diff --git a/alib2measurepp/src/processor/MeasurementProcessorOutput.hpp b/alib2measurepp/src/processor/MeasurementProcessorOutput.hpp index 40637bc6c05cf3f3716886269bedc563a77489df..f6bdbeab93b91c0e8d3d25ca2fc8e240d66eea44 100644 --- a/alib2measurepp/src/processor/MeasurementProcessorOutput.hpp +++ b/alib2measurepp/src/processor/MeasurementProcessorOutput.hpp @@ -28,7 +28,20 @@ struct MeasurementProcessorOutput { static void outputCsv ( std::ostream &, const MeasurementProvisionerResults &, const MeasurementProcessorOutput & ); static void outputHtml ( std::ostream &, const MeasurementProvisionerResults &, const MeasurementProcessorOutput & ); - static std::string getData ( const MeasurementFrame &, const MeasurementProcessorOutput & ); +private: + struct Row { + std::string input; + std::vector < std::string > data; + }; + + struct Table { + std::string description; + std::vector < std::string > header; + std::vector < Row > rows; + }; + + static std::vector < Table > getTableRepresentation ( const MeasurementProvisionerResults &, const MeasurementProcessorOutput & ); + static std::string getData ( const MeasurementFrame &, const MeasurementProcessorOutput & ); }; }