diff options
author | Andrej Rode <mail@andrejro.de> | 2018-08-07 23:38:25 +0200 |
---|---|---|
committer | Marcus Müller <marcus@hostalia.de> | 2018-08-26 18:21:27 +0200 |
commit | 79d6f970996aafd160fea4bcb519a54d846f0aa1 (patch) | |
tree | f63bd696123dce4f6d05c182c386e86e9bbec1b7 | |
parent | 1c5711e867c96f5f61615d440857af7d27e15de4 (diff) |
runtime: replace compile-time debugging option by GR_LOG_DEBUG()
Add identifier() calls to flowgraph components to return a string with a human
readable string to reuse in both: the std::ostream overload and the logging system.
-rw-r--r-- | gnuradio-runtime/include/gnuradio/basic_block.h | 3 | ||||
-rw-r--r-- | gnuradio-runtime/include/gnuradio/block.h | 2 | ||||
-rw-r--r-- | gnuradio-runtime/include/gnuradio/flowgraph.h | 18 | ||||
-rw-r--r-- | gnuradio-runtime/lib/block.cc | 6 | ||||
-rw-r--r-- | gnuradio-runtime/lib/flat_flowgraph.cc | 233 |
5 files changed, 135 insertions, 127 deletions
diff --git a/gnuradio-runtime/include/gnuradio/basic_block.h b/gnuradio-runtime/include/gnuradio/basic_block.h index 7c343220b9..4d8b228d73 100644 --- a/gnuradio-runtime/include/gnuradio/basic_block.h +++ b/gnuradio-runtime/include/gnuradio/basic_block.h @@ -153,6 +153,7 @@ namespace gr { * and never changes during the life of the block. */ std::string symbol_name() const { return d_symbol_name; } + std::string identifier() const { return this->name() + "(" + std::to_string(this->unique_id()) + ")"; } gr::io_signature::sptr input_signature() const { return d_input_signature; } gr::io_signature::sptr output_signature() const { return d_output_signature; } @@ -392,7 +393,7 @@ namespace gr { inline std::ostream &operator << (std::ostream &os, basic_block_sptr basic_block) { - os << basic_block->name() << "(" << basic_block->unique_id() << ")"; + os << basic_block->identifier(); return os; } diff --git a/gnuradio-runtime/include/gnuradio/block.h b/gnuradio-runtime/include/gnuradio/block.h index 1cb7947179..82cd5b8512 100644 --- a/gnuradio-runtime/include/gnuradio/block.h +++ b/gnuradio-runtime/include/gnuradio/block.h @@ -897,6 +897,8 @@ namespace gr { */ void clear_finished(){ d_finished = false; } + std::string identifier() const; + }; typedef std::vector<block_sptr> block_vector_t; diff --git a/gnuradio-runtime/include/gnuradio/flowgraph.h b/gnuradio-runtime/include/gnuradio/flowgraph.h index 280c01fc28..c7e5cb9a5c 100644 --- a/gnuradio-runtime/include/gnuradio/flowgraph.h +++ b/gnuradio-runtime/include/gnuradio/flowgraph.h @@ -45,8 +45,11 @@ namespace gr { endpoint(basic_block_sptr block, int port) { d_basic_block = block; d_port = port; } basic_block_sptr block() const { return d_basic_block; } int port() const { return d_port; } + std::string identifier() const { + return d_basic_block->alias() + ":" + std::to_string(d_port); + }; - bool operator==(const endpoint &other) const; + bool operator==(const endpoint& other) const; }; inline bool endpoint::operator==(const endpoint &other) const @@ -71,6 +74,9 @@ namespace gr { pmt::pmt_t port() const { return d_port; } bool is_hier() const { return d_is_hier; } void set_hier(bool h) { d_is_hier = h; } + std::string identifier() const { + return d_basic_block->alias() + ":" + pmt::symbol_to_string(d_port); + } bool operator==(const msg_endpoint &other) const; }; @@ -99,6 +105,7 @@ namespace gr { const endpoint &src() const { return d_src; } const endpoint &dst() const { return d_dst; } + std::string identifier() const { return d_src.identifier() + "->" + d_dst.identifier(); } private: endpoint d_src; @@ -123,6 +130,7 @@ namespace gr { const msg_endpoint &src() const { return d_src; } const msg_endpoint &dst() const { return d_dst; } + std::string identifier() const { return d_src.identifier() + "->" + d_dst.identifier(); } private: msg_endpoint d_src; @@ -286,28 +294,28 @@ namespace gr { inline std::ostream& operator <<(std::ostream &os, const endpoint endp) { - os << endp.block()->alias() << ":" << endp.port(); + os << endp.identifier(); return os; } inline std::ostream& operator <<(std::ostream &os, const edge edge) { - os << edge.src() << "->" << edge.dst(); + os << edge.identifier(); return os; } inline std::ostream& operator <<(std::ostream &os, const msg_endpoint endp) { - os << endp.block()->alias() << ":" << pmt::symbol_to_string(endp.port()); + os << endp.identifier(); return os; } inline std::ostream& operator <<(std::ostream &os, const msg_edge edge) { - os << edge.src() << "->" << edge.dst(); + os << edge.identifier(); return os; } diff --git a/gnuradio-runtime/lib/block.cc b/gnuradio-runtime/lib/block.cc index 4c408ab7ed..e0cc0b6045 100644 --- a/gnuradio-runtime/lib/block.cc +++ b/gnuradio-runtime/lib/block.cc @@ -903,10 +903,14 @@ namespace gr { #endif /* defined(GR_CTRLPORT) && defined(GR_PERFORMANCE_COUNTERS) */ } + std::string block::identifier() const { + return d_name + "(" + std::to_string(d_unique_id) + ")"; + } + std::ostream& operator << (std::ostream& os, const block *m) { - os << "<block " << m->name() << " (" << m->unique_id() << ")>"; + os << "<block " << m->identifier() << ">"; return os; } diff --git a/gnuradio-runtime/lib/flat_flowgraph.cc b/gnuradio-runtime/lib/flat_flowgraph.cc index b7e949127a..c83ab20769 100644 --- a/gnuradio-runtime/lib/flat_flowgraph.cc +++ b/gnuradio-runtime/lib/flat_flowgraph.cc @@ -27,6 +27,7 @@ #include "flat_flowgraph.h" #include <gnuradio/block_detail.h> #include <gnuradio/buffer.h> +#include <gnuradio/logger.h> #include <gnuradio/prefs.h> #include <volk/volk.h> #include <iostream> @@ -35,8 +36,6 @@ namespace gr { -#define FLAT_FLOWGRAPH_DEBUG 0 - // 32Kbyte buffer size between blocks #define GR_FIXED_BUFFER_SIZE (32*(1L<<10)) @@ -77,11 +76,12 @@ namespace gr { // Connect message ports connetions for(msg_edge_viter_t i = d_msg_edges.begin(); i != d_msg_edges.end(); i++) { - if(FLAT_FLOWGRAPH_DEBUG) - std::cout << boost::format("flat_fg connecting msg primitives: (%s, %s)->(%s, %s)\n") % - i->src().block() % i->src().port() % - i->dst().block() % i->dst().port(); - i->src().block()->message_port_sub(i->src().port(), pmt::cons(i->dst().block()->alias_pmt(), i->dst().port())); + GR_LOG_DEBUG(d_debug_logger, + boost::format("flat_fg connecting msg primitives: (%s, %s)->(%s, %s)\n") % + i->src().block() % i->src().port() % + i->dst().block() % i->dst().port() + ); + i->src().block()->message_port_sub(i->src().port(), pmt::cons(i->dst().block()->alias_pmt(), i->dst().port())); } } @@ -98,15 +98,13 @@ namespace gr { (boost::format("allocate_block_detail found non-gr::block (%s)")% block->alias()).str()); - if(FLAT_FLOWGRAPH_DEBUG) - std::cout << "Creating block detail for " << block << std::endl; + GR_LOG_DEBUG(d_debug_logger, "Creating block detail for " + block->identifier()); for(int i = 0; i < noutputs; i++) { grblock->expand_minmax_buffer(i); buffer_sptr buffer = allocate_buffer(block, i); - if(FLAT_FLOWGRAPH_DEBUG) - std::cout << "Allocated buffer for output " << block << ":" << i << std::endl; + GR_LOG_DEBUG(d_debug_logger, "Allocated buffer for output " + block->identifier() + " " + std::to_string(i)); detail->set_output(i, buffer); // Update the block's max_output_buffer based on what was actually allocated. @@ -210,8 +208,8 @@ namespace gr { throw std::runtime_error("connect_block_inputs found non-gr::block"); buffer_sptr src_buffer = src_grblock->detail()->output(src_port); - if(FLAT_FLOWGRAPH_DEBUG) - std::cout << "Setting input " << dst_port << " from edge " << (*e) << std::endl; + + GR_LOG_DEBUG(d_debug_logger, "Setting input " + std::to_string(dst_port) + " from edge " + (*e).identifier()); detail->set_input(dst_port, buffer_add_reader(src_buffer, grblock->history()-1, grblock, grblock->sample_delay(src_port))); @@ -227,89 +225,81 @@ namespace gr { for(basic_block_viter_t p = d_blocks.begin(); p != d_blocks.end(); p++) { block_sptr block = cast_to_block_sptr(*p); - if(!block->detail()) { - if(FLAT_FLOWGRAPH_DEBUG) - std::cout << "merge: allocating new detail for block " << (*p) << std::endl; - block->set_detail(allocate_block_detail(block)); - } - else { - if(FLAT_FLOWGRAPH_DEBUG) - std::cout << "merge: reusing original detail for block " << (*p) << std::endl; + if (!block->detail()) { + GR_LOG_DEBUG(d_debug_logger, + "merge: allocating new detail for block " + block->identifier()); + block->set_detail(allocate_block_detail(block)); + } else { + GR_LOG_DEBUG(d_debug_logger, + "merge: reusing original detail for block " + block->identifier()); } } // Calculate the old edges that will be going away, and clear the // buffer readers on the RHS. - for(edge_viter_t old_edge = old_ffg->d_edges.begin(); old_edge != old_ffg->d_edges.end(); old_edge++) { - if(FLAT_FLOWGRAPH_DEBUG) - std::cout << "merge: testing old edge " << (*old_edge) << "..."; - - edge_viter_t new_edge; - for(new_edge = d_edges.begin(); new_edge != d_edges.end(); new_edge++) - if(new_edge->src() == old_edge->src() && - new_edge->dst() == old_edge->dst()) - break; - - if(new_edge == d_edges.end()) { // not found in new edge list - if(FLAT_FLOWGRAPH_DEBUG) - std::cout << "not in new edge list" << std::endl; - // zero the buffer reader on RHS of old edge - block_sptr block(cast_to_block_sptr(old_edge->dst().block())); - int port = old_edge->dst().port(); - block->detail()->set_input(port, buffer_reader_sptr()); - } - else { - if (FLAT_FLOWGRAPH_DEBUG) - std::cout << "found in new edge list" << std::endl; - } + for (edge_viter_t old_edge = old_ffg->d_edges.begin(); old_edge != old_ffg->d_edges.end(); + old_edge++) { + GR_LOG_DEBUG(d_debug_logger, + "merge: testing old edge " + old_edge->identifier() + "..."); + + edge_viter_t new_edge; + for (new_edge = d_edges.begin(); new_edge != d_edges.end(); new_edge++) + if (new_edge->src() == old_edge->src() && new_edge->dst() == old_edge->dst()) + break; + + if (new_edge == d_edges.end()) { // not found in new edge list + GR_LOG_DEBUG(d_debug_logger, "not in new edge list"); + // zero the buffer reader on RHS of old edge + block_sptr block(cast_to_block_sptr(old_edge->dst().block())); + int port = old_edge->dst().port(); + block->detail()->set_input(port, buffer_reader_sptr()); + } else { + GR_LOG_DEBUG(d_debug_logger, "found in new edge list"); + } } // Now connect inputs to outputs, reusing old buffer readers if they exist for(basic_block_viter_t p = d_blocks.begin(); p != d_blocks.end(); p++) { block_sptr block = cast_to_block_sptr(*p); - if(FLAT_FLOWGRAPH_DEBUG) - std::cout << "merge: merging " << (*p) << "..."; - - if(old_ffg->has_block_p(*p)) { - // Block exists in old flow graph - if(FLAT_FLOWGRAPH_DEBUG) - std::cout << "used in old flow graph" << std::endl; - block_detail_sptr detail = block->detail(); - - // Iterate through the inputs and see what needs to be done - int ninputs = calc_used_ports(block, true).size(); // Might be different now - for(int i = 0; i < ninputs; i++) { - if(FLAT_FLOWGRAPH_DEBUG) - std::cout << "Checking input " << block << ":" << i << "..."; - edge edge = calc_upstream_edge(*p, i); - - // Fish out old buffer reader and see if it matches correct buffer from edge list - block_sptr src_block = cast_to_block_sptr(edge.src().block()); - block_detail_sptr src_detail = src_block->detail(); - buffer_sptr src_buffer = src_detail->output(edge.src().port()); - buffer_reader_sptr old_reader; - if(i < detail->ninputs()) // Don't exceed what the original detail has - old_reader = detail->input(i); - - // If there's a match, use it - if(old_reader && (src_buffer == old_reader->buffer())) { - if(FLAT_FLOWGRAPH_DEBUG) - std::cout << "matched, reusing" << std::endl; - } - else { - if(FLAT_FLOWGRAPH_DEBUG) - std::cout << "needs a new reader" << std::endl; - - // Create new buffer reader and assign - detail->set_input(i, buffer_add_reader(src_buffer, block->history()-1, block)); + GR_LOG_DEBUG(d_debug_logger, + "merge: merging " + block->identifier() + "..."); + + if (old_ffg->has_block_p(*p)) { + // Block exists in old flow graph + GR_LOG_DEBUG(d_debug_logger, "used in old flow graph") + block_detail_sptr detail = block->detail(); + + // Iterate through the inputs and see what needs to be done + int ninputs = calc_used_ports(block, true).size(); // Might be different now + for (int i = 0; i < ninputs; i++) { + GR_LOG_DEBUG(d_debug_logger, + "Checking input " + block->identifier() + ":" + std::to_string(i) + + "..."); + edge edge = calc_upstream_edge(*p, i); + + // Fish out old buffer reader and see if it matches correct buffer from edge list + block_sptr src_block = cast_to_block_sptr(edge.src().block()); + block_detail_sptr src_detail = src_block->detail(); + buffer_sptr src_buffer = src_detail->output(edge.src().port()); + buffer_reader_sptr old_reader; + if (i < detail->ninputs()) // Don't exceed what the original detail has + old_reader = detail->input(i); + + // If there's a match, use it + if (old_reader && (src_buffer == old_reader->buffer())) { + GR_LOG_DEBUG(d_debug_logger, "matched, reusing"); + } else { + GR_LOG_DEBUG(d_debug_logger, "needs a new reader"); + + // Create new buffer reader and assign + detail->set_input(i, buffer_add_reader(src_buffer, block->history() - 1, block)); + } } - } } else { // Block is new, it just needs buffer readers at this point - if(FLAT_FLOWGRAPH_DEBUG) - std::cout << "new block" << std::endl; + GR_LOG_DEBUG(d_debug_logger, "new block"); connect_block_inputs(block); // Make sure all buffers are aligned @@ -317,12 +307,12 @@ namespace gr { } // Connect message ports connetions - for(msg_edge_viter_t i = d_msg_edges.begin(); i != d_msg_edges.end(); i++) { - if(FLAT_FLOWGRAPH_DEBUG) - std::cout << boost::format("flat_fg connecting msg primitives: (%s, %s)->(%s, %s)\n") % - i->src().block() % i->src().port() % - i->dst().block() % i->dst().port(); - i->src().block()->message_port_sub(i->src().port(), pmt::cons(i->dst().block()->alias_pmt(), i->dst().port())); + for (msg_edge_viter_t i = d_msg_edges.begin(); i != d_msg_edges.end(); i++) { + GR_LOG_DEBUG(d_debug_logger, + boost::format("flat_fg connecting msg primitives: (%s, %s)->(%s, %s)\n") % + i->src().block() % i->src().port() % i->dst().block() % i->dst().port()); + i->src().block()->message_port_sub( + i->src().port(), pmt::cons(i->dst().block()->alias_pmt(), i->dst().port())); } // Now deal with the fact that the block details might have @@ -439,45 +429,48 @@ namespace gr { void flat_flowgraph::clear_hier() { - if(FLAT_FLOWGRAPH_DEBUG) - std::cout << "Clear_hier()" << std::endl; - for(size_t i=0; i<d_msg_edges.size(); i++) { - if(FLAT_FLOWGRAPH_DEBUG) - std::cout << "edge: " << d_msg_edges[i].src() << "-->" << d_msg_edges[i].dst() << std::endl; - if(d_msg_edges[i].src().is_hier() || d_msg_edges[i].dst().is_hier()){ - if(FLAT_FLOWGRAPH_DEBUG) - std::cout << "is hier" << std::endl; - d_msg_edges.erase(d_msg_edges.begin() + i); - i--; - } + GR_LOG_DEBUG(d_debug_logger, "Clear_hier()"); + for (size_t i = 0; i < d_msg_edges.size(); i++) { + GR_LOG_DEBUG(d_debug_logger, + "edge: " + d_msg_edges[i].src().identifier() + "-->" + + d_msg_edges[i].dst().identifier()); + if (d_msg_edges[i].src().is_hier() || d_msg_edges[i].dst().is_hier()) { + GR_LOG_DEBUG(d_debug_logger, "is hier"); + d_msg_edges.erase(d_msg_edges.begin() + i); + i--; + } } } void flat_flowgraph::replace_endpoint(const msg_endpoint &e, const msg_endpoint &r, bool is_src) { - size_t n_replr(0); - if(FLAT_FLOWGRAPH_DEBUG) - std::cout << boost::format("flat_flowgraph::replace_endpoint( %s, %s, %d )\n") % e.block()% r.block()% is_src; - for(size_t i=0; i<d_msg_edges.size(); i++) { - if(is_src) { - if(d_msg_edges[i].src() == e) { - if(FLAT_FLOWGRAPH_DEBUG) - std::cout << boost::format("flat_flowgraph::replace_endpoint() flattening to ( %s, %s )\n") \ - % r% d_msg_edges[i].dst(); - d_msg_edges.push_back( msg_edge(r, d_msg_edges[i].dst() ) ); - n_replr++; - } - } - else { - if(d_msg_edges[i].dst() == e) { - if(FLAT_FLOWGRAPH_DEBUG) - std::cout << boost::format("flat_flowgraph::replace_endpoint() flattening to ( %s, %s )\n") \ - % r% d_msg_edges[i].src(); - d_msg_edges.push_back( msg_edge(d_msg_edges[i].src(), r ) ); - n_replr++; - } - } + size_t n_replr(0); + GR_LOG_DEBUG(d_debug_logger, + boost::format("flat_flowgraph::replace_endpoint( %s, %s, %d )\n") % e.block() % + r.block() % is_src); + for (size_t i = 0; i < d_msg_edges.size(); i++) { + if (is_src) { + if (d_msg_edges[i].src() == e) { + GR_LOG_DEBUG( + d_debug_logger, + boost::format( + "flat_flowgraph::replace_endpoint() flattening to ( %s, %s )\n") % + r % d_msg_edges[i].dst()) + d_msg_edges.push_back(msg_edge(r, d_msg_edges[i].dst())); + n_replr++; + } + } else { + if (d_msg_edges[i].dst() == e) { + GR_LOG_DEBUG( + d_debug_logger, + boost::format( + "flat_flowgraph::replace_endpoint() flattening to ( %s, %s )\n") % + r % d_msg_edges[i].src()); + d_msg_edges.push_back(msg_edge(d_msg_edges[i].src(), r)); + n_replr++; + } + } } } |