This example shows a basic sink component class packaged as a shared object plugin.
The name of the plugin is epitome
and the name of the sink component class is output
. Therefore the component class is identified in the babeltrace2
command-line tool as sink.epitome.output
.
A sink.epitome.output
component prints one text line to the standard output for each event message it consumes, for example:
1 #1: kmem_kmalloc (5 payload members)
2 #2: kmem_kfree (2 payload members)
3 #3: sched_waking (4 payload members)
4 #4: sched_migrate_task (5 payload members)
5 #5: sched_stat_runtime (4 payload members)
6 #6: sched_wakeup (4 payload members)
7 #7: rcu_utilization (1 payload member)
8 #8: rcu_utilization (1 payload member)
9 #9: sched_switch (7 payload members)
10 #10: syscall_entry_write (3 payload members)
For each line, there is:
A sink.epitome.output
component does not need any initialization parameter: it just prints to the standard output.
A sink.epitome.output
component creates a single input port named in
.
To simplify this example, a sink.epitome.output
component doesn't check the return status codes of API functions, but you must check them in production code.
The sink component class implementation and the shared object plugin macros are in the same file, epitome.c
:
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
#include <string.h>
#include <babeltrace2/babeltrace.h>
struct epitome_out {
uint64_t index;
};
static
const bt_value *params,
void *initialize_method_data)
{
struct epitome_out *epitome_out = malloc(sizeof(*epitome_out));
epitome_out->index = 1;
epitome_out);
"in", NULL, NULL);
}
static
{
free(epitome_out);
}
static
{
self_component_sink, 0);
in_port, &epitome_out->message_iterator);
}
static
void print_message(
struct epitome_out *epitome_out,
const bt_message *message)
{
goto end;
}
printf("#%" PRIu64 ": %s (%" PRIu64 " payload member%s)\n",
member_count, member_count == 1 ? "" : "s");
epitome_out->index++;
end:
return;
}
{
uint64_t message_count;
&message_count);
switch (next_status) {
goto end;
goto end;
goto end;
goto end;
default:
break;
}
for (uint64_t i = 0; i < message_count; i++) {
print_message(epitome_out, message);
}
end:
return status;
}
epitome_out_initialize);
epitome_out_graph_is_configured);
As per the Compile and link a Babeltrace 2 shared object plugin guide, you can build the shared object plugin as such:
1 $ cc epitome.c -fPIC -c $(pkg-config --cflags babeltrace2)
2 $ ld epitome.o -o epitome.so -shared $(pkg-config --libs babeltrace2)
With the babeltrace2
tool, you can use a sink.epitome.output
component, reading a CTF trace (see babeltrace2-source.ctf.fs(7)
) for example:
1 $ babeltrace2 --plugin-path=. /path/to/ctf/trace --component=sink.epitome.output