The Sparta Modeling Framework
Loading...
Searching...
No Matches
sparta::app::CommandLineSimulator Class Reference

Command line simulator front-end class with argument parsing Works in conjunction with sparta::app::Simulation. More...

#include <CommandLineSimulator.hpp>

Collaboration diagram for sparta::app::CommandLineSimulator:

Public Member Functions

 CommandLineSimulator ()=delete
 Not default constructable.
 
 CommandLineSimulator (const std::string &usage, const DefaultValues &defs=DEFAULTS)
 Construct.
 
virtual ~CommandLineSimulator ()
 Destructor.
 
bool isParsed () const
 Has this simulator parsed the command line yet Being parsed is required to call for populateSimulation.
 
bool isSetup () const
 Has this simulator been setup yet? Being set up is required to call runSimulator.
 
const std::string & getUsage () const
 Gets the usage string specified for this simulator at construction. This string is printed when usage errors are encountered.
 
const MultiDetailOptionsgetSpartaOptions () const
 Gets the sparta-specific options for this simulator.
 
MultiDetailOptionsgetApplicationOptions ()
 Gets the application-specific options for this simulator.
 
MultiDetailOptionsgetAdvancedOptions ()
 Gets the advanced options for this simulator.
 
po::positional_options_description & getPositionalOptions ()
 Gets the boost positional options for the parser owned by this simulator.
 
const po::variables_map & getVariablesMap () const
 Variables map populated by command-line parsing. This map is populated within the parse() method.
 
bool parse (int argc, char **argv, int &err_code)
 Parse command line options.
 
int parse (int argc, char **argv)
 DEPRECATED Shorthand version of other parse method,.
 
void populateSimulation (Simulation *sim)
 Builds the content of the simulator making it ready to run.
 
void runSimulator (Simulation *sim)
 Run the simulator.
 
void runSimulator (Simulation *sim, uint64_t ticks)
 Run the simulator for the specified number of ticks.
 
void postProcess (Simulation *sim)
 Post-process the results of the simulation if applicable.
 
bool isRuntimeFinite () const
 
SimulationConfigurationgetSimulationConfiguration ()
 
const SimulationConfigurationgetSimulationConfiguration () const
 

Static Public Attributes

static DefaultValues DEFAULTS
 Static DefaultValues for a SPARTA CommandLineSimulator.
 

Protected Member Functions

void populateSimulation_ (Simulation *sim)
 Implements populateSimulation.
 
void runSimulator_ (Simulation *sim, uint64_t ticks)
 Implements runSimulator.
 
void postProcess_ (Simulation *sim)
 Implements postProcess.
 
virtual void postParse_ (po::basic_parsed_options< char > &opts)
 Callback before interpreting command parsed command line tokens.
 

Protected Attributes

SimulationConfiguration sim_config_
 Simulation configuration including default values.
 
FeatureConfiguration feature_config_
 Simulation feature configuration.
 
const std::string usage_
 Usage string specified at construction.
 
int argc_ = 0
 argc from main
 
char ** argv_ = nullptr
 argv from main
 
ReportDescVec reports_
 Vector of Report descriptors to instantiate on the simulator.
 
std::vector< std::string > report_descriptor_def_files_
 Vector of report descriptor definition files (YAML)
 
app::ReportYamlReplacements report_yaml_placeholder_replacements_
 Vector of yaml placeholder key-value pairs. These will be applied to the yamls given by "--report my_report_info.yaml".
 
std::unordered_map< std::string, app::ReportYamlReplacements > report_specific_yaml_placeholder_replacements_
 Map to hold report-specific yaml placeholder key-value pairs. An example usage might be: <sim> –report foo.yaml rep1.yaml –report bar.yaml rep2.yaml Where 'rep1.yaml' contains key-value replacements specifically for descriptor file 'foo.yaml', and 'rep2.yaml' contains those specifically for descriptor file 'bar.yaml'.
 
bool is_parsed_ = false
 Have the command line options been parsed yet by this class through the parse method.
 
bool is_setup_ = false
 Has the simulator been setup through the populateSimulation method.
 
uint64_t run_time_cycles_ = sparta::Scheduler::INDEFINITE
 Run-time user parameter.
 
uint64_t run_time_ticks_ = sparta::Scheduler::INDEFINITE
 
bool no_run_mode_ = false
 Is this simulator in no-run mode where it quits just before finalization.
 
std::string final_config_file_
 Destination to which final configuration (before running) will be written ("" if not written)
 
std::string read_final_config_ = ""
 The file to read from for reading in a final config file.
 
uint32_t config_applicators_used_ = 0
 number of non-final configuration applications used to modify parameters. A tally of all -p, –arch, –config-file. Does not include –read-final-config
 
std::string power_config_file_
 Destination to which power configuration (to be read by power model) will be written ("" if not written)
 
std::string final_config_file_verbose_
 Destination to which final configuration (before running) will be written ("" if not written). This file will also include descriptions of each parameter preceeding them with extra newlines.
 
bool no_show_config_ = false
 Should the trivialities of simulator configuration (e.g what command line options were specified) be hidden?
 
bool show_tree_ = false
 Display the device tree at every opportunity.
 
bool show_parameters_ = false
 Display all parameters in the device tree after building.
 
bool show_ports_ = false
 Display all ports in the device tree after finalization.
 
bool show_counters_ = false
 Display all counters and stats in the device tree after finalization.
 
bool show_clocks_ = false
 Display all the clocks in the tree.
 
bool show_pevents_ = false
 Display all the pevent types in the tree.
 
bool show_notifications_ = false
 Display all notifications in the device tree after finalization excluding log messages.
 
bool show_loggers_ = false
 Display all notifications in the device tree after finalization excluding log messages.
 
bool show_hidden_ = false
 Show hidden treenodes when displaying the device tree.
 
bool disable_colors_ = false
 Show hidden treenodes when displaying the device tree.
 
std::string dump_debug_type_ {"error"}
 Under what conditions should the debug content be dumped at simulator destruction. {always,never,error}.
 
std::string debug_dump_options_ {"all"}
 When a simulation error occurs and error logging is enabled, what content should the error log contain?
 
std::unique_ptr< sparta::trigger::Triggerable > pipeline_collection_triggerable_
 Instance of the pipeline collector if collection enabled.
 
std::unique_ptr< sparta::trigger::Trigger > pipeline_trigger_
 
std::unique_ptr< sparta::InformationWriter > info_out_
 
std::string pipeline_heartbeat_ = DefaultHeartbeat
 Heartbeat period of pipeline collection file (before lexical cast or validation)
 
std::set< std::string > pipeline_enabled_node_names_
 The names of the nodes to be enabled.
 
std::unique_ptr< sparta::trigger::Triggerable > pevent_trigger_
 The filename to log pevents too.
 
pevents::PeventCollectorController pevent_controller_
 a pevent controller is used to parse in pevent on and off commands, and prepare collection for the specified pevent types, this is different than pevent trigger because the controller only preps collectors, the trigger actually starts the trigger
 
bool run_pevents_ = false
 
std::string runtime_clock_
 The runtime clock to use for -r option.
 
std::string auto_summary_
 Automatic summary state. Determines what to do with the automatic summary after running.
 
std::string help_topic_
 Help topic to show.
 

Detailed Description

Command line simulator front-end class with argument parsing Works in conjunction with sparta::app::Simulation.

This class is extensible by clients by adding to its construction options before parsing (see parse) or by subclassing.

This class is intended to contain redundant sparta-enabled simulator code into a single set of classes to reduce the work necessary when implementing new simulators or maintaining a set of simulators and tests.

Additionally, this class helps ensure that the command-line look and feel of simulators and tests is consistent by providing the same argument names and documentation as other simulators

This class should mainly contain code relevant to setting up a simulator based on command-line options. Generic simulator setup code that might be invoked from a Python shell, remote interface, or something else does NOT belong in this class. Such common code should be in sparta::app::Simulation. If another simulation interface is desired, the functionality here should not need to be re-implemented.

Definition at line 84 of file CommandLineSimulator.hpp.

Constructor & Destructor Documentation

◆ CommandLineSimulator()

sparta::app::CommandLineSimulator::CommandLineSimulator ( const std::string &  usage,
const DefaultValues defs = DEFAULTS 
)

Construct.

Parameters
usageString describing usage of the simulator. Example:
* "Usage: ./sim_bin -r NUM_CYCLES [--other-args]"
* 

Member Function Documentation

◆ getAdvancedOptions()

MultiDetailOptions & sparta::app::CommandLineSimulator::getAdvancedOptions ( )
inline

Gets the advanced options for this simulator.

Definition at line 157 of file CommandLineSimulator.hpp.

◆ getApplicationOptions()

MultiDetailOptions & sparta::app::CommandLineSimulator::getApplicationOptions ( )
inline

Gets the application-specific options for this simulator.

Definition at line 150 of file CommandLineSimulator.hpp.

◆ getPositionalOptions()

po::positional_options_description & sparta::app::CommandLineSimulator::getPositionalOptions ( )
inline

Gets the boost positional options for the parser owned by this simulator.

Definition at line 165 of file CommandLineSimulator.hpp.

◆ getSimulationConfiguration() [1/2]

SimulationConfiguration & sparta::app::CommandLineSimulator::getSimulationConfiguration ( )
inline

Get the internal SimulationConfiguration this CommandLineSimulator uses

Definition at line 246 of file CommandLineSimulator.hpp.

◆ getSimulationConfiguration() [2/2]

const SimulationConfiguration & sparta::app::CommandLineSimulator::getSimulationConfiguration ( ) const
inline

Get the internal SimulationConfiguration this CommandLineSimulator uses

Definition at line 253 of file CommandLineSimulator.hpp.

◆ getSpartaOptions()

const MultiDetailOptions & sparta::app::CommandLineSimulator::getSpartaOptions ( ) const
inline

Gets the sparta-specific options for this simulator.

Note
This is a read-only result. Simulators must place their application-specific options in the application or advanced options sections
See also
getApplicationOptions
getAdvancedOptions

Definition at line 143 of file CommandLineSimulator.hpp.

◆ getUsage()

const std::string & sparta::app::CommandLineSimulator::getUsage ( ) const
inline

Gets the usage string specified for this simulator at construction. This string is printed when usage errors are encountered.

Definition at line 133 of file CommandLineSimulator.hpp.

◆ getVariablesMap()

const po::variables_map & sparta::app::CommandLineSimulator::getVariablesMap ( ) const
inline

Variables map populated by command-line parsing. This map is populated within the parse() method.

Definition at line 173 of file CommandLineSimulator.hpp.

◆ isParsed()

bool sparta::app::CommandLineSimulator::isParsed ( ) const
inline

Has this simulator parsed the command line yet Being parsed is required to call for populateSimulation.

Note
set to true after a successful call to parse

Definition at line 116 of file CommandLineSimulator.hpp.

◆ isRuntimeFinite()

bool sparta::app::CommandLineSimulator::isRuntimeFinite ( ) const
inline

Return whether this object is trying to run simulation for a finite amount of time via some command line argument.

Definition at line 236 of file CommandLineSimulator.hpp.

◆ isSetup()

bool sparta::app::CommandLineSimulator::isSetup ( ) const
inline

Has this simulator been setup yet? Being set up is required to call runSimulator.

Note
set to true after a successful call to populateSimulation

Definition at line 125 of file CommandLineSimulator.hpp.

◆ parse() [1/2]

int sparta::app::CommandLineSimulator::parse ( int  argc,
char **  argv 
)

DEPRECATED Shorthand version of other parse method,.

Note
THis is a deprecated signature and returns 0 on success, false on failure

◆ parse() [2/2]

bool sparta::app::CommandLineSimulator::parse ( int  argc,
char **  argv,
int &  err_code 
)

Parse command line options.

Parameters
simSimulation to configure after parsing
argccommand line arg count
argvcommand line parameter string vector
err_codeReference to value where parsing will store and error code. This is because this method could want the application to exit, but to use a zero error code.
Postcondition
If successful, isParsed will now return true
If failed, prints errors to cout
getVariablesMap() will return the populated variables map
Reconstructs the command-line string. See getCommandLine
Returns
true if application should continus and false if not. See err_code on failure for exit error code because returning false does not necessarily indicate an error (e.g. -h)
Exceptions
SpartaExceptionif anything cannot be parsed
Note
reparsing is not illegal, but is probably a bad idea

◆ populateSimulation()

void sparta::app::CommandLineSimulator::populateSimulation ( Simulation sim)

Builds the content of the simulator making it ready to run.

Note
It is the responsibiltiy of the caller to actually run the simulator manually or through CommandLineSimulator::runSimulator
Precondition
isParsed() must be true
Postcondition
isSetup() will be true

◆ postParse_()

virtual void sparta::app::CommandLineSimulator::postParse_ ( po::basic_parsed_options< char > &  opts)
inlineprotectedvirtual

Callback before interpreting command parsed command line tokens.

Parameters
optsParsed options with order information

Definition at line 278 of file CommandLineSimulator.hpp.

◆ postProcess()

void sparta::app::CommandLineSimulator::postProcess ( Simulation sim)

Post-process the results of the simulation if applicable.

Precondition
Simulator is done running and cannot be run again

Member Data Documentation

◆ argc_

int sparta::app::CommandLineSimulator::argc_ = 0
protected

argc from main

Definition at line 296 of file CommandLineSimulator.hpp.

◆ argv_

char** sparta::app::CommandLineSimulator::argv_ = nullptr
protected

argv from main

Definition at line 301 of file CommandLineSimulator.hpp.

◆ auto_summary_

std::string sparta::app::CommandLineSimulator::auto_summary_
protected

Automatic summary state. Determines what to do with the automatic summary after running.

Definition at line 492 of file CommandLineSimulator.hpp.

◆ config_applicators_used_

uint32_t sparta::app::CommandLineSimulator::config_applicators_used_ = 0
protected

number of non-final configuration applications used to modify parameters. A tally of all -p, –arch, –config-file. Does not include –read-final-config

Definition at line 367 of file CommandLineSimulator.hpp.

◆ debug_dump_options_

std::string sparta::app::CommandLineSimulator::debug_dump_options_ {"all"}
protected

When a simulation error occurs and error logging is enabled, what content should the error log contain?

  • Assert message, backtrace, and tree (default)
  • Assert message, backtrace
  • Assert message only

Definition at line 453 of file CommandLineSimulator.hpp.

◆ DEFAULTS

DefaultValues sparta::app::CommandLineSimulator::DEFAULTS
static

Static DefaultValues for a SPARTA CommandLineSimulator.

Definition at line 91 of file CommandLineSimulator.hpp.

◆ disable_colors_

bool sparta::app::CommandLineSimulator::disable_colors_ = false
protected

Show hidden treenodes when displaying the device tree.

Definition at line 438 of file CommandLineSimulator.hpp.

◆ dump_debug_type_

std::string sparta::app::CommandLineSimulator::dump_debug_type_ {"error"}
protected

Under what conditions should the debug content be dumped at simulator destruction. {always,never,error}.

Definition at line 444 of file CommandLineSimulator.hpp.

◆ feature_config_

FeatureConfiguration sparta::app::CommandLineSimulator::feature_config_
protected

Simulation feature configuration.

Definition at line 286 of file CommandLineSimulator.hpp.

◆ final_config_file_

std::string sparta::app::CommandLineSimulator::final_config_file_
protected

Destination to which final configuration (before running) will be written ("" if not written)

Definition at line 357 of file CommandLineSimulator.hpp.

◆ final_config_file_verbose_

std::string sparta::app::CommandLineSimulator::final_config_file_verbose_
protected

Destination to which final configuration (before running) will be written ("" if not written). This file will also include descriptions of each parameter preceeding them with extra newlines.

Definition at line 380 of file CommandLineSimulator.hpp.

◆ help_topic_

std::string sparta::app::CommandLineSimulator::help_topic_
protected

Help topic to show.

Definition at line 497 of file CommandLineSimulator.hpp.

◆ info_out_

std::unique_ptr<sparta::InformationWriter> sparta::app::CommandLineSimulator::info_out_
protected

Definition at line 460 of file CommandLineSimulator.hpp.

◆ is_parsed_

bool sparta::app::CommandLineSimulator::is_parsed_ = false
protected

Have the command line options been parsed yet by this class through the parse method.

Definition at line 334 of file CommandLineSimulator.hpp.

◆ is_setup_

bool sparta::app::CommandLineSimulator::is_setup_ = false
protected

Has the simulator been setup through the populateSimulation method.

Definition at line 339 of file CommandLineSimulator.hpp.

◆ no_run_mode_

bool sparta::app::CommandLineSimulator::no_run_mode_ = false
protected

Is this simulator in no-run mode where it quits just before finalization.

Definition at line 351 of file CommandLineSimulator.hpp.

◆ no_show_config_

bool sparta::app::CommandLineSimulator::no_show_config_ = false
protected

Should the trivialities of simulator configuration (e.g what command line options were specified) be hidden?

Definition at line 386 of file CommandLineSimulator.hpp.

◆ pevent_controller_

pevents::PeventCollectorController sparta::app::CommandLineSimulator::pevent_controller_
protected

a pevent controller is used to parse in pevent on and off commands, and prepare collection for the specified pevent types, this is different than pevent trigger because the controller only preps collectors, the trigger actually starts the trigger

Definition at line 482 of file CommandLineSimulator.hpp.

◆ pevent_trigger_

std::unique_ptr<sparta::trigger::Triggerable> sparta::app::CommandLineSimulator::pevent_trigger_
protected

The filename to log pevents too.

Definition at line 474 of file CommandLineSimulator.hpp.

◆ pipeline_collection_triggerable_

std::unique_ptr<sparta::trigger::Triggerable> sparta::app::CommandLineSimulator::pipeline_collection_triggerable_
protected

Instance of the pipeline collector if collection enabled.

Definition at line 458 of file CommandLineSimulator.hpp.

◆ pipeline_enabled_node_names_

std::set<std::string> sparta::app::CommandLineSimulator::pipeline_enabled_node_names_
protected

The names of the nodes to be enabled.

Definition at line 469 of file CommandLineSimulator.hpp.

◆ pipeline_heartbeat_

std::string sparta::app::CommandLineSimulator::pipeline_heartbeat_ = DefaultHeartbeat
protected

Heartbeat period of pipeline collection file (before lexical cast or validation)

Definition at line 466 of file CommandLineSimulator.hpp.

◆ pipeline_trigger_

std::unique_ptr<sparta::trigger::Trigger> sparta::app::CommandLineSimulator::pipeline_trigger_
protected

Definition at line 459 of file CommandLineSimulator.hpp.

◆ power_config_file_

std::string sparta::app::CommandLineSimulator::power_config_file_
protected

Destination to which power configuration (to be read by power model) will be written ("" if not written)

Definition at line 373 of file CommandLineSimulator.hpp.

◆ read_final_config_

std::string sparta::app::CommandLineSimulator::read_final_config_ = ""
protected

The file to read from for reading in a final config file.

Definition at line 362 of file CommandLineSimulator.hpp.

◆ report_descriptor_def_files_

std::vector<std::string> sparta::app::CommandLineSimulator::report_descriptor_def_files_
protected

Vector of report descriptor definition files (YAML)

Definition at line 311 of file CommandLineSimulator.hpp.

◆ report_specific_yaml_placeholder_replacements_

std::unordered_map<std::string, app::ReportYamlReplacements> sparta::app::CommandLineSimulator::report_specific_yaml_placeholder_replacements_
protected

Map to hold report-specific yaml placeholder key-value pairs. An example usage might be: <sim> –report foo.yaml rep1.yaml –report bar.yaml rep2.yaml Where 'rep1.yaml' contains key-value replacements specifically for descriptor file 'foo.yaml', and 'rep2.yaml' contains those specifically for descriptor file 'bar.yaml'.

Definition at line 328 of file CommandLineSimulator.hpp.

◆ report_yaml_placeholder_replacements_

app::ReportYamlReplacements sparta::app::CommandLineSimulator::report_yaml_placeholder_replacements_
protected

Vector of yaml placeholder key-value pairs. These will be applied to the yamls given by "--report my_report_info.yaml".

Definition at line 317 of file CommandLineSimulator.hpp.

◆ reports_

ReportDescVec sparta::app::CommandLineSimulator::reports_
protected

Vector of Report descriptors to instantiate on the simulator.

Definition at line 306 of file CommandLineSimulator.hpp.

◆ run_pevents_

bool sparta::app::CommandLineSimulator::run_pevents_ = false
protected

Definition at line 483 of file CommandLineSimulator.hpp.

◆ run_time_cycles_

uint64_t sparta::app::CommandLineSimulator::run_time_cycles_ = sparta::Scheduler::INDEFINITE
protected

Run-time user parameter.

Definition at line 344 of file CommandLineSimulator.hpp.

◆ run_time_ticks_

uint64_t sparta::app::CommandLineSimulator::run_time_ticks_ = sparta::Scheduler::INDEFINITE
protected

Definition at line 345 of file CommandLineSimulator.hpp.

◆ runtime_clock_

std::string sparta::app::CommandLineSimulator::runtime_clock_
protected

The runtime clock to use for -r option.

Definition at line 486 of file CommandLineSimulator.hpp.

◆ show_clocks_

bool sparta::app::CommandLineSimulator::show_clocks_ = false
protected

Display all the clocks in the tree.

Definition at line 412 of file CommandLineSimulator.hpp.

◆ show_counters_

bool sparta::app::CommandLineSimulator::show_counters_ = false
protected

Display all counters and stats in the device tree after finalization.

Definition at line 407 of file CommandLineSimulator.hpp.

◆ show_hidden_

bool sparta::app::CommandLineSimulator::show_hidden_ = false
protected

Show hidden treenodes when displaying the device tree.

Definition at line 433 of file CommandLineSimulator.hpp.

◆ show_loggers_

bool sparta::app::CommandLineSimulator::show_loggers_ = false
protected

Display all notifications in the device tree after finalization excluding log messages.

Definition at line 428 of file CommandLineSimulator.hpp.

◆ show_notifications_

bool sparta::app::CommandLineSimulator::show_notifications_ = false
protected

Display all notifications in the device tree after finalization excluding log messages.

Definition at line 422 of file CommandLineSimulator.hpp.

◆ show_parameters_

bool sparta::app::CommandLineSimulator::show_parameters_ = false
protected

Display all parameters in the device tree after building.

Definition at line 396 of file CommandLineSimulator.hpp.

◆ show_pevents_

bool sparta::app::CommandLineSimulator::show_pevents_ = false
protected

Display all the pevent types in the tree.

Definition at line 417 of file CommandLineSimulator.hpp.

◆ show_ports_

bool sparta::app::CommandLineSimulator::show_ports_ = false
protected

Display all ports in the device tree after finalization.

Definition at line 401 of file CommandLineSimulator.hpp.

◆ show_tree_

bool sparta::app::CommandLineSimulator::show_tree_ = false
protected

Display the device tree at every opportunity.

Definition at line 391 of file CommandLineSimulator.hpp.

◆ sim_config_

SimulationConfiguration sparta::app::CommandLineSimulator::sim_config_
protected

Simulation configuration including default values.

Definition at line 283 of file CommandLineSimulator.hpp.

◆ usage_

const std::string sparta::app::CommandLineSimulator::usage_
protected

Usage string specified at construction.

Definition at line 291 of file CommandLineSimulator.hpp.


The documentation for this class was generated from the following file: