F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
Memory.cpp
Go to the documentation of this file.
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 
15  struct sysinfo info;
16  // Only error in sysinfo call is invalid address
17  const int sysinfoStatus = sysinfo(&info);
18  FW_ASSERT(sysinfoStatus == 0);
19  FW_ASSERT(info.mem_unit > 0);
20  const FwSizeType MAX_MEASURABLE_RAM_UNITS = std::numeric_limits<FwSizeType>::max() / info.mem_unit;
21  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  memory_usage.total = info.totalram * info.mem_unit;
28  memory_usage.used = (info.totalram - info.freeram) * info.mem_unit;
29  return Status::OP_OK;
30 }
31 
33  return &this->m_handle;
34 }
35 
36 } // namespace Memory
37 } // namespace Linux
38 } // namespace Os
memory implementation
Definition: Memory.hpp:47
Operation succeeded.
Definition: Os.hpp:27
PlatformSizeType FwSizeType
Operation failed.
Definition: Os.hpp:28
Status _getUsage(Os::Memory::Usage &memory_usage) override
get system memory usage
Definition: Memory.cpp:14
Status
Generic OK/ERROR status.
Definition: Os.hpp:26
MemoryHandle * getHandle() override
returns the raw console handle
Definition: Memory.cpp:32
Memory variable handle parent.
Definition: Memory.hpp:13
FwSizeType total
Total amount.
Definition: Os.hpp:34
FwSizeType used
Used amount.
Definition: Os.hpp:33
Generic used/total struct.
Definition: Os.hpp:32
#define FW_ASSERT(...)
Definition: Assert.hpp:14