Commit 109bb971 authored by kulvait's avatar kulvait

Time reporting

*Improved program reporting of the time
parent 1a2eaba5
#pragma once
#include "PROG/parseArgs.h"
#include "CLI/CLI.hpp" //Command line parser
#include "PROG/parseArgs.h"
namespace CTL::util {
class Arguments
{
public:
Arguments(int argc, char ** argv, std::string appName="");
Arguments(int argc, char** argv, std::string appName = "");
std::shared_ptr<CLI::App> getCliApp();
//Call this function for parsing
int parse();
virtual void defineArguments() = 0;
virtual int preParse() = 0;
virtual int postParse() = 0;
// Call this function for parsing
/**
* @brief
*
* @param helpOnError Whether to print a help message on parsing error.
*
* @return
*/
int parse(bool helpOnError = true);
virtual void defineArguments() = 0;
virtual int preParse() = 0;
virtual int postParse() = 0;
protected:
std::shared_ptr<CLI::App> cliApp;
int argc;
char ** argv;
int argc;
char** argv;
};
} // namespace CTL
} // namespace CTL::util
......@@ -9,7 +9,7 @@ Arguments::Arguments(int argc, char* argv[], std::string appName)
cliApp = std::make_shared<CLI::App>(appName);
}
int Arguments::parse()
int Arguments::parse(bool helpOnError)
{
this->defineArguments();
try
......@@ -33,8 +33,11 @@ int Arguments::parse()
} catch(const CLI::ParseError& e)
{
int exitcode = cliApp->exit(e);
LOGE << io::xprintf("There was perse error with exit code %d catched.\n %s", exitcode,
cliApp->help().c_str());
LOGE << io::xprintf("There was perse error with exit code %d catched.", exitcode);
if(helpOnError)
{
std::cout << cliApp->help();
}
return -1;
} catch(...)
{
......
......@@ -25,12 +25,30 @@ void Program::startLog() { LOGI << io::xprintf("START %s", rti.getExecutableName
void Program::endLog(bool reportTimings)
{
using namespace std::chrono;
if(reportTimings)
{
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(
auto t = std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::steady_clock::now() - start_time);
LOGI << io::xprintf("END %s, duration %0.3f s.", rti.getExecutableName().c_str(),
float(duration.count() / 1000.0f));
auto min = duration_cast<minutes>(t);
t -= duration_cast<milliseconds>(min);
auto h = duration_cast<hours>(min);
min -= duration_cast<minutes>(h);
if(h.count() > 0)
{
LOGI << io::xprintf("END %s, duration %02dh %02dm %02.3fs.",
rti.getExecutableName().c_str(), h.count(), min.count(),
float(t.count() / 1000.0f));
} else if(min.count() > 0)
{
LOGI << io::xprintf("END %s, duration %02dm %02.3fs.",
rti.getExecutableName().c_str(), min.count(),
float(t.count() / 1000.0f));
} else
{
LOGI << io::xprintf("END %s, duration %02.3fs.", rti.getExecutableName().c_str(),
float(t.count() / 1000.0f));
}
} else
{
LOGI << io::xprintf("END %s", rti.getExecutableName().c_str());
......
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