Skip to content

Commit

Permalink
Added PrintSummary() private method.
Browse files Browse the repository at this point in the history
Closes #27.
  • Loading branch information
xvitaly committed Apr 26, 2020
1 parent 94a1dac commit da2fb4d
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/app/application/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<float>(ZSwapDebugger.GetPoolTotalSize()) / Power;
const float MemTotalPercent = static_cast<float>(ZSwapDebugger.GetPoolTotalSize()) / static_cast<float>(SysInfo.GetTotalRam()) * 100.f;
const float StoredPagesMB = static_cast<float>(ZSwapDebugger.GetStoredPages() * CWrappers::GetSCPageSize()) / Power;
const float SwapUsedPercent = static_cast<float>(ZSwapDebugger.GetStoredPages() * CWrappers::GetSCPageSize()) / static_cast<float>(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;
Expand All @@ -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;
}
Expand Down
2 changes: 2 additions & 0 deletions src/app/application/application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "cwrappers/cwrappers.hpp"
#include "zswapobject/zswapobject.hpp"
#include "zswapdebug/zswapdebug.hpp"
#include "ksysinfo/ksysinfo.hpp"

class Application
{
Expand All @@ -43,6 +44,7 @@ class Application
void ExecuteCmdLine(const cxxopts::ParseResult&);
void PrintDebugInfo();
void PrintSettings();
void PrintSummary();
void PrintCombined();
int PrintStats(int);
};
Expand Down
5 changes: 5 additions & 0 deletions src/lib/cwrappers/cwrappers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,8 @@ bool CWrappers::CheckRoot()
{
return getuid();
}

long CWrappers::GetSCPageSize()
{
return sysconf(_SC_PAGESIZE);
}
1 change: 1 addition & 0 deletions src/lib/cwrappers/cwrappers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class CWrappers
public:
static std::string GetEnv(const std::string&);
static bool CheckRoot();
static long GetSCPageSize();
private:
CWrappers() = default;
};
Expand Down

0 comments on commit da2fb4d

Please sign in to comment.