From e0dfa761f98d627ba5083e99f23d40528b2c4f14 Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Fri, 10 Feb 2017 22:49:22 -0500 Subject: [PATCH] Add utils.dummy component class, move plugins/trimmer to plugins/utils MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This patch adds a plugins/utils directory where the utils plugin sources are. plugins/trimmer is moved to this new directory because the trimmer component class is part of the utils plugin. Also in the utils plugin is the dummy sink component class. This sink does absolutely nothing with its notifications. It is the equivalent of the BT 1.x dummy format. At consume time, it gets one notification per input notification iterator and returns BT_NOTIFICATION_ITERATOR_STATUS_END when all the iterators are at the end. The legacy `-o dummy` option is not handled specifically in this commit. You can use the dummy sink as usual: babeltrace /path/to/trace -o utils.dummy The dummy component class ignores its initialization parameters. Signed-off-by: Philippe Proulx Signed-off-by: Jérémie Galarneau --- configure.ac | 4 +- converter/Makefile.am | 2 +- plugins/Makefile.am | 2 +- plugins/trimmer/Makefile.am | 19 ------ plugins/utils/Makefile.am | 15 +++++ plugins/utils/dummy/Makefile.am | 4 ++ plugins/utils/dummy/dummy.c | 83 ++++++++++++++++++++++++++ plugins/utils/dummy/dummy.h | 28 +++++++++ plugins/utils/plugin.c | 50 ++++++++++++++++ plugins/utils/trimmer/Makefile.am | 8 +++ plugins/{ => utils}/trimmer/iterator.c | 0 plugins/{ => utils}/trimmer/iterator.h | 0 plugins/{ => utils}/trimmer/trimmer.c | 19 ------ plugins/{ => utils}/trimmer/trimmer.h | 14 ++++- 14 files changed, 204 insertions(+), 44 deletions(-) delete mode 100644 plugins/trimmer/Makefile.am create mode 100644 plugins/utils/Makefile.am create mode 100644 plugins/utils/dummy/Makefile.am create mode 100644 plugins/utils/dummy/dummy.c create mode 100644 plugins/utils/dummy/dummy.h create mode 100644 plugins/utils/plugin.c create mode 100644 plugins/utils/trimmer/Makefile.am rename plugins/{ => utils}/trimmer/iterator.c (100%) rename plugins/{ => utils}/trimmer/iterator.h (100%) rename plugins/{ => utils}/trimmer/trimmer.c (90%) rename plugins/{ => utils}/trimmer/trimmer.h (79%) diff --git a/configure.ac b/configure.ac index de5553b9..d48be53b 100644 --- a/configure.ac +++ b/configure.ac @@ -492,8 +492,10 @@ AC_CONFIG_FILES([ plugins/ctf/lttng-live/Makefile plugins/muxer/Makefile plugins/text/Makefile - plugins/trimmer/Makefile plugins/writer/Makefile + plugins/utils/Makefile + plugins/utils/dummy/Makefile + plugins/utils/trimmer/Makefile babeltrace.pc babeltrace-ctf.pc ]) diff --git a/converter/Makefile.am b/converter/Makefile.am index 6cbe2ff9..5e88fb0b 100644 --- a/converter/Makefile.am +++ b/converter/Makefile.am @@ -1,6 +1,6 @@ PLUGINS_PATH = $(abs_top_builddir)/plugins AM_CFLAGS = $(PACKAGE_CFLAGS) -I$(top_srcdir)/include \ - -DCONFIG_IN_TREE_PLUGIN_PATH=\"$(PLUGINS_PATH)/ctf:$(PLUGINS_PATH)/text:$(PLUGINS_PATH)/muxer:$(PLUGINS_PATH)/trimmer:$(PLUGINS_PATH)/writer\" + -DCONFIG_IN_TREE_PLUGIN_PATH=\"$(PLUGINS_PATH)/ctf:$(PLUGINS_PATH)/text:$(PLUGINS_PATH)/muxer:$(PLUGINS_PATH)/writer:$(PLUGINS_PATH)/utils\" AM_LDFLAGS = -lpopt bin_PROGRAMS = babeltrace.bin babeltrace-log diff --git a/plugins/Makefile.am b/plugins/Makefile.am index 2d697dbb..158e7d7d 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -1,3 +1,3 @@ -SUBDIRS = ctf text muxer trimmer writer +SUBDIRS = ctf text muxer writer utils noinst_HEADERS = plugins-common.h diff --git a/plugins/trimmer/Makefile.am b/plugins/trimmer/Makefile.am deleted file mode 100644 index cf1fba4d..00000000 --- a/plugins/trimmer/Makefile.am +++ /dev/null @@ -1,19 +0,0 @@ -AM_CFLAGS = $(PACKAGE_CFLAGS) -I$(top_srcdir)/include -I$(top_srcdir)/plugins - -SUBDIRS = . - -plugindir = "$(PLUGINSDIR)" -plugin_LTLIBRARIES = libbabeltrace-plugin-trimmer.la - -libbabeltrace_plugin_trimmer_la_SOURCES = \ - trimmer.c \ - iterator.c \ - trimmer.h \ - iterator.h - -libbabeltrace_plugin_trimmer_la_LDFLAGS = \ - -version-info $(BABELTRACE_LIBRARY_VERSION) - -libbabeltrace_plugin_trimmer_la_LIBADD = \ - $(top_builddir)/lib/libbabeltrace.la \ - $(top_builddir)/formats/ctf/libbabeltrace-ctf.la diff --git a/plugins/utils/Makefile.am b/plugins/utils/Makefile.am new file mode 100644 index 00000000..99188070 --- /dev/null +++ b/plugins/utils/Makefile.am @@ -0,0 +1,15 @@ +AM_CFLAGS = $(PACKAGE_CFLAGS) -I$(top_srcdir)/include -I$(top_srcdir)/plugins + +SUBDIRS = dummy trimmer . + +plugindir = "$(PLUGINSDIR)" +plugin_LTLIBRARIES = libbabeltrace-plugin-utils.la + +libbabeltrace_plugin_utils_la_SOURCES = plugin.c +libbabeltrace_plugin_utils_la_LDFLAGS = \ + -version-info $(BABELTRACE_LIBRARY_VERSION) +libbabeltrace_plugin_utils_la_LIBADD = \ + $(top_builddir)/lib/libbabeltrace.la \ + $(top_builddir)/formats/ctf/libbabeltrace-ctf.la \ + dummy/libbabeltrace-plugin-dummy-cc.la \ + trimmer/libbabeltrace-plugin-dummy-cc.la diff --git a/plugins/utils/dummy/Makefile.am b/plugins/utils/dummy/Makefile.am new file mode 100644 index 00000000..8be2676d --- /dev/null +++ b/plugins/utils/dummy/Makefile.am @@ -0,0 +1,4 @@ +AM_CFLAGS = $(PACKAGE_CFLAGS) -I$(top_srcdir)/include -I$(top_srcdir)/plugins + +noinst_LTLIBRARIES = libbabeltrace-plugin-dummy-cc.la +libbabeltrace_plugin_dummy_cc_la_SOURCES = dummy.c dummy.h diff --git a/plugins/utils/dummy/dummy.c b/plugins/utils/dummy/dummy.c new file mode 100644 index 00000000..66b29968 --- /dev/null +++ b/plugins/utils/dummy/dummy.c @@ -0,0 +1,83 @@ +/* + * Copyright 2017 Philippe Proulx + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include +#include +#include +#include +#include + +enum bt_component_status dummy_consume(struct bt_component *component) +{ + enum bt_component_status ret; + struct bt_notification *notif = NULL; + struct bt_notification_iterator *it = NULL; + unsigned int it_count; + size_t i; + bool got_one = false; + + ret = bt_component_sink_get_input_count(component, &it_count); + assert(ret == 0); + + for (i = 0; i < it_count; i++) { + enum bt_notification_iterator_status it_ret; + + ret = bt_component_sink_get_input_iterator(component, i, &it); + assert(ret == 0); + it_ret = bt_notification_iterator_next(it); + switch (it_ret) { + case BT_NOTIFICATION_ITERATOR_STATUS_ERROR: + ret = BT_COMPONENT_STATUS_ERROR; + goto end; + case BT_NOTIFICATION_ITERATOR_STATUS_END: + ret = BT_COMPONENT_STATUS_END; + BT_PUT(it); + continue; + default: + break; + } + + notif = bt_notification_iterator_get_notification(it); + if (!notif) { + ret = BT_COMPONENT_STATUS_ERROR; + goto end; + } + + /* + * Dummy! I'm doing nothing with this notification, + * NOTHING. + */ + got_one = true; + BT_PUT(it); + BT_PUT(notif); + } + + if (!got_one) { + ret = BT_COMPONENT_STATUS_END; + } + +end: + bt_put(it); + bt_put(notif); + return ret; +} diff --git a/plugins/utils/dummy/dummy.h b/plugins/utils/dummy/dummy.h new file mode 100644 index 00000000..2fcf34be --- /dev/null +++ b/plugins/utils/dummy/dummy.h @@ -0,0 +1,28 @@ +#ifndef BABELTRACE_PLUGINS_UTILS_DUMMY_H +#define BABELTRACE_PLUGINS_UTILS_DUMMY_H + +/* + * Copyright 2017 Philippe Proulx + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +enum bt_component_status dummy_consume(struct bt_component *component); + +#endif /* BABELTRACE_PLUGINS_UTILS_DUMMY_H */ diff --git a/plugins/utils/plugin.c b/plugins/utils/plugin.c new file mode 100644 index 00000000..de25342c --- /dev/null +++ b/plugins/utils/plugin.c @@ -0,0 +1,50 @@ +/* + * Copyright 2017 Philippe Proulx + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include +#include "dummy/dummy.h" +#include "trimmer/trimmer.h" +#include "trimmer/iterator.h" + +BT_PLUGIN(utils); +BT_PLUGIN_DESCRIPTION("Utilities."); +BT_PLUGIN_AUTHOR("Philippe Proulx"); +BT_PLUGIN_LICENSE("MIT"); + +/* dummy sink */ +BT_PLUGIN_SINK_COMPONENT_CLASS(dummy, dummy_consume); +BT_PLUGIN_SINK_COMPONENT_CLASS_DESCRIPTION(dummy, + "Dummy sink component class: does absolutely nothing!"); + +/* trimmer filter */ +BT_PLUGIN_FILTER_COMPONENT_CLASS(trimmer, trimmer_iterator_get, + trimmer_iterator_next); +BT_PLUGIN_FILTER_COMPONENT_CLASS_DESCRIPTION(trimmer, + "Ensure that trace notifications outside of a given range are filtered-out."); +BT_PLUGIN_FILTER_COMPONENT_CLASS_INIT_METHOD(trimmer, trimmer_component_init); +BT_PLUGIN_FILTER_COMPONENT_CLASS_DESTROY_METHOD(trimmer, destroy_trimmer); +BT_PLUGIN_FILTER_COMPONENT_CLASS_NOTIFICATION_ITERATOR_INIT_METHOD(trimmer, + trimmer_iterator_init); +BT_PLUGIN_FILTER_COMPONENT_CLASS_NOTIFICATION_ITERATOR_DESTROY_METHOD(trimmer, + trimmer_iterator_destroy); +BT_PLUGIN_FILTER_COMPONENT_CLASS_NOTIFICATION_ITERATOR_SEEK_TIME_METHOD(trimmer, + trimmer_iterator_seek_time); diff --git a/plugins/utils/trimmer/Makefile.am b/plugins/utils/trimmer/Makefile.am new file mode 100644 index 00000000..8ef55db2 --- /dev/null +++ b/plugins/utils/trimmer/Makefile.am @@ -0,0 +1,8 @@ +AM_CFLAGS = $(PACKAGE_CFLAGS) -I$(top_srcdir)/include -I$(top_srcdir)/plugins + +noinst_LTLIBRARIES = libbabeltrace-plugin-dummy-cc.la +libbabeltrace_plugin_dummy_cc_la_SOURCES = \ + trimmer.c \ + iterator.c \ + trimmer.h \ + iterator.h diff --git a/plugins/trimmer/iterator.c b/plugins/utils/trimmer/iterator.c similarity index 100% rename from plugins/trimmer/iterator.c rename to plugins/utils/trimmer/iterator.c diff --git a/plugins/trimmer/iterator.h b/plugins/utils/trimmer/iterator.h similarity index 100% rename from plugins/trimmer/iterator.h rename to plugins/utils/trimmer/iterator.h diff --git a/plugins/trimmer/trimmer.c b/plugins/utils/trimmer/trimmer.c similarity index 90% rename from plugins/trimmer/trimmer.c rename to plugins/utils/trimmer/trimmer.c index 06814ef8..af838d72 100644 --- a/plugins/trimmer/trimmer.c +++ b/plugins/utils/trimmer/trimmer.c @@ -56,7 +56,6 @@ end: return trimmer; } -static void destroy_trimmer(struct bt_component *component) { void *data = bt_component_get_private_data(component); @@ -373,21 +372,3 @@ error: destroy_trimmer_data(trimmer); return ret; } - -/* Initialize plug-in entry points. */ -BT_PLUGIN(utils); -BT_PLUGIN_DESCRIPTION("Babeltrace Trace Trimmer Plug-In."); -BT_PLUGIN_AUTHOR("Jérémie Galarneau"); -BT_PLUGIN_LICENSE("MIT"); -BT_PLUGIN_FILTER_COMPONENT_CLASS(trimmer, trimmer_iterator_get, - trimmer_iterator_next); -BT_PLUGIN_FILTER_COMPONENT_CLASS_DESCRIPTION(trimmer, - "Ensure that trace notifications outside of a given range are filtered-out."); -BT_PLUGIN_FILTER_COMPONENT_CLASS_INIT_METHOD(trimmer, trimmer_component_init); -BT_PLUGIN_FILTER_COMPONENT_CLASS_DESTROY_METHOD(trimmer, destroy_trimmer); -BT_PLUGIN_FILTER_COMPONENT_CLASS_NOTIFICATION_ITERATOR_INIT_METHOD(trimmer, - trimmer_iterator_init); -BT_PLUGIN_FILTER_COMPONENT_CLASS_NOTIFICATION_ITERATOR_DESTROY_METHOD(trimmer, - trimmer_iterator_destroy); -BT_PLUGIN_FILTER_COMPONENT_CLASS_NOTIFICATION_ITERATOR_SEEK_TIME_METHOD(trimmer, - trimmer_iterator_seek_time); diff --git a/plugins/trimmer/trimmer.h b/plugins/utils/trimmer/trimmer.h similarity index 79% rename from plugins/trimmer/trimmer.h rename to plugins/utils/trimmer/trimmer.h index 4d82a244..655a60cb 100644 --- a/plugins/trimmer/trimmer.h +++ b/plugins/utils/trimmer/trimmer.h @@ -1,5 +1,5 @@ -#ifndef BABELTRACE_PLUGIN_TRIMMER_H -#define BABELTRACE_PLUGIN_TRIMMER_H +#ifndef BABELTRACE_PLUGINS_UTILS_TRIMMER_H +#define BABELTRACE_PLUGINS_UTILS_TRIMMER_H /* * BabelTrace - Trace Trimmer Plug-in @@ -29,6 +29,8 @@ #include #include +#include +#include #define NSEC_PER_SEC 1000000000LL @@ -48,4 +50,10 @@ struct trimmer { int year, month, day; }; -#endif /* BABELTRACE_PLUGIN_TRIMMER_H */ +enum bt_component_status trimmer_component_init( + struct bt_component *component, struct bt_value *params, + void *init_method_data); + +void destroy_trimmer(struct bt_component *component); + +#endif /* BABELTRACE_PLUGINS_UTILS_TRIMMER_H */ -- 2.34.1