Re: [Cluster-devel] [PATCH/RFC] java: add initial bindings

2022-07-13 Thread Alexander Aring
Hi,

On Fri, Jul 8, 2022 at 2:31 PM Steven Rostedt  wrote:
>
> On Mon, 20 Jun 2022 16:45:39 -0400
> Alexander Aring  wrote:
>
> Hi Alexander!
>
>
> > 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.
>
>
> Are you "the author"?
>

yes.

> 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.

> >
> > [0] https://gitlab.com/netcoder/dlm2slog2
> > Signed-off-by: Alexander Aring 
> > ---
> >  .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
> >
>
> 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.
>

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

[0] https://gitlab.com/netcoder/trace-cmd-java



Re: [Cluster-devel] [PATCH/RFC] java: add initial bindings

2022-07-08 Thread Steven Rostedt
On Mon, 20 Jun 2022 16:45:39 -0400
Alexander Aring  wrote:

Hi Alexander!


> 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.


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.

> 
> [0] https://gitlab.com/netcoder/dlm2slog2
> Signed-off-by: Alexander Aring 
> ---
>  .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
> 

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



[Cluster-devel] [PATCH/RFC] java: add initial bindings

2022-06-20 Thread Alexander Aring
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
Signed-off-by: Alexander Aring 
---
 .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

diff --git a/.gitignore b/.gitignore
index eb1b0db..586601a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -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
diff --git a/Makefile b/Makefile
index d72686d..eeafac9 100644
--- a/Makefile
+++ b/Makefile
@@ -89,6 +89,7 @@ export DESTDIR DESTDIR_SQ
 ifeq ($(prefix),$(HOME))
 plugin_tracecmd_dir = $(libdir)/trace-cmd/plugins
 python_dir ?= $(libdir)/trace-cmd/python
+java_dir ?= $(libdir)/trace-cmd/java
 var_dir = $(HOME)/.trace-cmd/
 else
 python_dir ?= $(libdir)/trace-cmd/python
@@ -96,6 +97,9 @@ PLUGIN_DIR_TRACECMD = 
-DPLUGIN_TRACECMD_DIR="$(plugin_tracecmd_dir)"
 PYTHON_DIR = -DPYTHON_DIR="$(python_dir)"
 PLUGIN_DIR_TRACECMD_SQ = '$(subst ','\'',$(PLUGIN_DIR_TRACECMD))'
 PYTHON_DIR_SQ = '$(subst ','\'',$(PYTHON_DIR))'
+java_dir ?= $(libdir)/trace-cmd/java
+JAVA_DIR = -DJAVA_DIR="$(java_dir)"
+JAVA_DIR_JAR = '$(subst ','\'',$(JAVA_DIR))'
 var_dir = /var
 endif
 
@@ -104,6 +108,7 @@ bindir_SQ = $(subst ','\'',$(bindir))
 bindir_relative_SQ = $(subst ','\'',$(bindir_relative))
 plugin_tracecmd_dir_SQ = $(subst ','\'',$(plugin_tracecmd_dir))
 python_dir_SQ = $(subst ','\'',$(python_dir))
+java_dir_JAR = $(subst ','\'',$(java_dir))
 
 pound := \#
 
@@ -120,8 +125,11 @@ BASH_COMPLETE_DIR ?= $(etcdir)/bash_completion.d
 export PLUGIN_DIR_TRACECMD
 export PYTHON_DIR
 export PYTHON_DIR_SQ
+export JAVA_DIR
+export JAVA_DIR_JAR
 export plugin_tracecmd_dir_SQ
 export python_dir_SQ
+export java_dir_JAR
 export var_dir
 
 # copy a bit from Linux kbuild
@@ -139,6 +147,7 @@ SWIG_DEFINED := $(shell if command -v swig; then echo 1; 
else echo 0; fi)
 ifeq ($(SWIG_DEFINED), 0)
 BUILD_PYTHON := report_noswig
 NO_PYTHON = 1
+NO_JAVA = 1
 endif
 
 ifndef NO_PYTHON
@@ -160,6 +169,21 @@ endif # NO_PYTHON
 export BUILD_PYTHON_WORKS
 export NO_PYTHON
 
+ifndef NO_JAVA
+JAVA   := tracecmd.jar
+
+ifeq ($(origin JAVA_HOME),undefined)
+   BUILD_JAVA := report_nojavadev
+   NO_JAVA = 1
+else
+   BUILD_JAVA := $(JAVA)
+   BUILD_JAVA_WORKS := 1
+endif
+endif # NO_JAVA
+
+export BUILD_JAVA_WORKS
+export NO_JAVA
+
 # $(call test-build, snippet, ret) -> ret if snippet compiles
 #  -> empty otherwise
 test-build = $(if $(shell sh -c 'echo "$(1)" | \
@@ -375,7 +399,7 @@ override CFLAGS += $(PLUGIN_DIR_TRACECMD_SQ)
 override CFLAGS += $(udis86-flags) $(blk-flags) $(memfd-flags)
 override LDFLAGS += $(udis86-ldflags)
 
-CMD_TARGETS = trace-cmd $(BUILD_PYTHON)
+CMD_TARGETS = trace-cmd $(BUILD_PYTHON) $(BUILD_JAVA)
 
 ###
 #Default we just build trace-cmd
@@ -487,10 +511,13 @@ install_pl