Commit a99fa9b6 authored by Ing. Jan Trávníček's avatar Ing. Jan Trávníček

simple measurement interface in cli

parent f77d8d09
#ifndef _CLI_CLEAR_MEASUREMENTS_H_
#define _CLI_CLEAR_MEASUREMENTS_H_
#include <ast/Command.h>
#include <environment/Environment.h>
#include <alib/measure>
namespace cli {
class ClearMeasurements : public Command {
public:
CommandResult run ( Environment & ) const override {
measurements::reset ( );
return CommandResult::OK;
}
};
} /* namespace cli */
#endif /* _CLI_CLEAR_MEASUREMENTS_H_ */
#ifndef _CLI_SHOW_MEASUREMENTS_H_
#define _CLI_SHOW_MEASUREMENTS_H_
#include <ast/Command.h>
#include <environment/Environment.h>
#include <alib/measure>
namespace cli {
class ShowMeasurements : public Command {
measurements::MeasurementFormat m_format;
public:
ShowMeasurements ( measurements::MeasurementFormat format ) : m_format ( format ) {
}
CommandResult run ( Environment & ) const override {
common::Streams::out << m_format << measurements::results ( ) << std::endl;
return CommandResult::OK;
}
};
} /* namespace cli */
#endif /* _CLI_SHOW_MEASUREMENTS_H_ */
#ifndef _CLI_START_MEASUREMENT_FRAME_H_
#define _CLI_START_MEASUREMENT_FRAME_H_
#include <ast/Command.h>
#include <environment/Environment.h>
#include <alib/measure>
namespace cli {
class StartMeasurementFrame : public Command {
std::string m_frameName;
measurements::Type m_type;
public:
StartMeasurementFrame ( std::string frameName, measurements::Type type ) : m_frameName ( std::move ( frameName ) ), m_type ( type ) {
}
CommandResult run ( Environment & ) const override {
measurements::start ( measurements::stealthStringFromString ( m_frameName ), m_type );
return CommandResult::OK;
}
};
} /* namespace cli */
#endif /* _CLI_START_MEASUREMENT_FRAME_H_ */
#ifndef _CLI_STOP_MEASUREMENT_FRAME_H_
#define _CLI_STOP_MEASUREMENT_FRAME_H_
#include <ast/Command.h>
#include <environment/Environment.h>
#include <alib/measure>
namespace cli {
class StopMeasurementFrame : public Command {
public:
CommandResult run ( Environment & ) const override {
measurements::end ( );
return CommandResult::OK;
}
};
} /* namespace cli */
#endif /* _CLI_STOP_MEASUREMENT_FRAME_H_ */
......@@ -27,6 +27,10 @@
#include <ast/command/BindingsIntrospectionCommand.h>
#include <ast/command/VariablesIntrospectionCommand.h>
#include <ast/command/SetCommand.h>
#include <ast/command/ShowMeasurements.h>
#include <ast/command/ClearMeasurements.h>
#include <ast/command/StartMeasurementFrame.h>
#include <ast/command/StopMeasurementFrame.h>
#include <ast/command/LoadCommand.h>
#include <ast/command/UnloadCommand.h>
#include <ast/command/CalcCommand.h>
......@@ -492,6 +496,65 @@ std::unique_ptr < Command > Parser::command ( ) {
std::string value = getTokenValue ( );
match ( cli::Lexer::TokenType::UNSIGNED, cli::Lexer::TokenType::IDENTIFIER, cli::Lexer::TokenType::STRING );
return std::make_unique < SetCommand > ( std::move ( param ), std::move ( value ) );
} else if ( check_nonreserved_kw ( "show" ) ) {
match_nonreserved_kw ( "show" );
std::string param = getTokenValue ( );
match_nonreserved_kw ( "measurements" );
match_nonreserved_kw ( "as" );
if ( check_nonreserved_kw ( "list" ) ) {
match_nonreserved_kw ( "list" );
return std::make_unique < ShowMeasurements > ( measurements::MeasurementFormat::LIST );
} else {
match_nonreserved_kw ( "tree" );
return std::make_unique < ShowMeasurements > ( measurements::MeasurementFormat::TREE );
}
} else if ( check_nonreserved_kw ( "clear" ) ) {
match_nonreserved_kw ( "clear" );
std::string param = getTokenValue ( );
match_nonreserved_kw ( "measurements" );
return std::make_unique < ClearMeasurements > ( );
} else if ( check_nonreserved_kw ( "start" ) ) {
match_nonreserved_kw ( "start" );
measurements::Type type;
if ( check_nonreserved_kw ( "root" ) ) {
match_nonreserved_kw ( "root" );
type = measurements::Type::ROOT;
} else if ( check_nonreserved_kw ( "overall" ) ) {
match_nonreserved_kw ( "overall" );
type = measurements::Type::OVERALL;
} else if ( check_nonreserved_kw ( "init" ) ) {
match_nonreserved_kw ( "init" );
type = measurements::Type::INIT;
} else if ( check_nonreserved_kw ( "finalize" ) ) {
match_nonreserved_kw ( "finalize" );
type = measurements::Type::FINALIZE;
} else if ( check_nonreserved_kw ( "main" ) ) {
match_nonreserved_kw ( "main" );
type = measurements::Type::MAIN;
} else if ( check_nonreserved_kw ( "auxiliary" ) ) {
match_nonreserved_kw ( "auxiliary" );
type = measurements::Type::AUXILIARY;
} else if ( check_nonreserved_kw ( "preprocess" ) ) {
match_nonreserved_kw ( "preprocess" );
type = measurements::Type::PREPROCESS;
} else {
match_nonreserved_kw ( "algorithm" );
type = measurements::Type::ALGORITHM;
}
match_nonreserved_kw ( "measurement" );
match_nonreserved_kw ( "frame" );
std::string frameName = getTokenValue ( );
match ( cli::Lexer::TokenType::UNSIGNED, cli::Lexer::TokenType::IDENTIFIER );
return std::make_unique < StartMeasurementFrame > ( std::move ( frameName ), type );
} else if ( check_nonreserved_kw ( "stop" ) ) {
match_nonreserved_kw ( "stop" );
match_nonreserved_kw ( "measurement" );
match_nonreserved_kw ( "frame" );
return std::make_unique < StopMeasurementFrame > ( );
} else if ( check_nonreserved_kw ( "load" ) ) {
match_nonreserved_kw ( "load" );
......
......@@ -136,10 +136,6 @@ int main ( int argc, char * argv[] ) {
/* --------------------------------------------------------------------------------------------------------- */
measurements::start ( "Overall", measurements::Type::OVERALL );
/* --------------------------------------------------------------------------------------------------------- */
cli::Environment & environment = Prompt::getPrompt ( ).getEnvironment ( );
environment.setBinding ( "stdin", "-" );
......@@ -160,13 +156,6 @@ int main ( int argc, char * argv[] ) {
/* --------------------------------------------------------------------------------------------------------- */
measurements::end ( );
if ( measure.getValue ( ) )
common::Streams::measure << measurements::results ( ) << std::endl;
/* --------------------------------------------------------------------------------------------------------- */
delete queriesVisitor;
delete fileVisitor;
delete interactiveVisitor;
......
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