Add trimmer plug-in skeleton
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 2 Dec 2016 20:36:52 +0000 (15:36 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Sat, 27 May 2017 18:09:07 +0000 (14:09 -0400)
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
configure.ac
include/babeltrace/plugin/plugin-system.h
plugins/Makefile.am
plugins/trimmer/Makefile.am [new file with mode: 0644]
plugins/trimmer/iterator.c [new file with mode: 0644]
plugins/trimmer/iterator.h [new file with mode: 0644]
plugins/trimmer/trimmer.c [new file with mode: 0644]
plugins/trimmer/trimmer.h [new file with mode: 0644]

index bc7df06811e4427ab587cbcaf635917fd23c1ce5..68d4668bfe3537281308eac33b85c1a53bc2cbcb 100644 (file)
@@ -423,6 +423,7 @@ AC_CONFIG_FILES([
        plugins/ctf/lttng-live/Makefile
        plugins/muxer/Makefile
        plugins/text/Makefile
+       plugins/trimmer/Makefile
        babeltrace.pc
        babeltrace-ctf.pc
 ])
index e471a0dd0c382293dd27605954e98b6117e66ba1..1ec7a08c40f269a513e2950408d5f1db086b9c46 100644 (file)
@@ -266,6 +266,17 @@ typedef struct bt_notification *(*bt_notification_iterator_get_cb)(
 typedef enum bt_notification_iterator_status (*bt_notification_iterator_next_cb)(
                struct bt_notification_iterator *iterator);
 
+/**
+ * Function advancing an iterator's position to a given time (relative to Epoch).
+ *
+ * @param iterator     Notification iterator instance
+ * @param time         Time at which to seek, expressed in ns since Epoch
+ * @returns            One of #bt_notification_iterator_status values
+ */
+typedef enum bt_notification_iterator_status
+               (*bt_notification_iterator_seek_time_cb)(
+               struct bt_notification_iterator *iterator, int64_t time);
+
 /**
  * Function cleaning-up an iterator's private data on destruction.
  *
@@ -296,6 +307,18 @@ extern enum bt_notification_iterator_status
 bt_notification_iterator_set_next_cb(struct bt_notification_iterator *iterator,
                bt_notification_iterator_next_cb next);
 
+/**
+ * Set an iterator's "seek_time" callback which sets the iterator's position to
+ *     provided time (in ns since Epoch).
+ *
+ * @param iterator     Notification iterator instance
+ * @param seek_timetime        Iterator "seek_time" callback
+ * @returns            One of #bt_notification_iterator_status values
+ */
+extern enum bt_notification_iterator_status
+bt_notification_iterator_set_seek_time_cb(struct bt_notification_iterator *iterator,
+               bt_notification_iterator_seek_time_cb seek_time);
+
 /**
  * Set an iterator's "destroy" callback.
  *
index 6575b0be24b59c0ccbaf7e0bb65df0fcfdb41f9c..ec8418f0672f53d4f91af4a3f9b047c49b1bff12 100644 (file)
@@ -1 +1 @@
-SUBDIRS = ctf text muxer
+SUBDIRS = ctf text muxer trimmer
diff --git a/plugins/trimmer/Makefile.am b/plugins/trimmer/Makefile.am
new file mode 100644 (file)
index 0000000..4729bc4
--- /dev/null
@@ -0,0 +1,16 @@
+AM_CFLAGS = $(PACKAGE_CFLAGS) -I$(top_srcdir)/include
+
+SUBDIRS = .
+
+plugindir = "$(PLUGINSDIR)"
+plugin_LTLIBRARIES = libbabeltrace-plugin-trimmer.la
+
+libbabeltrace_plugin_trimmer_la_SOURCES = \
+       trimmer.h trimmer.c iterator.h iterator.c
+
+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/trimmer/iterator.c b/plugins/trimmer/iterator.c
new file mode 100644 (file)
index 0000000..492f3f1
--- /dev/null
@@ -0,0 +1,91 @@
+/*
+ * iterator.c
+ *
+ * Babeltrace Trace Trimmer Iterator
+ *
+ * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ *
+ * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ *
+ * 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 "trimmer.h"
+#include "iterator.h"
+#include <babeltrace/plugin/notification/iterator.h>
+
+BT_HIDDEN
+enum bt_component_status trimmer_iterator_init(struct bt_component *component,
+               struct bt_notification_iterator *iterator)
+{
+       enum bt_component_status ret;
+       enum bt_notification_iterator_status it_ret;
+
+       it_ret = bt_notification_iterator_set_next_cb(iterator,
+                       trimmer_iterator_next);
+       if (it_ret) {
+               ret = BT_COMPONENT_STATUS_ERROR;
+               goto end;
+       }
+
+       it_ret = bt_notification_iterator_set_get_cb(iterator,
+                       trimmer_iterator_get);
+       if (it_ret) {
+               ret = BT_COMPONENT_STATUS_ERROR;
+               goto end;
+       }
+
+       it_ret = bt_notification_iterator_set_seek_time_cb(iterator,
+                       trimmer_iterator_seek_time);
+       if (it_ret) {
+               ret = BT_COMPONENT_STATUS_ERROR;
+               goto end;
+       }
+end:
+       return ret;
+}
+
+BT_HIDDEN
+struct bt_notification *trimmer_iterator_get(
+               struct bt_notification_iterator *iterator)
+{
+       return NULL;
+}
+
+BT_HIDDEN
+enum bt_notification_iterator_status trimmer_iterator_next(
+               struct bt_notification_iterator *iterator)
+{
+       enum bt_notification_iterator_status ret;
+
+       ret = BT_NOTIFICATION_ITERATOR_STATUS_OK;
+end:
+       return ret;
+}
+
+BT_HIDDEN
+enum bt_notification_iterator_status trimmer_iterator_seek_time(
+               struct bt_notification_iterator *iterator, int64_t time)
+{
+       enum bt_notification_iterator_status ret;
+
+       ret = BT_NOTIFICATION_ITERATOR_STATUS_OK;
+end:
+       return ret;
+}
diff --git a/plugins/trimmer/iterator.h b/plugins/trimmer/iterator.h
new file mode 100644 (file)
index 0000000..c32b498
--- /dev/null
@@ -0,0 +1,49 @@
+#ifndef BABELTRACE_PLUGIN_TRIMMER_ITERATOR_H
+#define BABELTRACE_PLUGIN_TRIMMER_ITERATOR_H
+
+/*
+ * BabelTrace - Trace Trimmer Iterator
+ *
+ * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ *
+ * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ *
+ * 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 "trimmer.h"
+
+BT_HIDDEN
+enum bt_component_status trimmer_iterator_init(
+               struct bt_component *component,
+               struct bt_notification_iterator *iterator);
+
+BT_HIDDEN
+struct bt_notification *trimmer_iterator_get(
+               struct bt_notification_iterator *iterator);
+
+BT_HIDDEN
+enum bt_notification_iterator_status trimmer_iterator_next(
+               struct bt_notification_iterator *iterator);
+
+BT_HIDDEN
+enum bt_notification_iterator_status trimmer_iterator_seek_time(
+               struct bt_notification_iterator *iterator, int64_t time);
+
+#endif /* BABELTRACE_PLUGIN_TRIMMER_ITERATOR_H */
diff --git a/plugins/trimmer/trimmer.c b/plugins/trimmer/trimmer.c
new file mode 100644 (file)
index 0000000..7e6f024
--- /dev/null
@@ -0,0 +1,109 @@
+/*
+ * trimmer.c
+ *
+ * Babeltrace Trace Trimmer
+ *
+ * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ *
+ * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ *
+ * 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 <babeltrace/plugin/plugin-macros.h>
+#include <babeltrace/plugin/component.h>
+#include <babeltrace/plugin/filter.h>
+#include <babeltrace/plugin/notification/notification.h>
+#include <babeltrace/plugin/notification/iterator.h>
+#include <babeltrace/plugin/notification/event.h>
+#include "trimmer.h"
+#include "iterator.h"
+
+static
+void destroy_trimmer_data(struct trimmer *trimmer)
+{
+       g_free(trimmer);
+}
+
+static
+struct trimmer *create_trimmer_data(void)
+{
+       struct trimmer *trimmer;
+
+       trimmer = g_new0(struct trimmer, 1);
+       if (!trimmer) {
+               goto end;
+       }
+end:
+       return trimmer;
+}
+
+static
+void destroy_trimmer(struct bt_component *component)
+{
+       void *data = bt_component_get_private_data(component);
+
+       destroy_trimmer_data(data);
+}
+
+enum bt_component_status trimmer_component_init(
+       struct bt_component *component, struct bt_value *params)
+{
+       enum bt_component_status ret;
+       struct trimmer *trimmer = create_trimmer_data();
+
+       if (!trimmer) {
+               ret = BT_COMPONENT_STATUS_NOMEM;
+               goto end;
+       }
+
+       ret = bt_component_set_destroy_cb(component,
+                       destroy_trimmer);
+       if (ret != BT_COMPONENT_STATUS_OK) {
+               goto error;
+       }
+
+       ret = bt_component_set_private_data(component, trimmer);
+       if (ret != BT_COMPONENT_STATUS_OK) {
+               goto error;
+       }
+
+       ret = bt_component_filter_set_iterator_init_cb(component,
+                       trimmer_iterator_init);
+       if (ret != BT_COMPONENT_STATUS_OK) {
+               goto error;
+       }
+end:
+       return ret;
+error:
+       destroy_trimmer_data(trimmer);
+       return ret;
+}
+
+/* Initialize plug-in entry points. */
+BT_PLUGIN_NAME("trimmer");
+BT_PLUGIN_DESCRIPTION("Babeltrace Trace Trimmer Plug-In.");
+BT_PLUGIN_AUTHOR("Jérémie Galarneau");
+BT_PLUGIN_LICENSE("MIT");
+
+BT_PLUGIN_COMPONENT_CLASSES_BEGIN
+BT_PLUGIN_FILTER_COMPONENT_CLASS_ENTRY("trimmer",
+               "Ensure that trace notifications outside of a given range are filtered-out.",
+               trimmer_component_init)
+BT_PLUGIN_COMPONENT_CLASSES_END
diff --git a/plugins/trimmer/trimmer.h b/plugins/trimmer/trimmer.h
new file mode 100644 (file)
index 0000000..9f4a34a
--- /dev/null
@@ -0,0 +1,39 @@
+#ifndef BABELTRACE_PLUGIN_TRIMMER_H
+#define BABELTRACE_PLUGIN_TRIMMER_H
+
+/*
+ * BabelTrace - Trace Trimmer Plug-in
+ *
+ * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ *
+ * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ *
+ * 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 <stdbool.h>
+#include <babeltrace/babeltrace-internal.h>
+#include <babeltrace/plugin/component.h>
+#include <babeltrace/plugin/plugin-system.h>
+
+struct trimmer {
+       int64_t range_start, range_end;
+};
+
+#endif /* BABELTRACE_PLUGIN_TRIMMER_H */
This page took 0.030578 seconds and 4 git commands to generate.