Skip to content

Commit 255eccb

Browse files
committed
Plugin to filter traces based on thapi_start/stop
1 parent 38b886a commit 255eccb

3 files changed

Lines changed: 89 additions & 6 deletions

File tree

utils/Makefile.am

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,38 @@ bin_PROGRAMS = thapi_metadata
4141

4242
include_HEADERS = thapi.h
4343

44-
BUILT_SOURCES += \
45-
thapi_tracepoints.h \
46-
thapi_tracepoints.c
47-
44+
lib_LTLIBRARIES = libThapi.la
4845
nodist_libThapi_la_SOURCES = \
4946
thapi_tracepoints.h \
5047
thapi_tracepoints.c
51-
5248
libThapi_la_SOURCES = thapi_toggle.c
5349
libThapi_la_CFLAGS = $(LTTNG_FLAGS) $(LTTNG_UST_CFLAGS)
5450
libThapi_la_LDFLAGS = $(LTTNG_UST_LIBS)
5551

56-
lib_LTLIBRARIES = libThapi.la
52+
BTX_THAPI_GENERATED = \
53+
btx_thapi/metababel/metababel.h \
54+
btx_thapi/metababel/btx_component.h \
55+
btx_thapi/metababel/btx_component.c \
56+
btx_thapi/metababel/btx_upstream.h \
57+
btx_thapi/metababel/btx_upstream.c \
58+
btx_thapi/metababel/btx_downstream.h \
59+
btx_thapi/metababel/btx_downstream.c \
60+
btx_thapi/btx_main.c
61+
62+
$(BTX_THAPI_GENERATED): btx_thapi.yaml thapi_callbacks.c
63+
$(METABABEL) --enable-callbacks on_downstream --component-type FILTER \
64+
--upstream $(top_srcdir)/utils/btx_thapi.yaml --downstream $(top_srcdir)/utils/btx_thapi.yaml \
65+
-o btx_thapi
66+
67+
noinst_LTLIBRARIES = libThapiPlugin.la
68+
nodist_libThapiPlugin_la_SOURCES = $(BTX_THAPI_GENERATED)
69+
libThapiPlugin_la_SOURCES = thapi_callbacks.c
70+
libThapiPlugin_la_CFLAGS = -fPIC -shared -Wall -Wextra -Wno-unused-parameter $(BABELTRACE2_CFLAGS) -I./btx_thapi -I$(top_srcdir)/utils/include
71+
72+
BUILT_SOURCES += \
73+
thapi_tracepoints.h \
74+
thapi_tracepoints.c \
75+
$(BTX_THAPI_GENERATED)
5776

5877
bin_SCRIPTS = \
5978
babeltrace_thapi
@@ -74,6 +93,7 @@ CLEANFILES = \
7493
version \
7594
optparse_thapi.rb \
7695
lttng/tracepoint_gen.h \
96+
$(BTX_THAPI_GENERATED) \
7797
$(BUILT_SOURCES)
7898

7999
EXTRA_DIST = \
@@ -87,6 +107,7 @@ EXTRA_DIST = \
87107
dump_trace_format.rb \
88108
thapi_metadata_tracepoints.tp \
89109
thapi_tracepoints.tp \
110+
btx_thapi.yaml \
90111
command.rb \
91112
meta_parameters.rb \
92113
optparse_thapi.rb \

utils/btx_thapi.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
:stream_classes:
2+
- :name: thapi_toggle
3+
:default_clock_class: {}
4+
:packet_context_field_class:
5+
:type: structure
6+
:members:
7+
- :name: cpu_id
8+
:field_class:
9+
:type: integer_unsigned
10+
:cast_type: uint64_t
11+
:field_value_range: 32
12+
:event_common_context_field_class:
13+
:type: structure
14+
:members:
15+
- :name: vpid
16+
:field_class:
17+
:type: integer_signed
18+
:field_value_range: 32
19+
:cast_type: int
20+
- :name: vtid
21+
:field_class:
22+
:type: integer_signed
23+
:field_value_range: 32
24+
:cast_type: int
25+
:event_classes:
26+
- :name: lttng_ust_toggle:start
27+
- :name: lttng_ust_toggle:stop

utils/thapi_callbacks.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include <metababel/metababel.h>
2+
3+
static void init(void **data) { *data = calloc(1, sizeof(int)); }
4+
5+
static void finalize(void *data) { free(data); }
6+
7+
static void thapi_start_callback(void *btx_handle, void *push, long int cpuid,
8+
int vpid, int vtid) {
9+
*((int *)push) = 1;
10+
}
11+
12+
static void thapi_stop_callback(void *btx_handle, void *push, long int cpuid,
13+
int vpid, int vtid) {
14+
*((int *)push) = 0;
15+
}
16+
17+
static void push_downstream(void *btx_handle, void *push,
18+
const bt_message *msg) {
19+
if (*((int *)push) == 1)
20+
btx_push_message(btx_handle, msg);
21+
else
22+
bt_message_put_ref(msg);
23+
}
24+
25+
void btx_register_usr_callbacks(void *btx_handle) {
26+
btx_register_callbacks_initialize_component(btx_handle, &init);
27+
btx_register_callbacks_finalize_component(btx_handle, &finalize);
28+
29+
btx_register_callbacks_lttng_ust_toggle_start(btx_handle,
30+
&thapi_start_callback);
31+
btx_register_callbacks_lttng_ust_toggle_stop(btx_handle,
32+
&thapi_stop_callback);
33+
34+
btx_register_on_downstream_message_callback(btx_handle, &push_downstream);
35+
}

0 commit comments

Comments
 (0)