Skip to content
Snippets Groups Projects
Commit 698f0c90 authored by Ewan Barr's avatar Ewan Barr
Browse files

moved around logging into sensible places

parent 689ad665
No related branches found
No related tags found
No related merge requests found
...@@ -10,10 +10,8 @@ namespace psrdada_cpp { ...@@ -10,10 +10,8 @@ namespace psrdada_cpp {
class DadaClientBase class DadaClientBase
{ {
private:
key_t _key;
protected: protected:
key_t _key;
dada_hdu_t* _hdu; dada_hdu_t* _hdu;
bool _connected; bool _connected;
MultiLog& _log; MultiLog& _log;
......
...@@ -26,17 +26,9 @@ namespace psrdada_cpp ...@@ -26,17 +26,9 @@ namespace psrdada_cpp
{ {
BOOST_LOG_TRIVIAL(info) << "Attaching new read client to buffer"; BOOST_LOG_TRIVIAL(info) << "Attaching new read client to buffer";
DadaReadClient client(_key,_log); DadaReadClient client(_key,_log);
BOOST_LOG_TRIVIAL(debug) << "Header buffer is " << client.header_buffer_count()
<< " x " << client.header_buffer_size() << " bytes";
BOOST_LOG_TRIVIAL(debug) << "Data buffer is " << client.data_buffer_count()
<< " x " << client.data_buffer_size() << " bytes";
auto& header_stream = client.header_stream(); auto& header_stream = client.header_stream();
auto& block = header_stream.next(); static_cast<ApplicationType*>(this)->on_connect(header_stream.next());
BOOST_LOG_TRIVIAL(debug) << "Acquired header block ("
<< block.used_bytes() <<"/"<<block.total_bytes() << " bytes)";
static_cast<ApplicationType*>(this)->on_connect(block);
header_stream.release(); header_stream.release();
BOOST_LOG_TRIVIAL(debug) << "Released header block";
auto& data_stream = client.data_stream(); auto& data_stream = client.data_stream();
while (!_stop) while (!_stop)
{ {
...@@ -45,12 +37,8 @@ namespace psrdada_cpp ...@@ -45,12 +37,8 @@ namespace psrdada_cpp
BOOST_LOG_TRIVIAL(info) << "Reached end of data"; BOOST_LOG_TRIVIAL(info) << "Reached end of data";
break; break;
} }
auto& data_block = data_stream.next(); static_cast<ApplicationType*>(this)->on_next(data_stream.next());
BOOST_LOG_TRIVIAL(debug) << "Acquired data block ("
<< block.used_bytes() <<"/"<<block.total_bytes() << " bytes)";
static_cast<ApplicationType*>(this)->on_next(data_block);
data_stream.release(); data_stream.release();
BOOST_LOG_TRIVIAL(debug) << "Released data block";
} }
} }
_running = false; _running = false;
......
...@@ -26,29 +26,17 @@ namespace psrdada_cpp ...@@ -26,29 +26,17 @@ namespace psrdada_cpp
{ {
BOOST_LOG_TRIVIAL(info) << "Attaching new write client to buffer"; BOOST_LOG_TRIVIAL(info) << "Attaching new write client to buffer";
DadaWriteClient client(_key,_log); DadaWriteClient client(_key,_log);
BOOST_LOG_TRIVIAL(debug) << "Header buffer is " << client.header_buffer_count()
<< " x " << client.header_buffer_size() << " bytes";
BOOST_LOG_TRIVIAL(debug) << "Data buffer is " << client.data_buffer_count()
<< " x " << client.data_buffer_size() << " bytes";
auto& header_stream = client.header_stream(); auto& header_stream = client.header_stream();
auto& block = header_stream.next(); static_cast<ApplicationType*>(this)->on_connect(header_stream.next());
BOOST_LOG_TRIVIAL(debug) << "Acquired header block ("
<< block.used_bytes() <<"/"<<block.total_bytes() << " bytes)";
static_cast<ApplicationType*>(this)->on_connect(block);
header_stream.release(); header_stream.release();
BOOST_LOG_TRIVIAL(debug) << "Released header block";
auto& data_stream = client.data_stream(); auto& data_stream = client.data_stream();
while (!_stop) while (!_stop)
{ {
auto& data_block = data_stream.next(); bool eod = static_cast<ApplicationType*>(this)->on_next(data_stream.next());
BOOST_LOG_TRIVIAL(debug) << "Acquired data block ("
<< block.used_bytes() <<"/"<<block.total_bytes() << " bytes)";
bool eod = static_cast<ApplicationType*>(this)->on_next(data_block);
data_stream.release(eod); data_stream.release(eod);
BOOST_LOG_TRIVIAL(debug) << "Released data block";
if (eod) if (eod)
{ {
BOOST_LOG_TRIVIAL(info) << "EOD set on last buffer"; BOOST_LOG_TRIVIAL(info) << "Final buffer written";
_stop = true; _stop = true;
break; break;
} }
......
...@@ -52,7 +52,6 @@ int main(int argc, char** argv) ...@@ -52,7 +52,6 @@ int main(int argc, char** argv)
set_log_level(level); set_log_level(level);
}), }),
"The logging level to use (debug, info, warning, error)"); "The logging level to use (debug, info, warning, error)");
po::variables_map vm; po::variables_map vm;
try try
{ {
...@@ -71,7 +70,6 @@ int main(int argc, char** argv) ...@@ -71,7 +70,6 @@ int main(int argc, char** argv)
std::cerr << desc << std::endl; std::cerr << desc << std::endl;
return ERROR_IN_COMMAND_LINE; return ERROR_IN_COMMAND_LINE;
} }
MultiLog log("dbnull"); MultiLog log("dbnull");
DbNull proc(key, log, nbytes); DbNull proc(key, log, nbytes);
proc.run(); proc.run();
......
...@@ -13,7 +13,6 @@ namespace psrdada_cpp { ...@@ -13,7 +13,6 @@ namespace psrdada_cpp {
void set_log_level(std::string level) void set_log_level(std::string level)
{ {
using namespace boost::log; using namespace boost::log;
if (level == "debug") if (level == "debug")
{ {
std::cout << "debug" << std::endl; std::cout << "debug" << std::endl;
......
...@@ -39,17 +39,25 @@ namespace psrdada_cpp { ...@@ -39,17 +39,25 @@ namespace psrdada_cpp {
void DadaClientBase::connect() void DadaClientBase::connect()
{ {
BOOST_LOG_TRIVIAL(debug) << "Connecting to dada buffer ["
<< std::hex << _key << std::dec << "]";
_hdu = dada_hdu_create(_log.native_handle()); _hdu = dada_hdu_create(_log.native_handle());
dada_hdu_set_key(_hdu, _key); dada_hdu_set_key(_hdu, _key);
if (dada_hdu_connect (_hdu) < 0){ if (dada_hdu_connect (_hdu) < 0){
_log.write(LOG_ERR, "could not connect to hdu\n"); _log.write(LOG_ERR, "could not connect to hdu\n");
throw std::runtime_error("Unable to connect to hdu\n"); throw std::runtime_error("Unable to connect to hdu\n");
} }
BOOST_LOG_TRIVIAL(debug) << "Header buffer is " << header_buffer_count()
<< " x " << header_buffer_size() << " bytes";
BOOST_LOG_TRIVIAL(debug) << "Data buffer is " << data_buffer_count()
<< " x " << data_buffer_size() << " bytes";
_connected = true; _connected = true;
} }
void DadaClientBase::disconnect() void DadaClientBase::disconnect()
{ {
BOOST_LOG_TRIVIAL(debug) << "Disconnecting from dada buffer ["
<< std::hex << _key << std::dec << "]";
if (dada_hdu_disconnect (_hdu) < 0){ if (dada_hdu_disconnect (_hdu) < 0){
_log.write(LOG_ERR, "could not disconnect from hdu\n"); _log.write(LOG_ERR, "could not disconnect from hdu\n");
throw std::runtime_error("Unable to disconnect from hdu\n"); throw std::runtime_error("Unable to disconnect from hdu\n");
......
...@@ -17,6 +17,7 @@ namespace psrdada_cpp ...@@ -17,6 +17,7 @@ namespace psrdada_cpp
void DadaIoLoop::stop() void DadaIoLoop::stop()
{ {
BOOST_LOG_TRIVIAL(debug) << "Stop requested on IO loop";
_stop = true; _stop = true;
} }
......
...@@ -19,7 +19,11 @@ namespace psrdada_cpp { ...@@ -19,7 +19,11 @@ namespace psrdada_cpp {
void DadaReadClient::lock() void DadaReadClient::lock()
{ {
if (!_connected) if (!_connected)
{
throw std::runtime_error("Lock requested on unconnected HDU\n"); throw std::runtime_error("Lock requested on unconnected HDU\n");
}
BOOST_LOG_TRIVIAL(debug) << "Acquiring reading lock on dada buffer ["
<< std::hex << _key << std::dec << "]";
if (dada_hdu_lock_read (_hdu) < 0) if (dada_hdu_lock_read (_hdu) < 0)
{ {
_log.write(LOG_ERR, "open_hdu: could not lock read\n"); _log.write(LOG_ERR, "open_hdu: could not lock read\n");
...@@ -30,8 +34,12 @@ namespace psrdada_cpp { ...@@ -30,8 +34,12 @@ namespace psrdada_cpp {
void DadaReadClient::release() void DadaReadClient::release()
{ {
if (!_locked) if (!_locked)
{
throw std::runtime_error("Release requested on unlocked HDU\n"); throw std::runtime_error("Release requested on unlocked HDU\n");
}
BOOST_LOG_TRIVIAL(debug) << "Releasing reading lock on dada buffer ["
<< std::hex << _key << std::dec << "]";
if (dada_hdu_unlock_read (_hdu) < 0) if (dada_hdu_unlock_read (_hdu) < 0)
{ {
_log.write(LOG_ERR, "open_hdu: could not release read\n"); _log.write(LOG_ERR, "open_hdu: could not release read\n");
...@@ -66,6 +74,7 @@ namespace psrdada_cpp { ...@@ -66,6 +74,7 @@ namespace psrdada_cpp {
{ {
throw std::runtime_error("Previous header block not released"); throw std::runtime_error("Previous header block not released");
} }
BOOST_LOG_TRIVIAL(debug) << "Acquiring next header block";
std::size_t nbytes = 0; std::size_t nbytes = 0;
char* tmp = ipcbuf_get_next_read(_parent._hdu->header_block, &nbytes); char* tmp = ipcbuf_get_next_read(_parent._hdu->header_block, &nbytes);
if (!tmp) if (!tmp)
...@@ -74,6 +83,8 @@ namespace psrdada_cpp { ...@@ -74,6 +83,8 @@ namespace psrdada_cpp {
throw std::runtime_error("Could not get header"); throw std::runtime_error("Could not get header");
} }
_current_block.reset(new RawBytes(tmp, _parent.header_buffer_size(), nbytes)); _current_block.reset(new RawBytes(tmp, _parent.header_buffer_size(), nbytes));
BOOST_LOG_TRIVIAL(debug) << "Header block used/total bytes = "
<< _current_block->used_bytes() <<"/"<<_current_block->total_bytes();
return *_current_block; return *_current_block;
} }
...@@ -83,7 +94,7 @@ namespace psrdada_cpp { ...@@ -83,7 +94,7 @@ namespace psrdada_cpp {
{ {
throw std::runtime_error("No header block to be released"); throw std::runtime_error("No header block to be released");
} }
BOOST_LOG_TRIVIAL(debug) << "Releasing header block";
if (ipcbuf_mark_cleared(_parent._hdu->header_block) < 0) if (ipcbuf_mark_cleared(_parent._hdu->header_block) < 0)
{ {
_parent._log.write(LOG_ERR, "Could not mark cleared header block\n"); _parent._log.write(LOG_ERR, "Could not mark cleared header block\n");
...@@ -114,6 +125,7 @@ namespace psrdada_cpp { ...@@ -114,6 +125,7 @@ namespace psrdada_cpp {
{ {
throw std::runtime_error("Previous data block not released"); throw std::runtime_error("Previous data block not released");
} }
BOOST_LOG_TRIVIAL(debug) << "Acquiring next data block";
std::size_t nbytes = 0; std::size_t nbytes = 0;
char* tmp = ipcio_open_block_read(_parent._hdu->data_block, &nbytes, &_block_idx); char* tmp = ipcio_open_block_read(_parent._hdu->data_block, &nbytes, &_block_idx);
if (!tmp) if (!tmp)
...@@ -122,6 +134,9 @@ namespace psrdada_cpp { ...@@ -122,6 +134,9 @@ namespace psrdada_cpp {
throw std::runtime_error("Could not open block to read"); throw std::runtime_error("Could not open block to read");
} }
_current_block.reset(new RawBytes(tmp, _parent.data_buffer_size(), nbytes)); _current_block.reset(new RawBytes(tmp, _parent.data_buffer_size(), nbytes));
BOOST_LOG_TRIVIAL(debug) << "Data block used/total bytes = "
<< _current_block->used_bytes() <<"/"<<_current_block->total_bytes();
return *_current_block;
} }
void DadaReadClient::DataStream::release() void DadaReadClient::DataStream::release()
...@@ -130,6 +145,7 @@ namespace psrdada_cpp { ...@@ -130,6 +145,7 @@ namespace psrdada_cpp {
{ {
throw std::runtime_error("No data block to be released"); throw std::runtime_error("No data block to be released");
} }
BOOST_LOG_TRIVIAL(debug) << "Releasing data block";
if (ipcio_close_block_read (_parent._hdu->data_block, _current_block->used_bytes()) < 0) if (ipcio_close_block_read (_parent._hdu->data_block, _current_block->used_bytes()) < 0)
{ {
_parent._log.write(LOG_ERR, "close_buffer: ipcio_close_block_read failed\n"); _parent._log.write(LOG_ERR, "close_buffer: ipcio_close_block_read failed\n");
......
...@@ -19,7 +19,11 @@ namespace psrdada_cpp { ...@@ -19,7 +19,11 @@ namespace psrdada_cpp {
void DadaWriteClient::lock() void DadaWriteClient::lock()
{ {
if (!_connected) if (!_connected)
{
throw std::runtime_error("Lock requested on unconnected HDU\n"); throw std::runtime_error("Lock requested on unconnected HDU\n");
}
BOOST_LOG_TRIVIAL(debug) << "Acquiring writing lock on dada buffer ["
<< std::hex << _key << std::dec << "]";
if (dada_hdu_lock_write (_hdu) < 0) if (dada_hdu_lock_write (_hdu) < 0)
{ {
_log.write(LOG_ERR, "open_hdu: could not lock write\n"); _log.write(LOG_ERR, "open_hdu: could not lock write\n");
...@@ -30,8 +34,12 @@ namespace psrdada_cpp { ...@@ -30,8 +34,12 @@ namespace psrdada_cpp {
void DadaWriteClient::release() void DadaWriteClient::release()
{ {
if (!_locked) if (!_locked)
{
throw std::runtime_error("Release requested on unlocked HDU\n"); throw std::runtime_error("Release requested on unlocked HDU\n");
}
BOOST_LOG_TRIVIAL(debug) << "Releasing writing lock on dada buffer ["
<< std::hex << _key << std::dec << "]";
if (dada_hdu_unlock_write (_hdu) < 0) if (dada_hdu_unlock_write (_hdu) < 0)
{ {
_log.write(LOG_ERR, "open_hdu: could not release write\n"); _log.write(LOG_ERR, "open_hdu: could not release write\n");
...@@ -66,6 +74,7 @@ namespace psrdada_cpp { ...@@ -66,6 +74,7 @@ namespace psrdada_cpp {
{ {
throw std::runtime_error("Previous header block not released"); throw std::runtime_error("Previous header block not released");
} }
BOOST_LOG_TRIVIAL(debug) << "Acquiring next header block";
char* tmp = ipcbuf_get_next_write(_parent._hdu->header_block); char* tmp = ipcbuf_get_next_write(_parent._hdu->header_block);
_current_block.reset(new RawBytes(tmp, _parent.header_buffer_size())); _current_block.reset(new RawBytes(tmp, _parent.header_buffer_size()));
return *_current_block; return *_current_block;
...@@ -77,7 +86,7 @@ namespace psrdada_cpp { ...@@ -77,7 +86,7 @@ namespace psrdada_cpp {
{ {
throw std::runtime_error("No header block to be released"); throw std::runtime_error("No header block to be released");
} }
BOOST_LOG_TRIVIAL(debug) << "Releasing header block";
if (ipcbuf_mark_filled(_parent._hdu->header_block, _current_block->used_bytes()) < 0) if (ipcbuf_mark_filled(_parent._hdu->header_block, _current_block->used_bytes()) < 0)
{ {
_parent._log.write(LOG_ERR, "Could not mark filled header block\n"); _parent._log.write(LOG_ERR, "Could not mark filled header block\n");
...@@ -103,8 +112,10 @@ namespace psrdada_cpp { ...@@ -103,8 +112,10 @@ namespace psrdada_cpp {
{ {
throw std::runtime_error("Previous data block not released"); throw std::runtime_error("Previous data block not released");
} }
BOOST_LOG_TRIVIAL(debug) << "Acquiring next header block";
char* tmp = ipcio_open_block_write(_parent._hdu->data_block, &_block_idx); char* tmp = ipcio_open_block_write(_parent._hdu->data_block, &_block_idx);
_current_block.reset(new RawBytes(tmp, _parent.data_buffer_size())); _current_block.reset(new RawBytes(tmp, _parent.data_buffer_size()));
BOOST_LOG_TRIVIAL(debug) << "Acquired data block " << _block_idx;
return *_current_block; return *_current_block;
} }
...@@ -114,8 +125,10 @@ namespace psrdada_cpp { ...@@ -114,8 +125,10 @@ namespace psrdada_cpp {
{ {
throw std::runtime_error("No data block to be released"); throw std::runtime_error("No data block to be released");
} }
BOOST_LOG_TRIVIAL(debug) << "Releasing data block";
if (eod) if (eod)
{ {
BOOST_LOG_TRIVIAL(debug) << "Setting EOD markers";
if (ipcio_update_block_write (_parent._hdu->data_block, _current_block->used_bytes()) < 0) if (ipcio_update_block_write (_parent._hdu->data_block, _current_block->used_bytes()) < 0)
{ {
_parent._log.write(LOG_ERR, "close_buffer: ipcio_update_block_write failed\n"); _parent._log.write(LOG_ERR, "close_buffer: ipcio_update_block_write failed\n");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment