command line parameter

- store most importend parameter in a singleton
- use config file parameter
This commit is contained in:
psychocrypt
2017-09-30 23:46:08 +02:00
parent 0e4cbe2643
commit 085f8c2584
14 changed files with 174 additions and 48 deletions
+3 -3
View File
@@ -8,6 +8,7 @@ namespace xmrstak
{
class GlobalStates;
class Params;
struct Environment
{
@@ -24,6 +25,7 @@ struct Environment
this->pGlobalStates = env.pGlobalStates;
this->pJconfConfig = env.pJconfConfig;
this->pExecutor = env.pExecutor;
this->pParams = env.pParams;
return *this;
}
@@ -34,12 +36,10 @@ struct Environment
printer* pPrinter;
GlobalStates* pGlobalStates;
jconf* pJconfConfig;
executor* pExecutor;
Params* pParams;
};
+45
View File
@@ -0,0 +1,45 @@
#pragma once
#include <string>
#include "Environment.hpp"
namespace xmrstak
{
struct Params
{
static inline Params& inst()
{
auto& env = Environment::inst();
if(env.pParams == nullptr)
env.pParams = new Params;
return *env.pParams;
}
std::string executablePrefix;
bool useAMD;
bool useNVIDIA;
bool useCPU;
std::string poolURL;
std::string poolPasswd;
std::string poolUsername;
std::string configFile;
std::string configFileAMD;
std::string configFileNVIDIA;
std::string configFileCPU;
Params() :
useAMD(true),
useNVIDIA(true),
useCPU(true),
configFile("config.txt"),
configFileAMD("amd.txt"),
configFileCPU("cpu.txt"),
configFileNVIDIA("nvidia.txt")
{}
};
} // namepsace xmrstak
+3 -2
View File
@@ -8,6 +8,7 @@
#include "../../console.h"
#include "../../ConfigEditor.hpp"
#include "amd_gpu/gpu.h"
#include "../../Params.hpp"
#include <vector>
#include <cstdio>
@@ -102,8 +103,8 @@ private:
configTpl.replace("PLATFORMINDEX",std::to_string(platformIndex));
configTpl.replace("NUMGPUS",std::to_string(devVec.size()));
configTpl.replace("GPUCONFIG",conf);
configTpl.write("amd.txt");
printer::inst()->print_msg(L0, "AMD: GPU configuration stored in file '%s'", "amd.txt");
configTpl.write(Params::inst().configFileAMD);
printer::inst()->print_msg(L0, "AMD: GPU configuration stored in file '%s'", Params::inst().configFileAMD.c_str());
}
std::vector<GpuContext> devVec;
+2 -1
View File
@@ -1,6 +1,7 @@
#pragma once
#include <stdlib.h>
#include <string>
#include "../../Params.hpp"
namespace xmrstak
{
@@ -16,7 +17,7 @@ public:
return oInst;
};
bool parse_config(const char* sFilename = "amd.txt");
bool parse_config(const char* sFilename = Params::inst().configFileAMD.c_str());
struct thd_cfg {
size_t index;
+3 -8
View File
@@ -40,6 +40,7 @@
#include "../../jconf.h"
#include "../../crypto/cryptonight.h"
#include "../../Environment.hpp"
#include "../../Params.hpp"
#include "amd_gpu/gpu.h"
@@ -97,19 +98,13 @@ std::vector<IBackend*>* minethd::thread_starter(uint32_t threadOffset, miner_wor
{
std::vector<IBackend*>* pvThreads = new std::vector<IBackend*>();
if(!ConfigEditor::file_exist("amd.txt"))
if(!ConfigEditor::file_exist(Params::inst().configFileAMD))
{
autoAdjust adjust;
if(!adjust.printConfig())
return pvThreads;
}
/*
if(!ConfigEditor::file_exist("amd.txt"))
{
printer::inst()->print_msg(L0, "WARNING: missing config file 'amd.txt'");
return pvThreads;
}
*/
if(!jconf::inst()->parse_config())
{
win_exit();
+3 -2
View File
@@ -3,6 +3,7 @@
#include "../../console.h"
#include "../../jconf.h"
#include "../../ConfigEditor.hpp"
#include "../../Params.hpp"
#include <string>
#ifdef _WIN32
@@ -97,8 +98,8 @@ public:
}
configTpl.replace("CPUCONFIG",conf);
configTpl.write("cpu.txt");
printer::inst()->print_msg(L0, "CPU configuration stored in file '%s'", "cpu.txt");
configTpl.write(Params::inst().configFileCPU);
printer::inst()->print_msg(L0, "CPU configuration stored in file '%s'", Params::inst().configFileCPU.c_str());
return true;
}
+3 -2
View File
@@ -3,6 +3,7 @@
#include "../../console.h"
#include <hwloc.h>
#include <stdio.h>
#include "../../Params.hpp"
#ifdef _WIN32
#include <windows.h>
@@ -74,8 +75,8 @@ public:
}
configTpl.replace("CPUCONFIG",conf);
configTpl.write("cpu.txt");
printer::inst()->print_msg(L0, "CPU configuration stored in file '%s'", "cpu.txt");
configTpl.write(Params::inst().configFileCPU);
printer::inst()->print_msg(L0, "CPU configuration stored in file '%s'", Params::inst().configFileCPU.c_str());
/* Destroy topology object. */
hwloc_topology_destroy(topology);
+2 -1
View File
@@ -1,6 +1,7 @@
#pragma once
#include <stdlib.h>
#include <string>
#include "../../Params.hpp"
namespace xmrstak
{
@@ -16,7 +17,7 @@ public:
return oInst;
};
bool parse_config(const char* sFilename = "cpu.txt");
bool parse_config(const char* sFilename = Params::inst().configFileCPU.c_str());
struct thd_cfg {
bool bDoubleMode;
+3 -2
View File
@@ -31,6 +31,7 @@
#include "../IBackend.hpp"
#include "../GlobalStates.hpp"
#include "../../ConfigEditor.hpp"
#include "../../Params.hpp"
#include "../../jconf.h"
#include "../../executor.h"
@@ -247,14 +248,14 @@ std::vector<IBackend*> minethd::thread_starter(uint32_t threadOffset, miner_work
{
std::vector<IBackend*> pvThreads;
if(!ConfigEditor::file_exist("cpu.txt"))
if(!ConfigEditor::file_exist(Params::inst().configFileCPU))
{
autoAdjust adjust;
if(!adjust.printConfig())
return pvThreads;
}
if(!xmrstak::cpu::jconf::inst()->parse_config("cpu.txt"))
if(!jconf::inst()->parse_config())
{
win_exit();
}
+3 -2
View File
@@ -7,6 +7,7 @@
#include "jconf.h"
#include "../../console.h"
#include "../../ConfigEditor.hpp"
#include "../../Params.hpp"
#include <vector>
#include <cstdio>
@@ -101,8 +102,8 @@ private:
}
configTpl.replace("GPUCONFIG",conf);
configTpl.write("nvidia.txt");
printer::inst()->print_msg(L0, "NVIDIA: GPU configuration stored in file '%s'", "nvidia.txt");
configTpl.write(Params::inst().configFileNVIDIA);
printer::inst()->print_msg(L0, "NVIDIA: GPU configuration stored in file '%s'", Params::inst().configFileNVIDIA.c_str());
}
std::vector<nvid_ctx> nvidCtxVec;
+2 -1
View File
@@ -1,6 +1,7 @@
#pragma once
#include <stdlib.h>
#include <string>
#include "../../Params.hpp"
namespace xmrstak
{
@@ -16,7 +17,7 @@ public:
return oInst;
};
bool parse_config(const char* sFilename = "nvidia.txt");
bool parse_config(const char* sFilename = Params::inst().configFileNVIDIA.c_str());
struct thd_cfg {
uint32_t id;
+3 -2
View File
@@ -30,6 +30,7 @@
#include "../../console.h"
#include "../../crypto/cryptonight_aesni.h"
#include "../cpu/minethd.h"
#include "../../Params.hpp"
#include "../../executor.h"
#include "minethd.h"
@@ -121,14 +122,14 @@ std::vector<IBackend*>* minethd::thread_starter(uint32_t threadOffset, miner_wor
{
std::vector<IBackend*>* pvThreads = new std::vector<IBackend*>();
if(!ConfigEditor::file_exist("nvidia.txt"))
if(!ConfigEditor::file_exist(Params::inst().configFileNVIDIA))
{
autoAdjust adjust;
if(!adjust.printConfig())
return pvThreads;
}
if(!jconf::inst()->parse_config("nvidia.txt"))
if(!jconf::inst()->parse_config())
{
win_exit();
}
+97 -21
View File
@@ -28,6 +28,7 @@
#include "../jconf.h"
#include "../console.h"
#include "../donate-level.h"
#include "../Params.hpp"
#include "../version.h"
@@ -37,7 +38,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <string>
#include <time.h>
@@ -66,32 +67,114 @@ int main(int argc, char *argv[])
srand(time(0));
const char* sFilename = "config.txt";
bool benchmark_mode = false;
using namespace xmrstak;
if(argc >= 2)
std::string pathWithName(argv[0]);
auto pos = pathWithName.rfind("/");
if(pos == std::string::npos)
{
if(strcmp(argv[1], "-h") == 0)
// try windows "\"
pos = pathWithName.rfind("\\");
}
Params::inst().executablePrefix = std::string(pathWithName, 0, pos);
for(int i = 1; i < argc; ++i)
{
std::string opName(argv[i]);
if(opName.compare("-h") == 0 || opName.compare("--help") == 0)
{
printer::inst()->print_msg(L0, "Usage %s [CONFIG FILE]", argv[0]);
printer::inst()->print_msg(L0, "Usage: %s [--help|-h] [--benchmark] [-c CONFIGFILE] [CONFIG FILE]", argv[0]);
win_exit();
return 0;
}
if(argc >= 3 && strcasecmp(argv[1], "-c") == 0)
else if(opName.compare("--noCPU") == 0)
{
sFilename = argv[2];
Params::inst().useCPU = false;
return 0;
}
else if(argc >= 3 && strcasecmp(argv[1], "benchmark_mode") == 0)
else if(opName.compare("--noAMD") == 0)
{
sFilename = argv[2];
benchmark_mode = true;
Params::inst().useAMD = false;
return 0;
}
else if(opName.compare("--noAMD") == 0)
{
Params::inst().useNVIDIA = false;
return 0;
}
else if(opName.compare("--cpu") == 0)
{
++i;
if( i >=argc )
{
printer::inst()->print_msg(L0, "No argument for opName '--cpu' given");
win_exit();
return 1;
}
Params::inst().configFileCPU = argv[i];
}
else if(opName.compare("--amd") == 0)
{
++i;
if( i >=argc )
{
printer::inst()->print_msg(L0, "No argument for opName '--amd' given");
win_exit();
return 1;
}
Params::inst().configFileAMD = argv[i];
}
else if(opName.compare("--nvidia") == 0)
{
++i;
if( i >=argc )
{
printer::inst()->print_msg(L0, "No argument for opName '--nvidia' given");
win_exit();
return 1;
}
Params::inst().configFileNVIDIA = argv[i];
}
else if(opName.compare("-o") == 0 || opName.compare("--url") == 0)
{
++i;
if( i >=argc )
{
printer::inst()->print_msg(L0, "No argument for opName '-o/--url' given");
win_exit();
return 1;
}
Params::inst().poolURL = argv[i];
}
else if(opName.compare("-u") == 0 || opName.compare("--user") == 0)
{
++i;
if( i >=argc )
{
printer::inst()->print_msg(L0, "No argument for opName '-u/--user' given");
win_exit();
return 1;
}
Params::inst().poolUsername = argv[i];
}
else if(opName.compare("-p") == 0 || opName.compare("--pass") == 0)
{
++i;
if( i >=argc )
{
printer::inst()->print_msg(L0, "No argument for opName '-p/--pass' given");
win_exit();
return 1;
}
Params::inst().poolPasswd = argv[i];
}
else
sFilename = argv[1];
Params::inst().configFile = argv[i];
}
if(!jconf::inst()->parse_config(sFilename))
if(!jconf::inst()->parse_config(Params::inst().configFile.c_str()))
{
win_exit();
return 0;
@@ -103,13 +186,6 @@ int main(int argc, char *argv[])
return 0;
}
if(benchmark_mode)
{
do_benchmark();
win_exit();
return 0;
}
#ifndef CONF_NO_HTTPD
if(jconf::inst()->GetHttpdPort() != 0)
{
+2 -1
View File
@@ -2,6 +2,7 @@
#include <stdlib.h>
#include <string>
#include "Environment.hpp"
#include "Params.hpp"
class jconf
{
@@ -14,7 +15,7 @@ public:
return env.pJconfConfig;
};
bool parse_config(const char* sFilename);
bool parse_config(const char* sFilename = xmrstak::Params::inst().configFile.c_str());
struct thd_cfg {
bool bDoubleMode;