Introduce a verbose mode for the Java agent ust-app-context
authorAlexandre Montplaisir <alexmonthy@efficios.com>
Thu, 4 Feb 2016 23:37:37 +0000 (18:37 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 5 Feb 2016 23:21:15 +0000 (18:21 -0500)
If the LTTNG_UST_DEBUG environment variable is defined, log messages
from the Java agent will be sent to stderr. This is in line with the
rest of UST.

Signed-off-by: Alexandre Montplaisir <alexmonthy@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
liblttng-ust-java-agent/java/lttng-ust-agent-common/Makefile.am
liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/LttngTcpSessiondClient.java
liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/context/ContextInfoSerializer.java
liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/utils/LttngUstAgentLogger.java [new file with mode: 0644]

index 683e451b15721cff825ee93c15662ec9f563d49a..8ef4bc23343c22921693bf0417f3d928ef40f005 100644 (file)
@@ -30,7 +30,8 @@ dist_noinst_JAVA = $(pkgpath)/AbstractLttngAgent.java \
                                   $(pkgpath)/filter/FilterChangeNotifier.java \
                                   $(pkgpath)/filter/IFilterChangeListener.java \
                                   $(pkgpath)/session/EventRule.java \
-                                  $(pkgpath)/session/LogLevelSelector.java
+                                  $(pkgpath)/session/LogLevelSelector.java \
+                                  $(pkgpath)/utils/LttngUstAgentLogger.java
 
 
 dist_noinst_DATA = $(jarfile_manifest)
@@ -41,7 +42,8 @@ classes = $(pkgpath)/*.class \
                  $(pkgpath)/client/*.class \
                  $(pkgpath)/context/*.class \
                  $(pkgpath)/filter/*.class \
-                 $(pkgpath)/session/*.class
+                 $(pkgpath)/session/*.class \
+                 $(pkgpath)/utils/*.class
 
 $(jarfile): classnoinst.stamp
        $(JAR) cfm $(JARFLAGS) $@ $(jarfile_manifest) $(classes) && rm -f $(jarfile_symlink) && $(LN_S) $@ $(jarfile_symlink)
@@ -63,4 +65,5 @@ CLEANFILES = $(jarfile) $(pkgpath)/*.class \
                         $(pkgpath)/context/*.class \
                         $(pkgpath)/filter/*.class \
                         $(pkgpath)/session/*.class \
+                        $(pkgpath)/utils/*.class \
                         $(juljniout)/org_lttng_ust_agent_context_LttngContextApi.h
index 5b5d50c4e3f360b563fb3fd2062934bdb47afac0..6177feac7a849cefb44e959197e30894b295f529 100644 (file)
@@ -32,6 +32,8 @@ import java.nio.ByteOrder;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 
+import org.lttng.ust.agent.utils.LttngUstAgentLogger;
+
 /**
  * Client for agents to connect to a local session daemon, using a TCP socket.
  *
@@ -109,12 +111,14 @@ public class LttngTcpSessiondClient implements Runnable {
                                /*
                                 * Connect to the session daemon before anything else.
                                 */
+                               LttngUstAgentLogger.log(getClass(), "Connecting to sessiond");
                                connectToSessiond();
 
                                /*
                                 * Register to the session daemon as the Java component of the
                                 * UST application.
                                 */
+                               LttngUstAgentLogger.log(getClass(), "Registering to sessiond");
                                registerToSessiond();
 
                                /*
@@ -122,6 +126,7 @@ public class LttngTcpSessiondClient implements Runnable {
                                 * session daemon. This will return if and only if there is a
                                 * fatal error or the socket closes.
                                 */
+                               LttngUstAgentLogger.log(getClass(), "Waiting on sessiond commands...");
                                handleSessiondCmd();
                        } catch (UnknownHostException uhe) {
                                uhe.printStackTrace();
@@ -139,6 +144,7 @@ public class LttngTcpSessiondClient implements Runnable {
         * Dispose this client and close any socket connection it may hold.
         */
        public void close() {
+               LttngUstAgentLogger.log(getClass(), "Closing client");
                this.quit = true;
 
                try {
@@ -247,6 +253,7 @@ public class LttngTcpSessiondClient implements Runnable {
                                 * We don't send any reply to the registration done command.
                                 * This just marks the end of the initial session setup.
                                 */
+                               LttngUstAgentLogger.log(getClass(), "Registration done");
                                continue;
                        }
                        case CMD_LIST:
@@ -254,6 +261,7 @@ public class LttngTcpSessiondClient implements Runnable {
                                SessiondCommand listLoggerCmd = new SessiondListLoggersCommand();
                                LttngAgentResponse response = listLoggerCmd.execute(logAgent);
                                responseData = response.getBytes();
+                               LttngUstAgentLogger.log(getClass(), "Received list loggers command");
                                break;
                        }
                        case CMD_EVENT_ENABLE:
@@ -266,6 +274,7 @@ public class LttngTcpSessiondClient implements Runnable {
                                SessiondCommand enableEventCmd = new SessiondEnableEventCommand(inputData);
                                LttngAgentResponse response = enableEventCmd.execute(logAgent);
                                responseData = response.getBytes();
+                               LttngUstAgentLogger.log(getClass(), "Received enable event command");
                                break;
                        }
                        case CMD_EVENT_DISABLE:
@@ -278,6 +287,7 @@ public class LttngTcpSessiondClient implements Runnable {
                                SessiondCommand disableEventCmd = new SessiondDisableEventCommand(inputData);
                                LttngAgentResponse response = disableEventCmd.execute(logAgent);
                                responseData = response.getBytes();
+                               LttngUstAgentLogger.log(getClass(), "Received disable event command");
                                break;
                        }
                        case CMD_APP_CTX_ENABLE:
@@ -290,6 +300,7 @@ public class LttngTcpSessiondClient implements Runnable {
                                SessiondCommand enableAppCtxCmd = new SessiondEnableAppContextCommand(inputData);
                                LttngAgentResponse response = enableAppCtxCmd.execute(logAgent);
                                responseData = response.getBytes();
+                               LttngUstAgentLogger.log(getClass(), "Received enable app-context command");
                                break;
                        }
                        case CMD_APP_CTX_DISABLE:
@@ -302,6 +313,7 @@ public class LttngTcpSessiondClient implements Runnable {
                                SessiondCommand disableAppCtxCmd = new SessiondDisableAppContextCommand(inputData);
                                LttngAgentResponse response = disableAppCtxCmd.execute(logAgent);
                                responseData = response.getBytes();
+                               LttngUstAgentLogger.log(getClass(), "Received disable app-context command");
                                break;
                        }
                        default:
@@ -310,11 +322,13 @@ public class LttngTcpSessiondClient implements Runnable {
                                responseData = new byte[4];
                                ByteBuffer buf = ByteBuffer.wrap(responseData);
                                buf.order(ByteOrder.BIG_ENDIAN);
+                               LttngUstAgentLogger.log(getClass(), "Received unknown command, ignoring");
                                break;
                        }
                        }
 
                        /* Send response to the session daemon. */
+                       LttngUstAgentLogger.log(getClass(), "Sending response");
                        this.outToSessiond.write(responseData, 0, responseData.length);
                        this.outToSessiond.flush();
                }
index 57382bd1c7d3613f5ad4393a0d3f75038b17e22a..be613043920af9b63290962df6c076879c43aa43 100644 (file)
@@ -24,6 +24,8 @@ import java.nio.charset.Charset;
 import java.util.Collection;
 import java.util.Map;
 
+import org.lttng.ust.agent.utils.LttngUstAgentLogger;
+
 /**
  * This class is used to serialize the list of "context info" objects to pass
  * through JNI.
@@ -142,6 +144,10 @@ public class ContextInfoSerializer {
                                buffer.put(strArray);
                                buffer.position(buffer.position() + remainingBytes);
 
+                               LttngUstAgentLogger.log(ContextInfoSerializer.class,
+                                               "ContextInfoSerializer: Context to be sent through JNI: " + fullContextName + '=' +
+                                               (contextInfo == null ? "null" : contextInfo.toString()));
+
                                serializeContextInfo(buffer, contextInfo);
                        }
                }
diff --git a/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/utils/LttngUstAgentLogger.java b/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/utils/LttngUstAgentLogger.java
new file mode 100644 (file)
index 0000000..16f23f7
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2016 - EfficiOS Inc., Alexandre Montplaisir <alexmonthy@efficios.com>
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License, version 2.1 only,
+ * as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.lttng.ust.agent.utils;
+
+/**
+ * Logging infrastructure for the lttng-ust Java agent. It prints log messages
+ * to stderr but only when the environment variable LTTNG_UST_DEBUG is defined.
+ *
+ * @author Alexandre Montplaisir
+ */
+public class LttngUstAgentLogger {
+
+       private static final String ENV_VAR_NAME = "LTTNG_UST_DEBUG";
+       private static final boolean LOGGING_ENABLED = (System.getenv(ENV_VAR_NAME) == null ? false : true);
+
+       /**
+        * Log event. Will be printed to stderr if the environment variable
+        * "LTTNG_UST_DEBUG" is defined.
+        *
+        * @param c
+        *            The class logging the message (should normally be called with
+        *            {@link #getClass()}).
+        * @param message
+        *            The message to print
+        */
+       public static void log(Class<?> c, String message) {
+               if (LOGGING_ENABLED) {
+                       System.err.println(c.getSimpleName() + ": " + message);
+               }
+       }
+}
This page took 0.028854 seconds and 5 git commands to generate.