| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // ====================================================================== | ||
| 2 | // \title Os/Linux/Memory.cpp | ||
| 3 | // \brief Linux implementation for Os::Memory | ||
| 4 | // ====================================================================== | ||
| 5 | #include <sys/sysinfo.h> | ||
| 6 | #include <Fw/Types/Assert.hpp> | ||
| 7 | #include <Os/Linux/Memory.hpp> | ||
| 8 | #include <cstdio> | ||
| 9 | #include <limits> | ||
| 10 | namespace Os { | ||
| 11 | namespace Linux { | ||
| 12 | namespace Memory { | ||
| 13 | |||
| 14 | 235 | MemoryInterface::Status LinuxMemory::_getUsage(Os::Memory::Usage& memory_usage) { | |
| 15 | struct sysinfo info; | ||
| 16 | // Only error in sysinfo call is invalid address | ||
| 17 | 235 | const int sysinfoStatus = sysinfo(&info); | |
| 18 | 235 | FW_ASSERT(sysinfoStatus == 0); | |
| 19 | 235 | FW_ASSERT(info.mem_unit > 0); | |
| 20 | 235 | const FwSizeType MAX_MEASURABLE_RAM_UNITS = std::numeric_limits<FwSizeType>::max() / info.mem_unit; | |
| 21 |
2/4✓ Branch 0 taken 235 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 235 times.
|
235 | if ((MAX_MEASURABLE_RAM_UNITS < info.totalram) || (MAX_MEASURABLE_RAM_UNITS < info.freeram)) { |
| 22 | ✗ | memory_usage.total = 1; | |
| 23 | ✗ | memory_usage.used = 1; | |
| 24 | ✗ | return Status::ERROR; | |
| 25 | } | ||
| 26 | |||
| 27 | 235 | memory_usage.total = info.totalram * info.mem_unit; | |
| 28 | 235 | memory_usage.used = (info.totalram - info.freeram) * info.mem_unit; | |
| 29 | 235 | return Status::OP_OK; | |
| 30 | } | ||
| 31 | |||
| 32 | ✗ | MemoryHandle* LinuxMemory::getHandle() { | |
| 33 | ✗ | return &this->m_handle; | |
| 34 | } | ||
| 35 | |||
| 36 | } // namespace Memory | ||
| 37 | } // namespace Linux | ||
| 38 | } // namespace Os | ||
| 39 |