Add timestamp to logs

This commit is contained in:
2018-07-11 09:13:54 +02:00
parent dc2ab56386
commit 7891261832
4 changed files with 60 additions and 0 deletions
+28
View File
@@ -20,6 +20,8 @@ hsize_t H5FormatUtils::expand_dataset(H5::DataSet& dataset, hsize_t frame_index,
dataset_dimension[0] = frame_index + dataset_increase_step;
#ifdef DEBUG_OUTPUT
using namespace date;
cout << "[" << std::chrono::system_clock::now() << "]";
cout << "[H5FormatUtils::expand_dataset] Expanding dataspace to size (";
for (int i=0; i<dataset_rank; ++i) {
cout << dataset_dimension[i] << ",";
@@ -43,6 +45,8 @@ void H5FormatUtils::compact_dataset(H5::DataSet& dataset, hsize_t max_frame_inde
dataset_dimension[0] = max_frame_index + 1;
#ifdef DEBUG_OUTPUT
using namespace date;
cout << "[" << std::chrono::system_clock::now() << "]";
cout << "[H5FormatUtils::compact_dataset] Compacting dataspace to size (";
for (int i=0; i<dataset_rank; ++i) {
cout << dataset_dimension[i] << ",";
@@ -65,6 +69,8 @@ const boost::any& H5FormatUtils::get_value_from_reference(const string& dataset_
auto reference_string = boost::any_cast<string>(value_reference);
#ifdef DEBUG_OUTPUT
using namespace date;
cout << "[" << std::chrono::system_clock::now() << "]";
cout << "[H5FormatUtils::get_value_from_reference] Getting dataset '"<< dataset_name;
cout << "' reference value '" << reference_string << "'." << endl;
#endif
@@ -73,12 +79,16 @@ const boost::any& H5FormatUtils::get_value_from_reference(const string& dataset_
} catch (const boost::bad_any_cast& exception) {
stringstream error_message;
using namespace date;
error_message << "[" << chrono::system_clock::now() << "]";
error_message << "Cannot convert dataset " << dataset_name << " value reference to string." << endl;
throw runtime_error(error_message.str());
} catch (const out_of_range& exception){
stringstream error_message;
using namespace date;
error_message << "[" << std::chrono::system_clock::now() << "]";
error_message << "Dataset " << dataset_name << " value reference " << boost::any_cast<string>(value_reference);
error_message << " not present in values map." << endl;
@@ -89,6 +99,8 @@ const boost::any& H5FormatUtils::get_value_from_reference(const string& dataset_
const H5::PredType& H5FormatUtils::get_dataset_data_type(const string& type)
{
#ifdef DEBUG_OUTPUT
using namespace date;
cout << "[" << std::chrono::system_clock::now() << "]";
cout << "[H5FormatUtils::get_dataset_data_type] Getting dataset type for received frame type " << type << endl;
#endif
@@ -119,6 +131,8 @@ const H5::PredType& H5FormatUtils::get_dataset_data_type(const string& type)
} else {
// We cannot really convert this attribute.
stringstream error_message;
using namespace date;
error_message << "[" << std::chrono::system_clock::now() << "]";
error_message << "[H5FormatUtils::get_dataset_data_type] Unsupported dataset data_type " << type << endl;
throw runtime_error(error_message.str());
@@ -152,6 +166,8 @@ H5::DataSet H5FormatUtils::write_dataset(H5::Group& target, const h5_dataset& da
// We cannot really convert this attribute.
stringstream error_message;
using namespace date;
error_message << "[" << std::chrono::system_clock::now() << "]";
error_message << "Cannot convert dataset " << name << " to string or const char*." << endl;
throw runtime_error(error_message.str());
@@ -163,6 +179,8 @@ H5::DataSet H5FormatUtils::write_dataset(H5::Group& target, const h5_dataset& da
// We cannot really convert this attribute.
stringstream error_message;
using namespace date;
error_message << "[" << std::chrono::system_clock::now() << "]";
error_message << "Cannot convert dataset " << name << " to NX_INT." << endl;
throw runtime_error(error_message.str());
@@ -173,11 +191,15 @@ H5::DataSet H5FormatUtils::write_dataset(H5::Group& target, const h5_dataset& da
// We cannot really convert this attribute.
stringstream error_message;
using namespace date;
error_message << "[" << std::chrono::system_clock::now() << "]";
error_message << "Cannot convert dataset " << name << " to NX_FLOAT." << endl;
throw runtime_error(error_message.str());
} else {
stringstream error_message;
using namespace date;
error_message << "[" << std::chrono::system_clock::now() << "]";
error_message << "Unsupported dataset type for dataset " << name << "." << endl;
throw runtime_error(error_message.str());
@@ -264,6 +286,8 @@ void H5FormatUtils::write_attribute(H5::H5Object& target, const h5_attr& attribu
// We cannot really convert this attribute.
stringstream error_message;
using namespace date;
error_message << "[" << std::chrono::system_clock::now() << "]";
error_message << "Cannot convert attribute " << name << " to string or const char*." << endl;
throw runtime_error(error_message.str());
@@ -276,6 +300,8 @@ void H5FormatUtils::write_attribute(H5::H5Object& target, const h5_attr& attribu
// We cannot really convert this attribute.
stringstream error_message;
using namespace date;
error_message << "[" << std::chrono::system_clock::now() << "]";
error_message << "Cannot convert attribute " << name << " to INT." << endl;
throw runtime_error(error_message.str());
@@ -309,6 +335,8 @@ void H5FormatUtils::write_format_data(H5::Group& file_node, const h5_parent& for
// You can specify only attributes inside a dataset.
if (dataset_attr.node_type != ATTRIBUTE) {
stringstream error_message;
using namespace date;
error_message << "[" << std::chrono::system_clock::now() << "]";
error_message << "Invalid element " << dataset_attr.name << " on dataset " << sub_dataset.name << ". Only attributes allowd.";
throw invalid_argument( error_message.str() );
+2
View File
@@ -8,6 +8,8 @@
#include <memory>
#include <tuple>
#include <boost/any.hpp>
#include <chrono>
#include "date.h"
typedef boost::any h5_value;
+28
View File
@@ -11,6 +11,8 @@ using namespace std;
RingBuffer::RingBuffer(size_t n_slots) : n_slots(n_slots), ringbuffer_slots(n_slots, 0)
{
#ifdef DEBUG_OUTPUT
using namespace date;
cout << "[" << std::chrono::system_clock::now() << "]";
cout << "[RingBuffer::RingBuffer] Creating ring buffer with n_slots " << n_slots << endl;
#endif
}
@@ -29,12 +31,16 @@ void RingBuffer::initialize(size_t slot_size)
// Check if the ring buffer is already initialized.
if (frame_data_buffer) {
stringstream error_message;
using namespace date;
error_message << "[" << std::chrono::system_clock::now() << "]";
error_message << "[RingBuffer::initialize] Ring buffer already initialized." << endl;
throw runtime_error(error_message.str());
}
#ifdef DEBUG_OUTPUT
using namespace date;
cout << "[" << std::chrono::system_clock::now() << "]";
cout << "[RingBuffer::initialize] Initializing ring buffer with slot_size " << slot_size << endl;
#endif
@@ -46,6 +52,8 @@ void RingBuffer::initialize(size_t slot_size)
this->ring_buffer_initialized = true;
#ifdef DEBUG_OUTPUT
using namespace date;
cout << "[" << std::chrono::system_clock::now() << "]";
cout << "[RingBuffer::initialize] Total buffer_size " << buffer_size << endl;
#endif
}
@@ -60,6 +68,8 @@ void RingBuffer::write(shared_ptr<FrameMetadata> frame_metadata, const char* dat
// All images must fit in the ring buffer.
if (frame_metadata->frame_bytes_size > slot_size) {
stringstream error_message;
using namespace date;
error_message << "[" << std::chrono::system_clock::now() << "]";
error_message << "[RingBuffer::write] Received frame index "<< frame_metadata->frame_index;
error_message << " that is too large for ring buffer slot. ";
error_message << "Slot size " << slot_size << ", but frame bytes size " << frame_metadata->frame_bytes_size << endl;
@@ -78,6 +88,8 @@ void RingBuffer::write(shared_ptr<FrameMetadata> frame_metadata, const char* dat
frame_metadata->buffer_slot_index = write_index;
#ifdef DEBUG_OUTPUT
using namespace date;
cout << "[" << std::chrono::system_clock::now() << "]";
cout << "[RingBuffer::write] Ring buffer slot " << frame_metadata->buffer_slot_index << " reserved for frame_index ";
cout << frame_metadata->frame_index << endl;
#endif
@@ -90,6 +102,8 @@ void RingBuffer::write(shared_ptr<FrameMetadata> frame_metadata, const char* dat
} else {
stringstream error_message;
using namespace date;
error_message << "[" << std::chrono::system_clock::now() << "]";
error_message << "[RingBuffer::write] Ring buffer is full. Collision at write_index = " << write_index << endl;
throw runtime_error(error_message.str());
@@ -101,6 +115,8 @@ void RingBuffer::write(shared_ptr<FrameMetadata> frame_metadata, const char* dat
memcpy(slot_memory_address, data, frame_metadata->frame_bytes_size);
#ifdef DEBUG_OUTPUT
using namespace date;
cout << "[" << std::chrono::system_clock::now() << "]";
cout << "[RingBuffer::write] Copied " << frame_metadata->frame_bytes_size << " frame bytes to buffer_slot_index ";
cout << frame_metadata->buffer_slot_index << endl;
#endif
@@ -113,6 +129,8 @@ void RingBuffer::write(shared_ptr<FrameMetadata> frame_metadata, const char* dat
}
#ifdef DEBUG_OUTPUT
using namespace date;
cout << "[" << std::chrono::system_clock::now() << "]";
cout << "[RingBuffer::write] Metadata for frame_index " << frame_metadata->frame_index << " added to metadata queue." << endl;
#endif
}
@@ -124,6 +142,8 @@ char* RingBuffer::get_buffer_slot_address(size_t buffer_slot_index)
// Check if the memory address is valid.
if (slot_memory_address > frame_data_buffer + buffer_size) {
stringstream error_message;
using namespace date;
error_message << "[" << std::chrono::system_clock::now() << "]";
error_message << "[RingBuffer::get_buffer_slot_address] Calculated ring buffer address is out of bound for buffer_slot_index ";
error_message << buffer_slot_index << endl;
@@ -151,6 +171,8 @@ pair<shared_ptr<FrameMetadata>, char*> RingBuffer::read()
}
#ifdef DEBUG_OUTPUT
using namespace date;
cout << "[" << std::chrono::system_clock::now() << "]";
cout << "[RingBuffer::read] Received metadata for frame_index " << frame_metadata->frame_index << endl;
#endif
@@ -160,6 +182,8 @@ pair<shared_ptr<FrameMetadata>, char*> RingBuffer::read()
if (!ringbuffer_slots[frame_metadata->buffer_slot_index]) {
stringstream error_message;
using namespace date;
error_message << "[" << std::chrono::system_clock::now() << "]";
error_message << "[RingBuffer::read] Ring buffer slot referenced in message header ";
error_message << frame_metadata->buffer_slot_index << " is empty." << endl;
@@ -177,6 +201,8 @@ void RingBuffer::release(size_t buffer_slot_index)
// Cannot release a slot index that is out of range.
if (buffer_slot_index >= n_slots) {
stringstream error_message;
using namespace date;
error_message << "[" << std::chrono::system_clock::now() << "]";
error_message << "[RingBuffer::release] Slot index to release " << buffer_slot_index;
error_message << " is out of range. Ring buffer n_slots = " << n_slots << endl;
@@ -194,6 +220,8 @@ void RingBuffer::release(size_t buffer_slot_index)
} else {
stringstream error_message;
using namespace date;
error_message << "[" << std::chrono::system_clock::now() << "]";
error_message << "[RingBuffer::release] Cannot release empty ring buffer slot " << buffer_slot_index << endl;
throw runtime_error(error_message.str());
+2
View File
@@ -8,6 +8,8 @@
#include <memory>
#include <string>
#include <boost/any.hpp>
#include <chrono>
#include "date.h"
struct FrameMetadata
{