java: add initial bindings
This patch adds basic java bindings for libtracecmd. It currently supports very basic handling of parsing trace-cmd recorded trace files. There might of course additional improvements regarding swig bindings and the memory handling. E.g. in javas builtin iterator for-each handling everything will keep in memory. The license for the high-level java bindings jar file is LGPL-2.1 and is the same as libtracecmd.
The author of this patch created a java application that uses those java bindings to trace locks and represent them in graphical GANTT diagram, see [0].
You need to set the JAVA_HOME environment variable to let the Makefile know that it builds the java bindings. This is somehow standard in the java world as replacement for pkg-config or similar. There should no trace-cmd java dependency, the recommended way should be to provide a kind of trace-cmd-java package from your distribution containing the tracecmd.jar and libctracecmdjava.so. This package would have then a java dependency to e.g. OpenJDK, that I was using to test those bindings for.
The author is not a swig expert but it works as it currently is. Also the author did not hit issues because memory _yet_. Those are beginning experimental bindings and can be changed/improved in future.
[0] https://gitlab.com/netcoder/dlm2slog2
--- .gitignore | 4 + Makefile | 60 ++++++- java/Makefile | 39 +++++ java/TraceCmd.java | 236 +++++++++++++++++++++++++ java/TraceCmdEvent.java | 277 ++++++++++++++++++++++++++++++ java/TraceCmdException.java | 16 ++ java/TraceCmdField.java | 104 +++++++++++ java/ctracecmdjava.i | 180 +++++++++++++++++++ java/example/Makefile | 7 + java/example/TraceCmdExample.java | 33 ++++ 10 files changed, 953 insertions(+), 3 deletions(-) create mode 100644 java/Makefile create mode 100644 java/TraceCmd.java create mode 100644 java/TraceCmdEvent.java create mode 100644 java/TraceCmdException.java create mode 100644 java/TraceCmdField.java create mode 100644 java/ctracecmdjava.i create mode 100644 java/example/Makefile create mode 100644 java/example/TraceCmdExample.java
.gitignore +4 -0
@@ -10,12 +10,16 @@ .pc *~ *.pyc +*.class +*.jar *.swp \#*\# patches/ tc_version.h ks_version.h ctracecmd_wrap.c +ctracecmdjava_wrap.c +swig/ ctracecmdgui_wrap.c tags TAGS
Makefile +57 -3
137 lines not on this page · raw message
java/Makefile new file +39 -0
@@ -0,0 +1,39 @@ +# SPDX-License-Identifier: GPL-2.0 + +include $(src)/scripts/utils.mk + +ifdef BUILD_JAVA_WORKS +JAVA_SO_INSTALL := libctracecmdjava.install +JAVA_JAR_INSTALL := tracecmd.install +endif + +root_pkgdir := tracecmd +swigdir := swig +jardir := jar + +SRCS := TraceCmd.java TraceCmdEvent.java TraceCmdException.java TraceCmdField.java + +libctracecmdjava.so: ctracecmdjava.i $(LIBTRACECMD_STATIC) + @mkdir -p $(swigdir) + swig -Wall -java -noproxy -package $(root_pkgdir).swig -I$(src)/include/trace-cmd $(LIBTRACEEVENT_CFLAGS) -outdir $(swigdir) ctracecmdjava.i + $(CC) -fpic -c $(JAVA_INCLUDES) $(CPPFLAGS) $(CFLAGS) ctracecmdjava_wrap.c + $(CC) --shared $(LIBTRACECMD_STATIC) $(LDFLAGS) ctracecmdjava_wrap.o -o libctracecmdjava.so $(TRACE_LIBS) + +tracecmd.jar: libctracecmdjava.so $(SRCS) + $(JAVA_JAVAC) -d . $(swigdir)/*.java *.java + $(JAVA_JAR) cf tracecmd.jar $(root_pkgdir) + +$(JAVA_SO_INSTALL): %.install : %.so force + $(Q)$(call do_install_data,$<,$(libdir_SQ)) + +$(JAVA_JAR_INSTALL): %.install : %.jar force + $(Q)$(call do_install_data,$<,$(java_dir_JAR)) + +install_java: $(JAVA_SO_INSTALL) $(JAVA_JAR_INSTALL) + +clean: + $(RM) *.jar *.a *.so *.o .*.d ctracecmdjava_wrap.* + $(RM) -r $(swigdir) tracecmd + +force: +.PHONY: clean force
java/TraceCmd.java new file +236 -0
236 lines not on this page · raw message
java/TraceCmdEvent.java new file +277 -0
277 lines not on this page · raw message
java/TraceCmdException.java new file +16 -0
@@ -0,0 +1,16 @@ +// SPDX-License-Identifier: LGPL-2.1 +/* + * Copyright (C) 2022 Red Hat Inc, Alexander Aring <[email protected]> + * + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + */ + +package tracecmd; + +class TraceCmdException extends RuntimeException +{ + public TraceCmdException(String m) + { + super(m); + } +}
java/TraceCmdField.java new file +104 -0
104 lines not on this page · raw message
java/ctracecmdjava.i new file +180 -0
180 lines not on this page · raw message
java/example/Makefile new file +7 -0
@@ -0,0 +1,7 @@ +# SPDX-License-Identifier: GPL-2.0 + +all: + $(JAVA_HOME)/bin/javac -classpath ../tracecmd.jar TraceCmdExample.java + +clean: + $(RM) *.class
java/example/TraceCmdExample.java new file +33 -0
@@ -0,0 +1,33 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2022 Red Hat Inc, Alexander Aring <[email protected]> + * + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + */ + +import tracecmd.*; + +/** +* Very small example how to use libtracecmd java bindings. +* +* Run as: +* +* $JAVA_HOME/bin/java -cp ../tracecmd.jar:. TraceCmdExample $TRACE.DAT +* +* @author Alexander Aring <[email protected]> +* +*/ +public class TraceCmdExample +{ + public static final void main(String[] args) + { + TraceCmd t = new TraceCmd(args[0]); + + System.out.println("First Timestamp: " + t.getFirstTs()); + System.out.println("Amount of Cpus: " + t.getCpus()); + + for (TraceCmdEvent e:t) { + System.out.println(e); + } + } +}
Signature · 1 line
2.31.1
On Mon, 20 Jun 2022 16:45:39 -0400
Alexander Aring <[email protected]> wrote:
Hi Alexander!
Quoted 19 lines
This patch adds basic java bindings for libtracecmd. It currently supports very basic handling of parsing trace-cmd recorded trace files. There might of course additional improvements regarding swig bindings and the memory handling. E.g. in javas builtin iterator for-each handling everything will keep in memory. The license for the high-level java bindings jar file is LGPL-2.1 and is the same as libtracecmd.
The author of this patch created a java application that uses those java bindings to trace locks and represent them in graphical GANTT diagram, see [0].
You need to set the
JAVA_HOMEenvironment variable to let theMakefileknow that it builds the java bindings. This is somehow standard in the java world as replacement for pkg-config or similar. There should no trace-cmd java dependency, the recommended way should be to provide a kind of trace-cmd-java package from your distribution containing the tracecmd.jar and libctracecmdjava.so. This package would have then a java dependency to e.g. OpenJDK, that I was using to test those bindings for.
Quoted 3 lines
The author is not a swig expert but it works as it currently is. Also the author did not hit issues because memory _yet_. Those are beginning experimental bindings and can be changed/improved in future.
Are you "the author"?
Could you rephrase this better?
Like:
"There may be better ways to do this with swig, but this appears to work as is, as there were no issues because of memory _yet_."
That is, please try to rewrite the change log without referring to yourself.
Quoted 15 lines
[0] https://gitlab.com/netcoder/dlm2slog2
Signed-off-by Alexander Aring <[email protected]>--- .gitignore | 4 + Makefile | 60 ++++++- java/Makefile | 39 +++++ java/TraceCmd.java | 236 +++++++++++++++++++++++++ java/TraceCmdEvent.java | 277 ++++++++++++++++++++++++++++++ java/TraceCmdException.java | 16 ++ java/TraceCmdField.java | 104 +++++++++++ java/ctracecmdjava.i | 180 +++++++++++++++++++ java/example/Makefile | 7 + java/example/TraceCmdExample.java | 33 ++++ 10 files changed, 953 insertions(+), 3 deletions(-)
Quoted 9 lines
create mode 100644 java/Makefile create mode 100644 java/TraceCmd.java create mode 100644 java/TraceCmdEvent.java create mode 100644 java/TraceCmdException.java create mode 100644 java/TraceCmdField.java create mode 100644 java/ctracecmdjava.i create mode 100644 java/example/Makefile create mode 100644 java/example/TraceCmdExample.java
I'm not a swig nor Java expert, and will likely not even test this code. But I'm happy to include it if it doesn't break anything that I do test. But if anyone complains of breakage, I'll simply point them to you ;-)
Are you OK with that?
Hmm, I should add a MAINTAINERS file to add people that support different portions of trace-cmd.
-- Steve
Hi,
Quoted 26 lines · Steven Rostedt
On Mon, 20 Jun 2022 16:45:39 -0400
Alexander Aring <[email protected]> wrote:Hi Alexander!
Quoted 19 lines
This patch adds basic java bindings for libtracecmd. It currently supports very basic handling of parsing trace-cmd recorded trace files. There might of course additional improvements regarding swig bindings and the memory handling. E.g. in javas builtin iterator for-each handling everything will keep in memory. The license for the high-level java bindings jar file is LGPL-2.1 and is the same as libtracecmd.
The author of this patch created a java application that uses those java bindings to trace locks and represent them in graphical GANTT diagram, see [0].
You need to set the
JAVA_HOMEenvironment variable to let theMakefileknow that it builds the java bindings. This is somehow standard in the java world as replacement for pkg-config or similar. There should no trace-cmd java dependency, the recommended way should be to provide a kind of trace-cmd-java package from your distribution containing the tracecmd.jar and libctracecmdjava.so. This package would have then a java dependency to e.g. OpenJDK, that I was using to test those bindings for.
Quoted 7 lines
Quoted 3 lines
The author is not a swig expert but it works as it currently is. Also the author did not hit issues because memory _yet_. Those are beginning experimental bindings and can be changed/improved in future.
Are you "the author"?
yes.
Quoted 9 lines
Could you rephrase this better?
Like:
"There may be better ways to do this with swig, but this appears to work as is, as there were no issues because of memory _yet_."
That is, please try to rewrite the change log without referring to yourself.
okay.
Quoted 25 lines
Quoted 15 lines
[0] https://gitlab.com/netcoder/dlm2slog2
Signed-off-by Alexander Aring <[email protected]>--- .gitignore | 4 + Makefile | 60 ++++++- java/Makefile | 39 +++++ java/TraceCmd.java | 236 +++++++++++++++++++++++++ java/TraceCmdEvent.java | 277 ++++++++++++++++++++++++++++++ java/TraceCmdException.java | 16 ++ java/TraceCmdField.java | 104 +++++++++++ java/ctracecmdjava.i | 180 +++++++++++++++++++ java/example/Makefile | 7 + java/example/TraceCmdExample.java | 33 ++++ 10 files changed, 953 insertions(+), 3 deletions(-)Quoted 9 lines
create mode 100644 java/Makefile create mode 100644 java/TraceCmd.java create mode 100644 java/TraceCmdEvent.java create mode 100644 java/TraceCmdException.java create mode 100644 java/TraceCmdField.java create mode 100644 java/ctracecmdjava.i create mode 100644 java/example/Makefile create mode 100644 java/example/TraceCmdExample.java
Quoted 9 lines
I'm not a swig nor Java expert, and will likely not even test this code. But I'm happy to include it if it doesn't break anything that I do test. But if anyone complains of breakage, I'll simply point them to you ;-)
Are you OK with that?
Hmm, I should add a
MAINTAINERSfile to add people that support different portions of trace-cmd.
I already created a new project trace-cmd-java [0]. This will static link against libtracecmd and their dependencies. At the end it produces a binary blob for the java bindings. The advantage here is that I have full control over the used version of libtracecmd and their dependencies.
I would like to go this way and see how it goes. Meanwhile I can do more testing and cleanups. I may come back again to bring it upstream.
- Alex