Skip to content

Commit

Permalink
Moved configuration file options initialization to the constructor of…
Browse files Browse the repository at this point in the history
… the Application class.
  • Loading branch information
xvitaly committed Oct 6, 2024
1 parent 4d020e3 commit 8288b3b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 15 deletions.
32 changes: 18 additions & 14 deletions src/app/application/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,20 +210,6 @@ int Application::ExecuteEnv() const

int Application::ExecuteConfig(const std::string& ConfigFile) const
{
std::unique_ptr<boost::program_options::variables_map> Config = std::make_unique<boost::program_options::variables_map>();
std::unique_ptr<boost::program_options::options_description> ConfigOptions = std::make_unique<boost::program_options::options_description>("Configuration file options.");
ConfigOptions -> add_options()
("zswap.enabled", boost::program_options::value<std::string>(), "Enable or disable the ZSwap kernel module.")
("zswap.same_filled_pages_enabled", boost::program_options::value<std::string>(), "Enable or disable memory pages deduplication.")
("zswap.max_pool_percent", boost::program_options::value<std::string>(), "The maximum percentage of memory that the compressed pool can occupy.")
("zswap.compressor", boost::program_options::value<std::string>(), "The algorithm used to compress memory pages.")
("zswap.zpool", boost::program_options::value<std::string>(), "The kernel's zpool type.")
("zswap.accept_threshold_percent", boost::program_options::value<std::string>(), "The threshold at which ZSwap would start accepting pages again after it became full.")
("zswap.non_same_filled_pages_enabled", boost::program_options::value<std::string>(), "Enable or disable accepting non same filled memory pages.")
("zswap.exclusive_loads", boost::program_options::value<std::string>(), "Enable or disable entries invalidation when memory pages are loaded from compressed pool.")
("zswap.shrinker_enabled", boost::program_options::value<std::string>(), "Enable or disable pool shrinking based on memory pressure.")
;

if (!std::filesystem::exists(ConfigFile)) throw std::invalid_argument("Configuration file does not exist!");
std::ifstream ConfigFileFs(ConfigFile);
boost::program_options::store(boost::program_options::parse_config_file(ConfigFileFs, *ConfigOptions), *Config);
Expand Down Expand Up @@ -313,7 +299,9 @@ void Application::CheckIfRunningBySuperUser() const
void Application::InitClassMembers()
{
CmdLineOptions = std::make_unique<boost::program_options::options_description>("Command-line tool to control the ZSwap kernel module");
ConfigOptions = std::make_unique<boost::program_options::options_description>("Configuration file options");
CmdLine = std::make_unique<boost::program_options::variables_map>();
Config = std::make_unique<boost::program_options::variables_map>();
ZSwap = std::make_unique<ZSwapObject>();
ZSwapDebugger = std::make_unique<ZSwapDebug>();
}
Expand Down Expand Up @@ -349,6 +337,21 @@ void Application::InitCmdLineOptions()
CmdLineOptions -> add(OptionsGeneral).add(OptionsConfiguration).add(OptionsZSwap);
}

void Application::InitConfigOptions()
{
ConfigOptions -> add_options()
("zswap.enabled", boost::program_options::value<std::string>(), "Enable or disable the ZSwap kernel module.")
("zswap.same_filled_pages_enabled", boost::program_options::value<std::string>(), "Enable or disable memory pages deduplication.")
("zswap.max_pool_percent", boost::program_options::value<std::string>(), "The maximum percentage of memory that the compressed pool can occupy.")
("zswap.compressor", boost::program_options::value<std::string>(), "The algorithm used to compress memory pages.")
("zswap.zpool", boost::program_options::value<std::string>(), "The kernel's zpool type.")
("zswap.accept_threshold_percent", boost::program_options::value<std::string>(), "The threshold at which ZSwap would start accepting pages again after it became full.")
("zswap.non_same_filled_pages_enabled", boost::program_options::value<std::string>(), "Enable or disable accepting non same filled memory pages.")
("zswap.exclusive_loads", boost::program_options::value<std::string>(), "Enable or disable entries invalidation when memory pages are loaded from compressed pool.")
("zswap.shrinker_enabled", boost::program_options::value<std::string>(), "Enable or disable pool shrinking based on memory pressure.")
;
}

void Application::ParseCmdLine(int argc, char** argv)
{
boost::program_options::store(boost::program_options::parse_command_line(argc, argv, *CmdLineOptions), *CmdLine);
Expand All @@ -360,5 +363,6 @@ Application::Application(int argc, char** argv)
CheckIfRunningBySuperUser();
InitClassMembers();
InitCmdLineOptions();
InitConfigOptions();
ParseCmdLine(argc, argv);
}
19 changes: 18 additions & 1 deletion src/app/application/application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,39 @@ class Application
*/
std::unique_ptr<boost::program_options::options_description> CmdLineOptions;

/**
* Stores the list of available configuration file options with
* their descriptions.
*/
std::unique_ptr<boost::program_options::options_description> ConfigOptions;

/**
* Stores the parsed map of the specified command-line arguments.
*/
std::unique_ptr<boost::program_options::variables_map> CmdLine;

/**
* Stores the parsed map of the specified configuration file.
*/
std::unique_ptr<boost::program_options::variables_map> Config;

/**
* Initializes private class members.
*/
void InitClassMembers();

/**
* Initializes the list of available command-line options
* with full descriptions.
* with their descriptions.
*/
void InitCmdLineOptions();

/**
* Initializes the list of available configuration file options
* with their descriptions.
*/
void InitConfigOptions();

/**
* Parses command-line arguments to the map.
* @param argc Command-line arguments count.
Expand Down

0 comments on commit 8288b3b

Please sign in to comment.