serialization: Add trace logs for BinarySerializer::load when compiled using debug build type

These may be removed in the final release, however, for the time being
they are fairly useful. The compiler will optimize the full "line" out
when compiled using the release build type, so no performance is lost.
This commit is contained in:
pythonology 2019-07-05 00:07:17 -04:00
parent 6518148b50
commit a9386abfeb
2 changed files with 34 additions and 1 deletions

8
include/ki/util/trace.h Normal file
View File

@ -0,0 +1,8 @@
#pragma once
#include <iostream>
#if defined(NDEBUG)
#define TRACE if (0) std::cout
#else
#define TRACE if (1) std::cout << "[TRACE] "
#endif

View File

@ -2,6 +2,7 @@
#include <zlib.h> #include <zlib.h>
#include <cassert> #include <cassert>
#include "ki/util/unique.h" #include "ki/util/unique.h"
#include "ki/util/trace.h"
namespace ki namespace ki
{ {
@ -298,6 +299,9 @@ namespace serialization
std::unique_ptr<pclass::PropertyClass> &dest, BitStream &stream) const std::unique_ptr<pclass::PropertyClass> &dest, BitStream &stream) const
{ {
const auto type_hash = stream.read<pclass::hash_t>(); const auto type_hash = stream.read<pclass::hash_t>();
TRACE << "BinarySerializer::preload_object: type_hash = "
<< type_hash << std::endl;
if (type_hash != 0) if (type_hash != 0)
{ {
// Instantiate the type // Instantiate the type
@ -318,6 +322,10 @@ namespace serialization
// Did we get an object or null? // Did we get an object or null?
if (!dest) if (!dest)
return; return;
TRACE << "BinarySerializer::load_object: dest->get_type().get_name() = "
<< dest->get_type().get_name() << std::endl;
auto &properties = dest->get_properties(); auto &properties = dest->get_properties();
if (m_is_file) if (m_is_file)
@ -326,6 +334,8 @@ namespace serialization
// ensure that data is only read from inside this region. // ensure that data is only read from inside this region.
const auto object_size = const auto object_size =
stream.read<uint32_t>() - bitsizeof<uint32_t>::value; stream.read<uint32_t>() - bitsizeof<uint32_t>::value;
TRACE << "BinarySerializer::load_object: object_size = "
<< object_size << std::endl;
auto object_buffer = stream.buffer().segment( auto object_buffer = stream.buffer().segment(
stream.tell(), object_size stream.tell(), object_size
); );
@ -343,6 +353,8 @@ namespace serialization
// ensure that data is only read from inside this region. // ensure that data is only read from inside this region.
const auto property_size = const auto property_size =
object_stream.read<uint32_t>() - bitsizeof<uint32_t>::value; object_stream.read<uint32_t>() - bitsizeof<uint32_t>::value;
TRACE << "BinarySerializer::load_object: property_size = "
<< property_size << std::endl;
const auto property_buffer = object_buffer->segment( const auto property_buffer = object_buffer->segment(
object_stream.tell(), property_size object_stream.tell(), property_size
); );
@ -351,6 +363,8 @@ namespace serialization
// Get the property to load based on it's hash, and then load // Get the property to load based on it's hash, and then load
// it's value. // it's value.
const auto property_hash = property_stream.read<uint32_t>(); const auto property_hash = property_stream.read<uint32_t>();
TRACE << "BinarySerializer::load_object: property_hash = "
<< property_hash << std::endl;
auto &prop = properties.get_property(property_hash); auto &prop = properties.get_property(property_hash);
load_property(prop, property_stream); load_property(prop, property_stream);
@ -383,6 +397,9 @@ namespace serialization
!FLAG_IS_SET(prop.get_flags(), pclass::IProperty::flags::PUBLIC)) !FLAG_IS_SET(prop.get_flags(), pclass::IProperty::flags::PUBLIC))
return; return;
TRACE << "BinarySerializer::load_property: prop.get_name() = "
<< prop.get_name() << std::endl;
// Re-align the stream if we're going to read a prefix for this property // Re-align the stream if we're going to read a prefix for this property
if (prop.is_dynamic()) if (prop.is_dynamic())
stream.realign(); stream.realign();
@ -403,10 +420,14 @@ namespace serialization
element_count = stream.read<uint32_t>(); element_count = stream.read<uint32_t>();
} }
prop.set_element_count(element_count); prop.set_element_count(element_count);
TRACE << "BinarySerializer::load_property: element_count = "
<< element_count << std::endl;
} }
for (auto i = 0; i < prop.get_element_count(); ++i) for (auto i = 0; i < prop.get_element_count(); ++i)
{ {
TRACE << "BinarySerializer::load_property: i = " << i << std::endl;
// Realign the stream if necessary // Realign the stream if necessary
if (prop.get_type().is_byte_aligned()) if (prop.get_type().is_byte_aligned())
stream.realign(); stream.realign();
@ -420,7 +441,11 @@ namespace serialization
prop.set_object(object, i); prop.set_object(object, i);
} }
else else
{
prop.read_value_from(stream, m_is_file, i); prop.read_value_from(stream, m_is_file, i);
TRACE << "BinarySerializer::load_property: prop.get_value(" << i << ") = "
<< prop.get_value(i).as<std::string>().get<std::string>() << std::endl;
}
} }
} }
} }