Created
October 24, 2014 15:55
-
-
Save trondeau/708ac72c97b7730e1278 to your computer and use it in GitHub Desktop.
reset gr buffer counters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/gnuradio-runtime/include/gnuradio/block_detail.h b/gnuradio-runtime/include/gnuradio/block_detail.h | |
index 41568c8..8f9b039 100644 | |
--- a/gnuradio-runtime/include/gnuradio/block_detail.h | |
+++ b/gnuradio-runtime/include/gnuradio/block_detail.h | |
@@ -94,13 +94,25 @@ namespace gr { | |
*/ | |
void produce_each(int how_many_items); | |
- // Return the number of items read on input stream which_input | |
+ /*! | |
+ * Return the number of items read on input stream \p which_input. | |
+ */ | |
uint64_t nitems_read(unsigned int which_input); | |
- // Return the number of items written on output stream which_output | |
+ /*! | |
+ * Return the number of items written on output stream | |
+ * \p which_output. | |
+ */ | |
uint64_t nitems_written(unsigned int which_output); | |
/*! | |
+ * Resets all read and write counters for all the block's | |
+ * buffers. Mostly meant to be called during a flowgraph | |
+ * reconfiguration. | |
+ */ | |
+ void reset_buffer_counters(); | |
+ | |
+ /*! | |
* \brief Adds a new tag to the given output stream. | |
* | |
* Calls gr::buffer::add_item_tag(), | |
diff --git a/gnuradio-runtime/include/gnuradio/buffer.h b/gnuradio-runtime/include/gnuradio/buffer.h | |
index c0c9f3d..5b24901 100644 | |
--- a/gnuradio-runtime/include/gnuradio/buffer.h | |
+++ b/gnuradio-runtime/include/gnuradio/buffer.h | |
@@ -93,8 +93,18 @@ namespace gr { | |
gr::thread::mutex *mutex() { return &d_mutex; } | |
+ /*! | |
+ * Returns a counter of the number of items written to this | |
+ * buffer since the start/restart of a flowgraph. | |
+ */ | |
uint64_t nitems_written() { return d_abs_write_offset; } | |
+ /*! | |
+ * Resets the buffer's write counter. Immediately after this call, | |
+ * nitems_written will return 0. | |
+ */ | |
+ void reset_nitems_written() { d_abs_write_offset = 0; } | |
+ | |
size_t get_sizeof_item() { return d_sizeof_item; } | |
/*! | |
@@ -281,8 +291,18 @@ namespace gr { | |
gr::thread::mutex *mutex() { return d_buffer->mutex(); } | |
+ /*! | |
+ * Returns a counter of the number of items read by this buffer | |
+ * reader since the start/restart of a flowgraph. | |
+ */ | |
uint64_t nitems_read() { return d_abs_read_offset; } | |
+ /*! | |
+ * Resets the buffer's read counter. Immediately after this call, | |
+ * nitems_read will return 0. | |
+ */ | |
+ void reset_nitems_read() { d_abs_read_offset = 0; } | |
+ | |
size_t get_sizeof_item() { return d_buffer->get_sizeof_item(); } | |
/*! | |
diff --git a/gnuradio-runtime/lib/block_detail.cc b/gnuradio-runtime/lib/block_detail.cc | |
index 77c457c..bfa14ca 100644 | |
--- a/gnuradio-runtime/lib/block_detail.cc | |
+++ b/gnuradio-runtime/lib/block_detail.cc | |
@@ -159,6 +159,17 @@ namespace gr { | |
} | |
void | |
+ block_detail::reset_buffer_counters() | |
+ { | |
+ for(unsigned int n = 0; n < d_ninputs; n++) { | |
+ d_input[n]->reset_nitems_read(); | |
+ } | |
+ for(unsigned int n = 0; n < d_noutputs; n++) { | |
+ d_output[n]->reset_nitems_written(); | |
+ } | |
+ } | |
+ | |
+ void | |
block_detail::add_item_tag(unsigned int which_output, const tag_t &tag) | |
{ | |
if(!pmt::is_symbol(tag.key)) { | |
diff --git a/gnuradio-runtime/lib/flat_flowgraph.cc b/gnuradio-runtime/lib/flat_flowgraph.cc | |
index 9e5964c..36fe0bb 100644 | |
--- a/gnuradio-runtime/lib/flat_flowgraph.cc | |
+++ b/gnuradio-runtime/lib/flat_flowgraph.cc | |
@@ -304,6 +304,9 @@ namespace gr { | |
// Now deal with the fact that the block details might have | |
// changed numbers of inputs and outputs vs. in the old | |
// flowgraph. | |
+ | |
+ // Makes sure all buffer counters are reset for each block. | |
+ block->detail()->reset_buffer_counters(); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment