xaizek / etabench (License: GPLv3) (since 2022-09-08)
Benchmark for algorithms that compute I/O ETA
<root> / src / Args.cpp (2c6225da939b456a4428ffd88e14d2f725e5cf3f) (4,695B) (mode 100644) [raw]
// etabench
// Copyright (C) 2022 xaizek <xaizek@posteo.net>
//
// This file is part of etabench.
//
// etabench is free software: you can redistribute it and/or modify
// it under the terms of version 3 of the GNU General Public License
// as published by the Free Software Foundation.
//
// etabench is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with etabench.  If not, see <https://www.gnu.org/licenses/>.

#include "Args.hpp"

#include <cstdlib>

#include <stdexcept>

#include <tclap/CmdLine.h>

Args::Args(int argc, char *argv[])
{
    TCLAP::CmdLine cmd("I/O ETA benchmark.", ' ', "0.1", /*help=*/false);

    TCLAP::ValueArg<int> totalArg("",
                                  "total",
                                  "Simulated transfer total.",
                                  /*req=*/false,
                                  1000,
                                  "integer",
                                  cmd);

    TCLAP::ValueArg<std::string> plotArg("",
                                         "plot",
                                         "Use gnuplot to make graphs per "
                                         "profile in <dir>.",
                                         /*req=*/false,
                                         "",
                                         "dir",
                                         cmd);

    TCLAP::ValueArg<std::string> montageArg("",
                                            "montage",
                                            "Use ImageMagick to montage plots "
                                            "in <file>.",
                                            /*req=*/false,
                                            "",
                                            "file",
                                            cmd);

    TCLAP::SwitchArg listAlgsArg("",
                                 "list-algs",
                                 "List available algorithms.",
                                 cmd,
                                 /*def=*/false);

    TCLAP::SwitchArg listProfsArg("",
                                  "list-profs",
                                  "List available profiles.",
                                  cmd,
                                  /*def=*/false);

    TCLAP::ValueArg<std::string> algsArg("",
                                         "algs",
                                         "List of algorithms to benchmark.",
                                         /*req=*/false,
                                         /*def=*/std::string(),
                                         "list",
                                         cmd);

    TCLAP::ValueArg<std::string> profsArg("",
                                          "profs",
                                          "List of profiles to benchmark.",
                                          /*req=*/false,
                                          /*def=*/std::string(),
                                          "list",
                                          cmd);

    TCLAP::SwitchArg verboseArg("",
                                "verbose",
                                "Display verbose output.",
                                cmd,
                                /*def=*/false);

    TCLAP::SwitchArg help("h",
                          "help",
                          "Displays usage information and exits.",
                          cmd,
                          /*def=*/false);

    TCLAP::SwitchArg vers("v",
                          "version",
                          "Displays version information and exits.",
                          cmd,
                          /*def=*/false);

    cmd.parse(argc, argv);

    if (help) {
        TCLAP::StdOutput stdOutput;
        stdOutput.usage(cmd);
        std::exit(0);
    }

    if (vers) {
        TCLAP::StdOutput stdOutput;
        stdOutput.version(cmd);
        std::exit(0);
    }

    total = totalArg;
    plotDir = plotArg;
    montageFile = montageArg;
    verbose = verboseArg;
    listAlgs = listAlgsArg;
    listProfs = listProfsArg;
    algs = algsArg;
    profs = profsArg;

    // The value is limited because of hard-coded values in profiles.  Deriving
    // them or correcting code can remove the limit.  The latter option sounds
    // better.
    if (total < 50) {
        throw std::runtime_error("--total must be at least 50.");
    }
}
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/etabench

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/etabench

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master