diff --git a/src/app/application/application.cpp b/src/app/application/application.cpp index 38f4cec..e4ee72f 100644 --- a/src/app/application/application.cpp +++ b/src/app/application/application.cpp @@ -76,6 +76,35 @@ void Application::PrintSettings() << std::endl; } +void Application::PrintSummary() +{ + ZSwapDebug ZSwapDebugger; + KSysInfo SysInfo; + + if (ZSwapDebugger.GetPoolTotalSize() == 0) + { + std::cerr << "ZSwap is not working. The pool is empty." << std::endl; + return; + } + + constexpr const long Power = 1024 << 10; + const float PoolSizeMB = static_cast(ZSwapDebugger.GetPoolTotalSize()) / Power; + const float MemTotalPercent = static_cast(ZSwapDebugger.GetPoolTotalSize()) / static_cast(SysInfo.GetTotalRam()) * 100.f; + const float StoredPagesMB = static_cast(ZSwapDebugger.GetStoredPages() * CWrappers::GetSCPageSize()) / Power; + const float SwapUsedPercent = static_cast(ZSwapDebugger.GetStoredPages() * CWrappers::GetSCPageSize()) / static_cast(SysInfo.GetTotalSwap() - SysInfo.GetFreeSwap()) * 100.f; + const float CompressionRatio = StoredPagesMB / PoolSizeMB; + + std::cout << fmt::format("Pool: {0:.2f} MiB ({1:.1f}% of MemTotal)\n" + "Stored: {2:.2f} MiB ({3:.1f}% of SwapUsed)\n" + "Comression ratio: {4:.2f}", + PoolSizeMB, + MemTotalPercent, + StoredPagesMB, + SwapUsedPercent, + CompressionRatio) + << std::endl; +} + void Application::PrintCombined() { std::cout << "ZSWAP KERNEL MODULE SETTINGS:" << std::endl; @@ -98,6 +127,9 @@ int Application::PrintStats(const int Value) case 2: PrintDebugInfo(); break; + case 3: + PrintSummary(); + break; default: std::cout << "Incorrect value of --stats command-line option was specified." << std::endl; } diff --git a/src/app/application/application.hpp b/src/app/application/application.hpp index e721887..48ae71c 100644 --- a/src/app/application/application.hpp +++ b/src/app/application/application.hpp @@ -30,6 +30,7 @@ #include "cwrappers/cwrappers.hpp" #include "zswapobject/zswapobject.hpp" #include "zswapdebug/zswapdebug.hpp" +#include "ksysinfo/ksysinfo.hpp" class Application { @@ -43,6 +44,7 @@ class Application void ExecuteCmdLine(const cxxopts::ParseResult&); void PrintDebugInfo(); void PrintSettings(); + void PrintSummary(); void PrintCombined(); int PrintStats(int); }; diff --git a/src/lib/cwrappers/cwrappers.cpp b/src/lib/cwrappers/cwrappers.cpp index 2ecba0c..53530b8 100644 --- a/src/lib/cwrappers/cwrappers.cpp +++ b/src/lib/cwrappers/cwrappers.cpp @@ -32,3 +32,8 @@ bool CWrappers::CheckRoot() { return getuid(); } + +long CWrappers::GetSCPageSize() +{ + return sysconf(_SC_PAGESIZE); +} diff --git a/src/lib/cwrappers/cwrappers.hpp b/src/lib/cwrappers/cwrappers.hpp index 024adbe..351b35b 100644 --- a/src/lib/cwrappers/cwrappers.hpp +++ b/src/lib/cwrappers/cwrappers.hpp @@ -31,6 +31,7 @@ class CWrappers public: static std::string GetEnv(const std::string&); static bool CheckRoot(); + static long GetSCPageSize(); private: CWrappers() = default; };