Skip to content
Snippets Groups Projects
Commit c25d6414 authored by Radovan Červený's avatar Radovan Červený
Browse files

basic html output

parent 0967b864
No related branches found
No related tags found
1 merge request!15BP_cervera3 - automatic measurements, processing
......@@ -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 "";
}
 
}
......@@ -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 & );
};
 
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment