12 #include "hebench/modules/args_parser/include/args_parser.h" 
   16 using namespace std::literals;
 
   28     static constexpr 
const char *TimeUnit         = 
"--time_unit";
 
   29     static constexpr 
const char *TimeUnitStats    = 
"--time_unit_stats";
 
   30     static constexpr 
const char *TimeUnitOverview = 
"--time_unit_overview";
 
   31     static constexpr 
const char *TimeUnitSummary  = 
"--time_unit_summary";
 
   32     static constexpr 
const char *ShowOverview     = 
"--show_overview";
 
   33     static constexpr 
const char *SilentRun        = 
"--silent_run";
 
   35     static constexpr 
bool DefaultShowOverView = 
true;
 
   40     static std::string getTimeUnitName(
char time_unit, 
const std::string &default_name = 
"(default)");
 
   43     static const std::unordered_set<std::string> m_allowed_time_units;
 
   46 const std::unordered_set<std::string> ProgramConfig::m_allowed_time_units({ 
"s", 
"ms", 
"us", 
"ns" });
 
   54         retval = 
"milliseconds";
 
   57         retval = 
"microseconds";
 
   60         retval = 
"nanoseconds";
 
   63         retval = default_name;
 
   71     input_file = parser.getPositionalValue(0);
 
   72     input_file = std::filesystem::canonical(input_file);
 
   74     parser.getValue<
bool>(b_show_overview, ShowOverview, DefaultShowOverView);
 
   75     b_silent = parser.hasArgument(SilentRun);
 
   79     if (parser.hasArgument(TimeUnit))
 
   81         parser.getValue<std::string>(s_tmp, TimeUnit);
 
   82         if (m_allowed_time_units.count(s_tmp) <= 0)
 
   83             throw hebench::ArgsParser::InvalidArgument(
"Invalid argument value for parameter \"" + std::string(TimeUnit) + 
"\": " + s_tmp);
 
   85     time_unit = s_tmp.empty() ? 0 : s_tmp.front();
 
   88     if (parser.hasArgument(TimeUnitOverview))
 
   90         parser.getValue<std::string>(s_tmp, TimeUnitOverview);
 
   91         if (m_allowed_time_units.count(s_tmp) <= 0)
 
   92             throw hebench::ArgsParser::InvalidArgument(
"Invalid argument value for parameter \"" + std::string(TimeUnitOverview) + 
"\": " + s_tmp);
 
   94     time_unit_overview = s_tmp.empty() ? 0 : s_tmp.front();
 
   97     if (parser.hasArgument(TimeUnitStats))
 
   99         parser.getValue<std::string>(s_tmp, TimeUnitStats);
 
  100         if (m_allowed_time_units.count(s_tmp) <= 0)
 
  101             throw hebench::ArgsParser::InvalidArgument(
"Invalid argument value for parameter \"" + std::string(TimeUnitStats) + 
"\": " + s_tmp);
 
  103     time_unit_stats = s_tmp.empty() ? 0 : s_tmp.front();
 
  106     if (parser.hasArgument(TimeUnitSummary))
 
  108         parser.getValue<std::string>(s_tmp, TimeUnitSummary);
 
  109         if (m_allowed_time_units.count(s_tmp) <= 0)
 
  110             throw hebench::ArgsParser::InvalidArgument(
"Invalid argument value for parameter \"" + std::string(TimeUnitSummary) + 
"\": " + s_tmp);
 
  112     time_unit_summary = s_tmp.empty() ? 0 : s_tmp.front();
 
  117     std::string fallback_time_unit = getTimeUnitName(time_unit);
 
  118     os << 
"==================" << std::endl
 
  119        << 
"Global Configuration:" << std::endl
 
  120        << 
"    Input file: " << input_file << std::endl
 
  121        << 
"    Show overview: " << (b_show_overview ? 
"Yes" : 
"No") << std::endl
 
  122        << 
"    Overview time unit: " << (time_unit_overview == 0 ? fallback_time_unit : getTimeUnitName(time_unit_overview)) << std::endl
 
  123        << 
"    Summary time unit: " << (time_unit_summary == 0 ? fallback_time_unit : getTimeUnitName(time_unit_summary)) << std::endl
 
  124        << 
"    Statistics time unit: " << (time_unit_stats == 0 ? fallback_time_unit : getTimeUnitName(time_unit_stats)) << std::endl;
 
  125     os << 
"==================" << std::endl;
 
  135     parser.addPositionalArgument(
"input_file",
 
  136                                  "    Input file to be used during report generation. This can be a single\n" 
  137                                  "    benchmark report generated by Test Harness or a file containing a list\n" 
  138                                  "    of report files to process. The directory for this file must be\n" 
  139                                  "    available for writing.");
 
  141                        "    [OPTIONAL] Specifies the time unit to be used for the generated reports\n" 
  142                        "    if no time unit is specified for a report type. The value of this\n" 
  143                        "    parameter must be one of:\n" 
  145                        "      \"ms\" - milliseconds\n" 
  146                        "      \"us\" - microseconds\n" 
  147                        "      \"ns\" - nanoseconds\n" 
  148                        "    If missing, an appropriate unit will be automatically selected per\n" 
  151                        "    [OPTIONAL] Specifies the time unit to be used for the generated overview.\n" 
  152                        "    If no time unit is specified, the fallback time unit specified for\n" 
  156                        "    [OPTIONAL] Specifies the time unit to be used for the generated\n" 
  157                        "    statistics. If no time unit is specified, the fallback time unit\n" 
  158                        "    specified for parameter `" 
  161                        "    [OPTIONAL] Specifies the time unit to be used for the generated\n" 
  162                        "    summaries. If no time unit is specified, the fallback time unit\n" 
  163                        "    specified for parameter `" 
  166                        "    [OPTIONAL] Specifies whether or not to display report overview to\n" 
  167                        "    standard output. If option is missing, default is \"true\".");
 
  169                        "    [OPTIONAL] When present, this flag indicates that the run must be\n" 
  170                        "    silent. Only specifically requested outputs will be displayed to\n" 
  171                        "    standard output. When running silent, important messages, warnings and\n" 
  172                        "    errors will be sent to standard error stream `stderr`.");
 
  173     parser.parse(argc, argv);
 
  176 int main(
int argc, 
char **argv)
 
  180     std::stringstream ss_err;
 
  182     hebench::ArgsParser args_parser;
 
  191             std::cout << 
"HEBench Report Compiler" << std::endl
 
  194             std::cout << std::endl;
 
  198         std::string s_input_file = config.
input_file.string();
 
  199         std::vector<char> c_error_msg(1024, 0);
 
  201         compile_config.
input_file         = s_input_file.c_str();
 
  210             throw std::runtime_error(c_error_msg.data());
 
  212     catch (hebench::ArgsParser::HelpShown &)
 
  216     catch (hebench::ArgsParser::InvalidArgument &ap_ex)
 
  218         ss_err << 
"Error occurred with message: " << std::endl
 
  219                << ap_ex.what() << std::endl
 
  221         args_parser.printUsage(ss_err);
 
  224     catch (std::exception &ex)
 
  226         ss_err << 
"ERROR: " << std::endl
 
  227                << ex.what() << std::endl;
 
  232         ss_err << 
"Unexpected error occurred!" << std::endl;
 
  238         std::cerr << std::endl
 
  239                   << ss_err.str() << std::endl
 
  240                   << 
"Terminated with errors." << std::endl;
 
  243         std::cout << std::endl
 
  244                   << 
"Complete!" << std::endl;
 
char time_unit_overview
Time unit for report overview. If 0, the fallback time_unit will be used.
int32_t b_silent
If non-zero, the run details will be omited. Any warning, error, or important messages are directed t...
const char * input_file
C-string containing the input file name.
char time_unit_stats
Time unit for report statistics. If 0, the fallback time_unit will be used.
int32_t compile(const ReportCompilerConfigC *p_config, char *s_error, size_t s_error_size)
Runs the compiler using the specified configuration.
char time_unit_summary
Time unit for report summaries. If 0, the fallback time_unit will be used.
int32_t b_show_overview
If non-zero, the compiled overview will be output to stdout.
char time_unit
Fallback time unit when no time unit is specified for a specific output.
Configuration for a compiler run.
int main(int argc, char **argv)
void initArgsParser(hebench::ArgsParser &parser, int argc, char **argv)
static constexpr const char * ShowOverview
std::filesystem::path input_file
void initializeConfig(const hebench::ArgsParser &parser)
static std::ostream & showVersion(std::ostream &os)
static constexpr const char * TimeUnit
static constexpr const char * TimeUnitSummary
static void showVersion(std::ostream &os)
static constexpr const char * TimeUnitOverview
void showConfig(std::ostream &os) const
static std::string getTimeUnitName(char time_unit, const std::string &default_name="(default)")
static constexpr const char * SilentRun
static constexpr const char * TimeUnitStats