From 98a67ab60bd0d19a0d1c3b2e820be7fdd6aa22c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cezary=20Skrzy=C5=84ski?= Date: Thu, 19 Nov 2020 16:03:56 +0100 Subject: [PATCH] #156: footprinting: support vector of non-serializable elements --- src/checkpoint/container/vector_serialize.h | 16 ++++++++++++++++ tests/unit/test_footprinter.cc | 13 +++++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/checkpoint/container/vector_serialize.h b/src/checkpoint/container/vector_serialize.h index b449950a..8f973c43 100644 --- a/src/checkpoint/container/vector_serialize.h +++ b/src/checkpoint/container/vector_serialize.h @@ -102,6 +102,22 @@ void serialize(Serializer& s, std::vector& vec) { } } +template < + typename SerializerT, + typename T, + typename VectorAllocator, + typename = std::enable_if_t< + std::is_same< // is_footprintable + size_t, + decltype(checkpoint::getMemoryFootprint(std::declval())) + >::value + > +> +void serialize(SerializerT& s, std::vector& vec) { + s.countBytes(vec); + s.addBytes(vec.capacity() * sizeof(T)); +} + } /* end namespace checkpoint */ #endif /*INCLUDED_CHECKPOINT_CONTAINER_VECTOR_SERIALIZE_H*/ diff --git a/tests/unit/test_footprinter.cc b/tests/unit/test_footprinter.cc index 754ea8e6..33cd8d24 100644 --- a/tests/unit/test_footprinter.cc +++ b/tests/unit/test_footprinter.cc @@ -586,4 +586,17 @@ TEST_F(TestFootprinter, test_ompi) { } } +struct TestNoSerialize { + double d; + int i; +}; + +TEST_F(TestFootprinter, test_no_serialize) { + std::vector v(7); + + EXPECT_EQ( + checkpoint::getMemoryFootprint(v), + sizeof(v) + v.capacity() * sizeof(TestNoSerialize) + ); +} }}} // end namespace checkpoint::tests::unit