Skip to content

Commit 6fd0af6

Browse files
committed
Implemented --stats command-line option.
Closes #19.
1 parent 939f07d commit 6fd0af6

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

src/app/application/application.cpp

+17
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,22 @@ bool Application::CheckIfRunningBySuperUser()
5050
return false;
5151
}
5252

53+
int Application::GetUsageStats()
54+
{
55+
ZSwapDebug ZSwapDebugger;
56+
std::cout << fmt::format("Duplicate entries count: {0}.", ZSwapDebugger.GetDuplicateEntry()) << std::endl;
57+
std::cout << fmt::format("Pool limit hit: {0}.", ZSwapDebugger.GetPoolLimitHit()) << std::endl;
58+
std::cout << fmt::format("Pool total size: {0}.", ZSwapDebugger.GetPoolTotalSize()) << std::endl;
59+
std::cout << fmt::format("Reject allocation failures: {0}.", ZSwapDebugger.GetRejectAllocFail()) << std::endl;
60+
std::cout << fmt::format("Reject compression poor: {0}.", ZSwapDebugger.GetRejectCompressPoor()) << std::endl;
61+
std::cout << fmt::format("Reject Kmemcache failures: {0}.", ZSwapDebugger.GetRejectKmemCacheFail()) << std::endl;
62+
std::cout << fmt::format("Reject reclaim failures: {0}.", ZSwapDebugger.GetRejectReclaimFail()) << std::endl;
63+
std::cout << fmt::format("Same filled pages count: {0}.", ZSwapDebugger.GetSameFilledPages()) << std::endl;
64+
std::cout << fmt::format("Stored pages count: {0}.", ZSwapDebugger.GetStoredPages()) << std::endl;
65+
std::cout << fmt::format("Written back pages count: {0}.", ZSwapDebugger.GetWrittenBackPages()) << std::endl;
66+
return 0;
67+
}
68+
5369
void Application::ExecuteEnv()
5470
{
5571
const std::string ZSwapEnabledEnv = CWrappers::GetEnv("ZSWAP_ENABLED_VALUE");
@@ -80,6 +96,7 @@ void Application::ExecuteCmdLine(const cxxopts::ParseResult& CmdLine)
8096
int Application::Run(const cxxopts::ParseResult& CmdLine)
8197
{
8298
if (CheckIfRunningBySuperUser()) return 1;
99+
if (CmdLine.count("stats")) return GetUsageStats();
83100
if (CmdLine.count("env")) ExecuteEnv(); else ExecuteCmdLine(CmdLine);
84101
return 0;
85102
}

src/app/application/application.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "cwrappers/cwrappers.hpp"
3131
#include "zswapworker/zswapworker.hpp"
3232
#include "zswapobject/zswapobject.hpp"
33+
#include "zswapdebug/zswapdebug.hpp"
3334

3435
class Application
3536
{
@@ -49,6 +50,7 @@ class Application
4950
bool CheckIfRunningBySuperUser();
5051
void ExecuteEnv();
5152
void ExecuteCmdLine(const cxxopts::ParseResult&);
53+
int GetUsageStats();
5254
};
5355

5456
#endif // APPLICATION_H

src/app/main.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ int main(int argc, char** argv)
2828
cxxopts::Options options("zswap-cli", "Command-line tool to control ZSwap Linux kernel module.");
2929
options.add_options()
3030
("env", "Get options from environment variables instead of cmdline.", cxxopts::value<bool>()->default_value("false"))
31+
("stats", "Get statistics of ZSwap usage and current settings.", cxxopts::value<bool>()->default_value("false"))
3132
("e,enabled", "Enable or disable ZSwap kernel module.", cxxopts::value<std::string>())
3233
("s,same_filled_pages_enabled", "Enable or disable memory pages deduplication.", cxxopts::value<std::string>())
3334
("p,max_pool_percent", "The maximum percentage of memory that the compressed pool can occupy.", cxxopts::value<std::string>())

0 commit comments

Comments
 (0)