diff options
author | Igor Freire <igor@blockstream.com> | 2020-01-08 09:15:19 -0300 |
---|---|---|
committer | Martin Braun <martin@gnuradio.org> | 2020-02-18 22:23:56 -0800 |
commit | bebed18070bb3366c53f8d1b775c5ed5959859ea (patch) | |
tree | c54aded02148f5cdd77b430bd3c844221fc1b567 /gr-blocks/lib | |
parent | 64ee803068269fe3b9563fd415c420fb513a1c9b (diff) |
blocks: support saving of all tags on tag debug
For testing, it is often useful to check all tags ever received, rather than
solely the tags from the last call to the Tag Debug's work function. This patch
adds this option and a public method for activating it.
This is more appropriate for controlled test environments, where the vector of
tags is known not to grown indefinitely. Hence, the option is not exposed as a
block parameter.
Diffstat (limited to 'gr-blocks/lib')
-rw-r--r-- | gr-blocks/lib/tag_debug_impl.cc | 37 | ||||
-rw-r--r-- | gr-blocks/lib/tag_debug_impl.h | 6 |
2 files changed, 34 insertions, 9 deletions
diff --git a/gr-blocks/lib/tag_debug_impl.cc b/gr-blocks/lib/tag_debug_impl.cc index 3f2061274f..0c92e677b7 100644 --- a/gr-blocks/lib/tag_debug_impl.cc +++ b/gr-blocks/lib/tag_debug_impl.cc @@ -35,7 +35,8 @@ tag_debug_impl::tag_debug_impl(size_t sizeof_stream_item, io_signature::make(1, -1, sizeof_stream_item), io_signature::make(0, 0, 0)), d_name(name), - d_display(true) + d_display(true), + d_save_all(false) { set_key_filter(key_filter); } @@ -45,7 +46,12 @@ tag_debug_impl::~tag_debug_impl() {} std::vector<tag_t> tag_debug_impl::current_tags() { gr::thread::scoped_lock l(d_mutex); - return d_tags; + + if (d_save_all) { + return d_tags; + } else { + return d_work_tags; + } } int tag_debug_impl::num_tags() @@ -57,6 +63,17 @@ int tag_debug_impl::num_tags() void tag_debug_impl::set_display(bool d) { d_display = d; } +void tag_debug_impl::set_save_all(bool s) +{ + gr::thread::scoped_lock l(d_mutex); + + if (d_save_all && !s) { + d_tags.clear(); + } + + d_save_all = s; +} + void tag_debug_impl::set_key_filter(const std::string& key_filter) { if (key_filter.empty()) @@ -86,20 +103,19 @@ int tag_debug_impl::work(int noutput_items, abs_N = nitems_read(i); end_N = abs_N + (uint64_t)(noutput_items); - d_tags.clear(); + d_work_tags.clear(); if (pmt::is_null(d_filter)) - get_tags_in_range(d_tags, i, abs_N, end_N); + get_tags_in_range(d_work_tags, i, abs_N, end_N); else - get_tags_in_range(d_tags, i, abs_N, end_N, d_filter); + get_tags_in_range(d_work_tags, i, abs_N, end_N, d_filter); - if (!d_tags.empty()) { + if (!d_work_tags.empty()) toprint = true; - } if (d_display) { sout << "Input Stream: " << std::setw(2) << std::setfill('0') << i << std::setfill(' ') << std::endl; - for (const auto& tag : d_tags) { + for (const auto& tag : d_work_tags) { sout << std::setw(10) << "Offset: " << tag.offset << std::setw(10) << "Source: " << (pmt::is_symbol(tag.srcid) ? pmt::symbol_to_string(tag.srcid) @@ -109,6 +125,11 @@ int tag_debug_impl::work(int noutput_items, sout << tag.value << std::endl; } } + + if (d_save_all) { + for (const auto& tag : d_work_tags) + d_tags.push_back(tag); + } } if (d_display) { diff --git a/gr-blocks/lib/tag_debug_impl.h b/gr-blocks/lib/tag_debug_impl.h index 81b6f0dfe8..49f89a86f3 100644 --- a/gr-blocks/lib/tag_debug_impl.h +++ b/gr-blocks/lib/tag_debug_impl.h @@ -22,8 +22,10 @@ class tag_debug_impl : public tag_debug { private: const std::string d_name; - std::vector<tag_t> d_tags; + std::vector<tag_t> d_work_tags; /** tags from last work */ + std::vector<tag_t> d_tags; /** optionally holds all tags ever received */ bool d_display; + bool d_save_all; pmt::pmt_t d_filter; gr::thread::mutex d_mutex; @@ -40,6 +42,8 @@ public: void set_display(bool d); + void set_save_all(bool s); + void set_key_filter(const std::string& key_filter); std::string key_filter() const; |