Skip to content

Commit

Permalink
#156: Footprint all non-serializable types T using sizeof(T)
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilMiller committed Nov 24, 2020
1 parent f650ecc commit da084ef
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 176 deletions.
1 change: 0 additions & 1 deletion src/checkpoint/checkpoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
#include "checkpoint/container/function_serialize.h"
#include "checkpoint/container/list_serialize.h"
#include "checkpoint/container/map_serialize.h"
#include "checkpoint/container/ompi_serialize.h"
#include "checkpoint/container/queue_serialize.h"
#include "checkpoint/container/raw_ptr_serialize.h"
#include "checkpoint/container/shared_ptr_serialize.h"
Expand Down
32 changes: 0 additions & 32 deletions src/checkpoint/container/list_serialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,38 +106,6 @@ inline void serialize(Serializer& s, std::deque<T>& lst) {
serializeOrderedContainer(s, lst);
}


/**
* Note: 'typename std::list<T>::iterator' doesn't work here.
* This depends on the (standard library) implementation details and requires
* checking for '_LIBCPP_VERSION' for libc++ to work.
*/
#if defined(_LIBCPP_VERSION)
template <
typename SerializerT,
typename T,
typename VoidPtr,
typename = std::enable_if_t<
std::is_same<SerializerT, checkpoint::Footprinter>::value
>
>
inline void serialize(
SerializerT& s, const std::__list_iterator<T, VoidPtr>& iter
) {
#else
template <
typename SerializerT,
typename T,
typename = std::enable_if_t<
std::is_same<SerializerT, checkpoint::Footprinter>::value
>
>
inline void serialize(SerializerT& s, const std::_List_iterator<T>& iter) {
#endif
s.countBytes(iter);
}


} /* end namespace checkpoint */

#endif /*INCLUDED_CHECKPOINT_CONTAINER_LIST_SERIALIZE_H*/
116 changes: 0 additions & 116 deletions src/checkpoint/container/ompi_serialize.h

This file was deleted.

4 changes: 2 additions & 2 deletions src/checkpoint/dispatch/dispatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ buffer::ImplReturnType packBuffer(
T& target, SerialSizeType size, BufferObtainFnType fn
);

//template <typename Serializer, typename T>
//inline void serializeArray(Serializer& s, T* array, SerialSizeType const len);
template <typename Serializer, typename T>
inline void serializeArray(Serializer& s, T* array, SerialSizeType const len);

template <typename T>
buffer::ImplReturnType serializeType(T& target, BufferObtainFnType fn = nullptr);
Expand Down
22 changes: 2 additions & 20 deletions src/checkpoint/dispatch/dispatch.impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,31 +120,13 @@ T* Standard::construct(SerialByteType* mem) {
return Traverse::reconstruct<T>(mem);
}

template <
typename Serializer,
typename T
>
inline std::enable_if_t< SerializableTraits<T, Serializer>::is_traversable, void > serializeArray(Serializer& s, T* array, SerialSizeType const len) {
template <typename Serializer, typename T>
inline void serializeArray(Serializer& s, T* array, SerialSizeType const len) {
if (len > 0) {
Traverse::with<T, Serializer>(*array, s, len);
}
}

template <
typename Serializer,
typename T
>
inline
std::enable_if_t<
not SerializableTraits<T, Serializer>::is_traversable
and
std::is_same<Serializer, checkpoint::Footprinter>::value,
void
>
serializeArray(Serializer& s, T* array, SerialSizeType const len) {
s.addBytes(sizeof(T) * len);
}

template <typename T>
buffer::ImplReturnType packBuffer(
T& target, SerialSizeType size, BufferObtainFnType fn
Expand Down
20 changes: 20 additions & 0 deletions src/checkpoint/dispatch/dispatch_serializer_nonbyte.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,15 @@ struct SerializerDispatchNonByte {
template <typename U>
using isEnum =
typename std::enable_if<std::is_enum<U>::value, T>::type;

template <typename U>
using justFootprint =
typename std::enable_if<
std::is_same<S, checkpoint::Footprinter>::value and
not SerializableTraits<U, S>::is_traversable and
not std::is_enum<U>::value,
T
>::type;
#else
template <typename U>
using hasInSerialize =
Expand Down Expand Up @@ -161,6 +170,17 @@ struct SerializerDispatchNonByte {
serializeEnum(s, *val);
}

template <typename U = T>
void applyStatic(
SerializerT& s, T* val, SerialSizeType num, justFootprint<U>* = nullptr
) {
debug_checkpoint(
"SerializerDispatch: justFootprint: val=%p\n",
static_cast<void*>(&val)
);
s.contiguousBytes(val, sizeof(T), num);
}

template <typename U = T>
void applyStatic(
SerializerT& s, T* val, SerialSizeType num, hasInSerialize<U>* = nullptr
Expand Down
22 changes: 17 additions & 5 deletions tests/unit/test_footprinter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -599,11 +599,23 @@ struct TestNoSerialize {
};

TEST_F(TestFootprinter, test_no_serialize) {
std::vector<TestNoSerialize> v(7);
{
std::vector<TestNoSerialize> v(7);

EXPECT_EQ(
checkpoint::getMemoryFootprint(v),
sizeof(v) + v.capacity() * sizeof(TestNoSerialize)
);
}

{
std::vector<std::list<int>::iterator> v(7);

EXPECT_EQ(
checkpoint::getMemoryFootprint(v),
sizeof(v) + v.capacity() * sizeof(std::list<int>::iterator)
);
}

EXPECT_EQ(
checkpoint::getMemoryFootprint(v),
sizeof(v) + v.capacity() * sizeof(TestNoSerialize)
);
}
}}} // end namespace checkpoint::tests::unit

0 comments on commit da084ef

Please sign in to comment.