Skip to content

Commit

Permalink
Added a new public method GetPageSize() to the KSysInfo class.
Browse files Browse the repository at this point in the history
  • Loading branch information
xvitaly committed Oct 2, 2024
1 parent 2529159 commit 488537c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/app/application/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ void Application::PrintSummary()
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 StoredPagesMB = static_cast<float>(ZSwapDebugger -> GetStoredPages() * SysInfo -> GetPageSize()) / Power;
const float SwapUsedPercent = static_cast<float>(ZSwapDebugger -> GetStoredPages() * SysInfo -> GetPageSize()) / static_cast<float>(SysInfo -> GetTotalSwap() - SysInfo -> GetFreeSwap()) * 100.f;
const float CompressionRatio = StoredPagesMB / PoolSizeMB;

std::cout << std::format("Pool: {0:.2f} MiB ({1:.1f}% of MemTotal).\n"
Expand Down
12 changes: 12 additions & 0 deletions src/lib/ksysinfo/ksysinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <sys/sysinfo.h>

#include "ksysinfo/ksysinfo.hpp"
#include "cwrappers/cwrappers.hpp"

long& KSysInfo::GetUptime()
{
Expand Down Expand Up @@ -66,6 +67,11 @@ unsigned int& KSysInfo::GetMemUnitSize()
return MemUnitSize;
}

long& KSysInfo::GetPageSize()
{
return PageSize;
}

void KSysInfo::ReadSysInfo()
{
struct sysinfo SysInfo;
Expand All @@ -83,7 +89,13 @@ void KSysInfo::ReadSysInfo()
MemUnitSize = static_cast<unsigned int>(SysInfo.mem_unit);
}

void KSysInfo::ReadPageSize()
{
PageSize = CWrappers::GetSCPageSize();
}

KSysInfo::KSysInfo()
{
ReadSysInfo();
ReadPageSize();
}
16 changes: 16 additions & 0 deletions src/lib/ksysinfo/ksysinfo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,24 @@ class KSysInfo
* @returns Memory unit size.
*/
unsigned int& GetMemUnitSize();

/**
* Gets system page size value.
* @returns System page size value.
*/
long& GetPageSize();
private:
/**
* Reads the sysinfo structure into the class fields.
* @exception Raises an instance of std::runtime_error on error.
*/
void ReadSysInfo();

/**
* Reads the SC_PAGESIZE system variable value.
*/
void ReadPageSize();

/**
* Stores current uptime (in seconds since boot) value.
*/
Expand Down Expand Up @@ -149,6 +160,11 @@ class KSysInfo
* Stores memory unit size in bytes value.
*/
unsigned int MemUnitSize;

/**
* Stores the system page size value.
*/
long PageSize;
};

#endif // KSYSINFO_HPP

0 comments on commit 488537c

Please sign in to comment.