Skip to contentSkip to conversation

tracecmd library: Use libtraceevent record refcounting

RFC PATCH New Benjamin Berg 1 participant 2 messages Oct 12, 2022 Kbuild

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/2 tracecmd library: Use libtraceevent record refcounting

Moving this into libtraceevent has the advantage that a python plugin loader can be implemented that does not need access to trace-cmd API.

---
 .../include/private/trace-cmd-private.h       |  2 +-
 lib/trace-cmd/trace-input.c                   | 94 +++++++++----------
 2 files changed, 48 insertions(+), 48 deletions(-)
lib/trace-cmd/include/private/trace-cmd-private.h +1 -1
index d73a5191..b08ebcee 100644
@@ -235,7 +235,7 @@ tracecmd_peek_data_ref(struct tracecmd_input *handle, int cpu)
 {
 	struct tep_record *rec = tracecmd_peek_data(handle, cpu);
 	if (rec)
-		rec->ref_count++;
+		tep_record_ref(rec);
 	return rec;
 }
 
lib/trace-cmd/trace-input.c +47 -47

205 lines not on this page · raw message

Signature · 1 line
2.37.3
#1 lore raw

RFC PATCH 2/2 trace-cmd: Add back python support without wrapping trace-cmd API

This code appears to be working at this point. Note that it is a pure libtraceevent plugin at this point (the trace-cmd API is not wrapped anymore). As such, the code should live in libtraceevent rather than here.

Also, the Makefile changes are incomplete.

Coming from the GNOME side, I was considering that a good approach might be to create a GLib based wrapper library for libtraceevent and a separate (python) plugin loader using it. I suppose, if people are happy with the current SWIG bindings, then it is not worth to do that though.

---
 Makefile                      |   5 +-
 python/Makefile               |  11 +++-
 python/ctracecmd.i            |  12 ++--
 python/plugin_python_loader.c | 115 ++++++++++++++++++++++++++++++++++
 python/tracecmd.py            |  91 +++------------------------
 5 files changed, 143 insertions(+), 91 deletions(-)
 create mode 100644 python/plugin_python_loader.c
Makefile +4 -1
index 7178d7a9..19649f4a 100644
@@ -142,7 +142,7 @@ NO_PYTHON = 1
 endif
 
 ifndef NO_PYTHON
-PYTHON		:= ctracecmd.so
+PYTHON		:= ctracecmd.so plugin_python_loader.so
 
 PYTHON_VERS ?= python
 PYTHON_PKGCONFIG_VERS ?= $(PYTHON_VERS)
@@ -585,6 +585,9 @@ export PYGTK_CFLAGS
 ctracecmd.so: force $(LIBTRACECMD_STATIC)
 	$(Q)$(MAKE) -C $(src)/python $@
 
+plugin_python_loader.so: force $(LIBTRACECMD_STATIC)
+	$(Q)$(MAKE) -C $(src)/python $@
+
 PHONY += python
 python: $(PYTHON)
 
python/Makefile +9 -2
index 63f5736d..d0bab375 100644
@@ -6,10 +6,11 @@ ifdef BUILD_PYTHON_WORKS
 PYTHON_SO_INSTALL := ctracecmd.install
 PYTHON_PY_PROGS := event-viewer.install
 PYTHON_PY_LIBS := tracecmd.install
+PYTHON_PLUGIN := plugin_python_loader.so
 endif
 
 ctracecmd.so: ctracecmd.i $(LIBTRACECMD_STATIC)
-	swig -Wall -python -noproxy -I$(src)/include/trace-cmd $(LIBTRACEEVENT_CFLAGS) ctracecmd.i
+	swig -Wall -python -noproxy $(LIBTRACEEVENT_CFLAGS) ctracecmd.i
 	$(CC) -fpic -c $(CPPFLAGS) $(CFLAGS) $(PYTHON_INCLUDES)  ctracecmd_wrap.c
 	$(CC) --shared $(LIBTRACECMD_STATIC) $(LDFLAGS) ctracecmd_wrap.o -o ctracecmd.so $(TRACE_LIBS)
 
@@ -22,7 +23,13 @@ $(PYTHON_PY_PROGS): %.install : %.py force
 $(PYTHON_PY_LIBS): %.install : %.py force
 	$(Q)$(call do_install_data,$<,$(python_dir_SQ))
 
-install_python: $(PYTHON_SO_INSTALL) $(PYTHON_PY_PROGS) $(PYTHON_PY_LIBS)
+plugin_python_loader.so: %.so: %.o
+	$(Q)$(do_python_plugin_build)
+
+plugin_python_loader.o: %.o : %.c
+	$(Q)$(do_compile_python_plugin_obj)
+
+install_python: $(PYTHON_SO_INSTALL) $(PYTHON_PY_PROGS) $(PYTHON_PY_LIBS) $(PYTHON_PLUGIN)
 
 
 clean:
python/ctracecmd.i +8 -4
index 6d0179e3..c0c0097c 100644
@@ -12,9 +12,16 @@
 %apply unsigned long long *OUTPUT {unsigned long long *}
 %apply int *OUTPUT {int *}
 
+%ignore ref_count;
+%ignore locked;
+%ignore tep_print_field;
+%rename(tep_print_field) tep_print_field_content;
+
+//%feature("ref")   record "tep_record_ref($this));"
+//%feature("unref") record "tep_record_unref($this);"
+
 
 %{
-#include "trace-cmd.h"
 #include "event-parse.h"
 #include "event-utils.h"
 #include <Python.h>
@@ -204,8 +211,6 @@ static int python_callback(struct trace_seq *s,
 	PyObject *arglist, *result;
 	int r = 0;
 
-	record->ref_count++;
-
 	arglist = Py_BuildValue("(OOO)",
 		SWIG_NewPointerObj(SWIG_as_voidptr(s),
 				   SWIGTYPE_p_trace_seq, 0),
@@ -245,6 +250,5 @@ static int python_callback(struct trace_seq *s,
 #define __attribute__(x)
 #define __thread
 
-%include "trace-cmd.h"
 %include <trace-seq.h>
 %include <event-parse.h>
python/plugin_python_loader.c new file +115 -0

115 lines not on this page · raw message

python/tracecmd.py +7 -84

118 lines not on this page · raw message

Signature · 1 line
2.37.3