F´ Flight Software - C/C++ Documentation  devel
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 <Os/Linux/Memory.hpp>
6 #include <Fw/Types/Assert.hpp>
7 #include <sys/sysinfo.h>
8 #include <limits>
9 #include <cstdio>
10 namespace Os {
11 namespace Linux {
12 namespace Memory {
13 
15  struct sysinfo info;
16  // Only error in sysinfo call is invalid address
17  FW_ASSERT(sysinfo(&info) == 0);
18  const FwSizeType MAX_MEASURABLE_RAM_UNITS = std::numeric_limits<FwSizeType>::max() / info.mem_unit;
19  if ((MAX_MEASURABLE_RAM_UNITS < info.totalram) || (MAX_MEASURABLE_RAM_UNITS < info.freeram)) {
20  memory_usage.total = 1;
21  memory_usage.used = 1;
22  return Status::ERROR;
23  }
24 
25  memory_usage.total = info.totalram * info.mem_unit;
26  memory_usage.used = info.freeram * info.mem_unit;
27  return Status::OP_OK;
28 }
29 
31  return &this->m_handle;
32 }
33 
34 } // namespace Memory
35 } // namespace Linux
36 } // namespace Os
#define FW_ASSERT(...)
Definition: Assert.hpp:14
PlatformSizeType FwSizeType
Definition: FpConfig.h:35
MemoryHandle * getHandle() override
returns the raw console handle
Definition: Memory.cpp:30
Status _getUsage(Os::Memory::Usage &memory_usage) override
get system memory usage
Definition: Memory.cpp:14
Memory variable handle parent.
Definition: Memory.hpp:13
memory implementation
Definition: Memory.hpp:47
Status
Generic OK/ERROR status.
Definition: Os.hpp:25
@ OP_OK
Operation succeeded.
Definition: Os.hpp:26
@ ERROR
Operation failed.
Definition: Os.hpp:27
Generic used/total struct.
Definition: Os.hpp:31
FwSizeType total
Total amount.
Definition: Os.hpp:33
FwSizeType used
Used amount.
Definition: Os.hpp:32