Add memory_estimation function for estimating shm usage
This makes it so that we can actually test that all of our shared memory
channels can fit in the shared memory actually available on a machine.
Change-Id: I348c02bafb6de94413da94c2f591019db4aee463
Signed-off-by: James Kuszmaul <james.kuszmaul@bluerivertech.com>
diff --git a/aos/ipc_lib/memory_estimation.cc b/aos/ipc_lib/memory_estimation.cc
new file mode 100644
index 0000000..d193c75
--- /dev/null
+++ b/aos/ipc_lib/memory_estimation.cc
@@ -0,0 +1,16 @@
+#include "aos/ipc_lib/memory_estimation.h"
+
+#include "aos/ipc_lib/memory_mapped_queue.h"
+namespace aos::ipc_lib {
+size_t TotalSharedMemoryUsage(const aos::Configuration *config,
+ const aos::Node *node) {
+ size_t total_size = 0;
+ for (const aos::Channel *channel : *CHECK_NOTNULL(config->channels())) {
+ if (aos::configuration::ChannelIsReadableOnNode(channel, node)) {
+ total_size +=
+ LocklessQueueMemorySize(MakeQueueConfiguration(config, channel));
+ }
+ }
+ return total_size;
+}
+} // namespace aos::ipc_lib