Compute Library
 22.11
CommonOptions Class Reference

Common command line options used to configure the framework. More...

#include <CommonOptions.h>

Collaboration diagram for CommonOptions:
[legend]

Public Member Functions

 CommonOptions (arm_compute::utils::CommandLineParser &parser)
 Constructor. More...
 
 CommonOptions (const CommonOptions &)=delete
 Prevent instances of this class from being copy constructed. More...
 
CommonOptionsoperator= (const CommonOptions &)=delete
 Prevent instances of this class from being copied. More...
 
std::vector< std::unique_ptr< Printer > > create_printers ()
 Create the printers based on parsed command line options. More...
 

Data Fields

arm_compute::utils::ToggleOptionhelp
 Show help option. More...
 
arm_compute::utils::EnumListOption< InstrumentsDescription > * instruments
 Instruments option. More...
 
arm_compute::utils::SimpleOption< int > * iterations
 Number of iterations option. More...
 
arm_compute::utils::EnumOption< LogFormat > * log_format
 Log format option. More...
 
arm_compute::utils::SimpleOption< std::string > * log_file
 Log file option. More...
 
arm_compute::utils::EnumOption< LogLevel > * log_level
 Logging level option. More...
 
arm_compute::utils::ToggleOptionthrow_errors
 Throw errors option. More...
 
arm_compute::utils::ToggleOptioncolor_output
 Color output option. More...
 
arm_compute::utils::ToggleOptionpretty_console
 Pretty console option. More...
 
arm_compute::utils::SimpleOption< std::string > * json_file
 JSON output file option. More...
 
arm_compute::utils::SimpleOption< std::string > * pretty_file
 Pretty output file option. More...
 
std::vector< std::shared_ptr< std::ofstream > > log_streams
 Log streams. More...
 

Detailed Description

Common command line options used to configure the framework.

The options in this object get populated when "parse()" is called on the parser used to construct it. The expected workflow is:

CommandLineParser parser; CommonOptions options( parser ); parser.parse(argc, argv); if(options.log_level->value() > LogLevel::NONE) –> Use the options values

Definition at line 54 of file CommonOptions.h.

Constructor & Destructor Documentation

◆ CommonOptions() [1/2]

Constructor.

Parameters
[in,out]parserA parser on which "parse()" hasn't been called yet.

Definition at line 40 of file CommonOptions.cpp.

References CommandLineParser::add_option(), arm_compute::test::framework::ALL, Framework::available_instruments(), CommonOptions::color_output, arm_compute::test::framework::CONFIG, arm_compute::test::framework::DEBUG, arm_compute::test::framework::ERRORS, Framework::get(), CommonOptions::help, CommonOptions::instruments, CommonOptions::iterations, arm_compute::test::framework::JSON, CommonOptions::json_file, CommonOptions::log_file, CommonOptions::log_format, CommonOptions::log_level, arm_compute::test::framework::MEASUREMENTS, arm_compute::test::framework::NONE, arm_compute::test::framework::PRETTY, CommonOptions::pretty_console, CommonOptions::pretty_file, Option::set_help(), arm_compute::test::framework::TESTS, CommonOptions::throw_errors, type, and arm_compute::test::framework::WALL_CLOCK_TIMER.

41  : help(parser.add_option<ToggleOption>("help")),
42  instruments(),
43  iterations(parser.add_option<SimpleOption<int>>("iterations", 1)),
44  log_format(),
45  log_file(parser.add_option<SimpleOption<std::string>>("log-file")),
46  log_level(),
47  throw_errors(parser.add_option<ToggleOption>("throw-errors")),
48 #if !defined(_WIN64)
49  color_output(parser.add_option<ToggleOption>("color-output", isatty(STDOUT_FILENO))), // Only enable colors by default if we're running in a terminal
50 #endif // !defined(_WIN64)
51  pretty_console(parser.add_option<ToggleOption>("pretty-console", false)),
52  json_file(parser.add_option<SimpleOption<std::string>>("json-file")),
53  pretty_file(parser.add_option<SimpleOption<std::string>>("pretty-file")),
54  log_streams()
55 {
56  Framework &framework = Framework::get();
57  std::set<InstrumentsDescription> allowed_instruments
58  {
59  std::pair<InstrumentType, ScaleFactor>(InstrumentType::ALL, ScaleFactor::NONE),
60  std::pair<InstrumentType, ScaleFactor>(InstrumentType::NONE, ScaleFactor::NONE),
61  };
62 
63  for(const auto &type : framework.available_instruments())
64  {
65  allowed_instruments.insert(type);
66  }
67 
68  std::set<LogFormat> supported_log_formats
69  {
73  };
74 
75  std::set<LogLevel> supported_log_levels
76  {
84  };
85 
86  instruments = parser.add_option<EnumListOption<InstrumentsDescription>>("instruments", allowed_instruments, std::initializer_list<InstrumentsDescription> { std::pair<InstrumentType, ScaleFactor>(InstrumentType::WALL_CLOCK_TIMER, ScaleFactor::NONE) });
87  log_format = parser.add_option<EnumOption<LogFormat>>("log-format", supported_log_formats, LogFormat::PRETTY);
88  log_level = parser.add_option<EnumOption<LogLevel>>("log-level", supported_log_levels, LogLevel::ALL);
89 
90  help->set_help("Show this help message");
91  instruments->set_help("Set the profiling instruments to use");
92  iterations->set_help("Number of iterations per test case");
93  log_format->set_help("Output format for measurements and failures (affects only log-file)");
94  log_file->set_help("Write output to file instead of to the console (affected by log-format)");
95  log_level->set_help("Verbosity of the output");
96  throw_errors->set_help("Don't catch fatal errors (useful for debugging)");
97  color_output->set_help("Produce colored output on the console");
98  pretty_console->set_help("Produce pretty output on the console");
99  json_file->set_help("Write output to a json file.");
100  pretty_file->set_help("Write output to a text file");
101 }
arm_compute::utils::ToggleOption * help
Show help option.
Definition: CommonOptions.h:74
arm_compute::utils::EnumOption< LogFormat > * log_format
Log format option.
Definition: CommonOptions.h:77
Implementation of an option that can be either true or false.
Definition: ToggleOption.h:36
arm_compute::utils::ToggleOption * color_output
Color output option.
Definition: CommonOptions.h:81
decltype(strategy::transforms) typedef type
static Framework & get()
Access to the singleton.
Definition: Framework.cpp:124
T * add_option(const std::string &name, As &&... args)
Function to add a new option to the parser.
std::vector< std::shared_ptr< std::ofstream > > log_streams
Log streams.
Definition: CommonOptions.h:85
arm_compute::utils::SimpleOption< std::string > * pretty_file
Pretty output file option.
Definition: CommonOptions.h:84
arm_compute::utils::SimpleOption< int > * iterations
Number of iterations option.
Definition: CommonOptions.h:76
arm_compute::utils::EnumListOption< InstrumentsDescription > * instruments
Instruments option.
Definition: CommonOptions.h:75
arm_compute::utils::EnumOption< LogLevel > * log_level
Logging level option.
Definition: CommonOptions.h:79
arm_compute::utils::SimpleOption< std::string > * log_file
Log file option.
Definition: CommonOptions.h:78
arm_compute::utils::ToggleOption * pretty_console
Pretty console option.
Definition: CommonOptions.h:82
arm_compute::utils::SimpleOption< std::string > * json_file
JSON output file option.
Definition: CommonOptions.h:83
void set_help(std::string help)
Set the help message for the option.
Definition: Option.h:125
arm_compute::utils::ToggleOption * throw_errors
Throw errors option.
Definition: CommonOptions.h:80

◆ CommonOptions() [2/2]

CommonOptions ( const CommonOptions )
delete

Prevent instances of this class from being copy constructed.

Member Function Documentation

◆ create_printers()

std::vector< std::unique_ptr< Printer > > create_printers ( )

Create the printers based on parsed command line options.

Precondition
"parse()" has been called on the parser used to construct this object
Returns
List of printers

Definition at line 102 of file CommonOptions.cpp.

References CommonOptions::color_output, Option::is_set(), arm_compute::test::framework::JSON, CommonOptions::json_file, CommonOptions::log_file, CommonOptions::log_format, CommonOptions::log_streams, arm_compute::test::framework::NONE, arm_compute::test::framework::PRETTY, CommonOptions::pretty_console, CommonOptions::pretty_file, EnumOption< T >::value(), and SimpleOption< T >::value().

Referenced by main(), and arm_compute::utils::run_example().

103 {
104  std::vector<std::unique_ptr<Printer>> printers;
105 
107  {
108  auto pretty_printer = std::make_unique<PrettyPrinter>();
109  pretty_printer->set_color_output(color_output->value());
110  printers.push_back(std::move(pretty_printer));
111  }
112 
113  std::unique_ptr<Printer> printer;
114  switch(log_format->value())
115  {
116  case LogFormat::JSON:
117  printer = std::make_unique<JSONPrinter>();
118  break;
119  case LogFormat::NONE:
120  break;
121  case LogFormat::PRETTY:
122  default:
123  auto pretty_printer = std::make_unique<PrettyPrinter>();
124  // Don't use colours if we print to a file:
125  pretty_printer->set_color_output((!log_file->is_set()) && color_output->value());
126  printer = std::move(pretty_printer);
127  break;
128  }
129 
130  if(log_file->is_set())
131  {
132  log_streams.push_back(std::make_shared<std::ofstream>(log_file->value()));
133  if(printer != nullptr)
134  {
135  printer->set_stream(*log_streams.back().get());
136  }
137  }
138 
139  if(printer != nullptr)
140  {
141  printers.push_back(std::move(printer));
142  }
143 
144  if(json_file->is_set())
145  {
146  printers.push_back(std::make_unique<JSONPrinter>());
147  log_streams.push_back(std::make_shared<std::ofstream>(json_file->value()));
148  printers.back()->set_stream(*log_streams.back().get());
149  }
150 
151  if(pretty_file->is_set())
152  {
153  printers.push_back(std::make_unique<PrettyPrinter>());
154  log_streams.push_back(std::make_shared<std::ofstream>(pretty_file->value()));
155  printers.back()->set_stream(*log_streams.back().get());
156  }
157 
158  return printers;
159 }
arm_compute::utils::EnumOption< LogFormat > * log_format
Log format option.
Definition: CommonOptions.h:77
arm_compute::utils::ToggleOption * color_output
Color output option.
Definition: CommonOptions.h:81
std::vector< std::shared_ptr< std::ofstream > > log_streams
Log streams.
Definition: CommonOptions.h:85
arm_compute::utils::SimpleOption< std::string > * pretty_file
Pretty output file option.
Definition: CommonOptions.h:84
const T & value() const
Get the option value.
Definition: SimpleOption.h:112
bool is_set() const
Has a value been assigned to the option?
Definition: Option.h:135
arm_compute::utils::SimpleOption< std::string > * log_file
Log file option.
Definition: CommonOptions.h:78
const T & value() const
Get the selected value.
arm_compute::utils::ToggleOption * pretty_console
Pretty console option.
Definition: CommonOptions.h:82
arm_compute::utils::SimpleOption< std::string > * json_file
JSON output file option.
Definition: CommonOptions.h:83

◆ operator=()

CommonOptions& operator= ( const CommonOptions )
delete

Prevent instances of this class from being copied.

Field Documentation

◆ color_output

Color output option.

Definition at line 81 of file CommonOptions.h.

Referenced by CommonOptions::CommonOptions(), and CommonOptions::create_printers().

◆ help

Show help option.

Definition at line 74 of file CommonOptions.h.

Referenced by CommonOptions::CommonOptions(), main(), and arm_compute::utils::run_example().

◆ instruments

◆ iterations

Number of iterations option.

Definition at line 76 of file CommonOptions.h.

Referenced by CommonOptions::CommonOptions(), main(), and arm_compute::utils::run_example().

◆ json_file

arm_compute::utils::SimpleOption<std::string>* json_file

JSON output file option.

Definition at line 83 of file CommonOptions.h.

Referenced by CommonOptions::CommonOptions(), and CommonOptions::create_printers().

◆ log_file

arm_compute::utils::SimpleOption<std::string>* log_file

Log file option.

Definition at line 78 of file CommonOptions.h.

Referenced by CommonOptions::CommonOptions(), and CommonOptions::create_printers().

◆ log_format

Log format option.

Definition at line 77 of file CommonOptions.h.

Referenced by CommonOptions::CommonOptions(), and CommonOptions::create_printers().

◆ log_level

Logging level option.

Definition at line 79 of file CommonOptions.h.

Referenced by CommonOptions::CommonOptions(), main(), and arm_compute::utils::run_example().

◆ log_streams

std::vector<std::shared_ptr<std::ofstream> > log_streams

Log streams.

Definition at line 85 of file CommonOptions.h.

Referenced by CommonOptions::create_printers().

◆ pretty_console

Pretty console option.

Definition at line 82 of file CommonOptions.h.

Referenced by CommonOptions::CommonOptions(), and CommonOptions::create_printers().

◆ pretty_file

arm_compute::utils::SimpleOption<std::string>* pretty_file

Pretty output file option.

Definition at line 84 of file CommonOptions.h.

Referenced by CommonOptions::CommonOptions(), and CommonOptions::create_printers().

◆ throw_errors

Throw errors option.

Definition at line 80 of file CommonOptions.h.

Referenced by CommonOptions::CommonOptions(), main(), and arm_compute::utils::run_example().


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