Log more information in the Java TCP client
authorAlexandre Montplaisir <alexmonthy@efficios.com>
Fri, 17 Feb 2017 21:13:20 +0000 (16:13 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 10 Mar 2017 16:30:24 +0000 (11:30 -0500)
Instead of just logging "event enabled" and "event disabled",
also print what event rule was enabled or disabled.

Also print what type of response is sent (success or failure).

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/org/lttng/ust/agent/client/LttngAgentResponse.java
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/client/SessiondDisableEventCommand.java
liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/SessiondEnableEventCommand.java

index 40c38a55c1bf4588ea1fcd8862882a0e7fef3716..3dce64b1584dcdc61d47021343c599fa13c4b853 100644 (file)
@@ -32,25 +32,50 @@ abstract class LttngAgentResponse {
 
        private static final int INT_SIZE = 4;
 
+       public static final LttngAgentResponse SUCESS_RESPONSE = new LttngAgentResponse() {
+               @Override
+               public ReturnCode getReturnCode() {
+                       return ReturnCode.CODE_SUCCESS_CMD;
+               }
+       };
+
+       public static final LttngAgentResponse FAILURE_RESPONSE = new LttngAgentResponse() {
+               @Override
+               public ReturnCode getReturnCode() {
+                       return ReturnCode.CODE_INVALID_CMD;
+               }
+       };
+
        /**
         * Return codes used in agent responses, to indicate success or different
         * types of failures of the commands.
         */
        protected enum ReturnCode {
 
-               CODE_SUCCESS_CMD(1),
-               CODE_INVALID_CMD(2),
-               CODE_UNKNOWN_LOGGER_NAME(3);
+               CODE_SUCCESS_CMD(1, "sucess"),
+               CODE_INVALID_CMD(2, "invalid"),
+               CODE_UNKNOWN_LOGGER_NAME(3, "unknown logger name");
 
-               private int code;
+               private final int code;
+               private final String toString;
 
-               private ReturnCode(int c) {
+               private ReturnCode(int c, String str) {
                        code = c;
+                       toString = str;
                }
 
                public int getCode() {
                        return code;
                }
+
+               /**
+                * Mainly used for debugging. The strings are not sent through the
+                * socket.
+                */
+               @Override
+               public String toString() {
+                       return toString;
+               }
        }
 
        /**
@@ -75,17 +100,11 @@ abstract class LttngAgentResponse {
                return data;
        }
 
-       public static final LttngAgentResponse SUCESS_RESPONSE = new LttngAgentResponse() {
-               @Override
-               public ReturnCode getReturnCode() {
-                       return ReturnCode.CODE_SUCCESS_CMD;
-               }
-       };
-
-       public static final LttngAgentResponse FAILURE_RESPONSE = new LttngAgentResponse() {
-               @Override
-               public ReturnCode getReturnCode() {
-                       return ReturnCode.CODE_INVALID_CMD;
-               }
-       };
+       @Override
+       public String toString() {
+               return "LttngAgentResponse["
+                               + "code=" + getReturnCode().getCode()
+                               + ", " + getReturnCode().toString()
+                               + "]";
+       }
 }
index a0adceae6d32b0e9c1f9031b20dc422b07953678..c035e5e2e31043d4899ba2dc1bf1ee940ad249e7 100644 (file)
@@ -254,7 +254,7 @@ public class LttngTcpSessiondClient implements Runnable {
                /* Data read from the socket */
                byte inputData[] = null;
                /* Reply data written to the socket, sent to the sessiond */
-               byte responseData[] = null;
+               LttngAgentResponse response;
 
                while (true) {
                        /* Get header from session daemon. */
@@ -282,8 +282,7 @@ public class LttngTcpSessiondClient implements Runnable {
                        case CMD_LIST:
                        {
                                SessiondCommand listLoggerCmd = new SessiondListLoggersCommand();
-                               LttngAgentResponse response = listLoggerCmd.execute(logAgent);
-                               responseData = response.getBytes();
+                               response = listLoggerCmd.execute(logAgent);
                                log("Received list loggers command");
                                break;
                        }
@@ -291,38 +290,35 @@ public class LttngTcpSessiondClient implements Runnable {
                        {
                                if (inputData == null) {
                                        /* Invalid command */
-                                       responseData = LttngAgentResponse.FAILURE_RESPONSE.getBytes();
+                                       response = LttngAgentResponse.FAILURE_RESPONSE;
                                        break;
                                }
                                SessiondCommand enableEventCmd = new SessiondEnableEventCommand(inputData);
-                               LttngAgentResponse response = enableEventCmd.execute(logAgent);
-                               responseData = response.getBytes();
-                               log("Received enable event command");
+                               response = enableEventCmd.execute(logAgent);
+                               log("Received enable event command: " + enableEventCmd.toString());
                                break;
                        }
                        case CMD_EVENT_DISABLE:
                        {
                                if (inputData == null) {
                                        /* Invalid command */
-                                       responseData = LttngAgentResponse.FAILURE_RESPONSE.getBytes();
+                                       response = LttngAgentResponse.FAILURE_RESPONSE;
                                        break;
                                }
                                SessiondCommand disableEventCmd = new SessiondDisableEventCommand(inputData);
-                               LttngAgentResponse response = disableEventCmd.execute(logAgent);
-                               responseData = response.getBytes();
-                               log("Received disable event command");
+                               response = disableEventCmd.execute(logAgent);
+                               log("Received disable event command: " + disableEventCmd.toString());
                                break;
                        }
                        case CMD_APP_CTX_ENABLE:
                        {
                                if (inputData == null) {
                                        /* This commands expects a payload, invalid command */
-                                       responseData = LttngAgentResponse.FAILURE_RESPONSE.getBytes();
+                                       response = LttngAgentResponse.FAILURE_RESPONSE;
                                        break;
                                }
                                SessiondCommand enableAppCtxCmd = new SessiondEnableAppContextCommand(inputData);
-                               LttngAgentResponse response = enableAppCtxCmd.execute(logAgent);
-                               responseData = response.getBytes();
+                               response = enableAppCtxCmd.execute(logAgent);
                                log("Received enable app-context command");
                                break;
                        }
@@ -330,28 +326,33 @@ public class LttngTcpSessiondClient implements Runnable {
                        {
                                if (inputData == null) {
                                        /* This commands expects a payload, invalid command */
-                                       responseData = LttngAgentResponse.FAILURE_RESPONSE.getBytes();
+                                       response = LttngAgentResponse.FAILURE_RESPONSE;
                                        break;
                                }
                                SessiondCommand disableAppCtxCmd = new SessiondDisableAppContextCommand(inputData);
-                               LttngAgentResponse response = disableAppCtxCmd.execute(logAgent);
-                               responseData = response.getBytes();
+                               response = disableAppCtxCmd.execute(logAgent);
                                log("Received disable app-context command");
                                break;
                        }
                        default:
                        {
                                /* Unknown command, send empty reply */
-                               responseData = new byte[4];
-                               ByteBuffer buf = ByteBuffer.wrap(responseData);
-                               buf.order(ByteOrder.BIG_ENDIAN);
+                               response = null;
                                log("Received unknown command, ignoring");
                                break;
                        }
                        }
 
                        /* Send response to the session daemon. */
-                       log("Sending response");
+                       byte[] responseData;
+                       if (response == null) {
+                               responseData = new byte[4];
+                               ByteBuffer buf = ByteBuffer.wrap(responseData);
+                               buf.order(ByteOrder.BIG_ENDIAN);
+                       } else {
+                               log("Sending response: " + response.toString());
+                               responseData = response.getBytes();
+                       }
                        this.outToSessiond.write(responseData, 0, responseData.length);
                        this.outToSessiond.flush();
                }
index 43ff4026346fa62a8a18ef5d402eda6272d17c8f..7af4667e633c7f322a48de83daa6b0e3abb24e0b 100644 (file)
@@ -30,6 +30,17 @@ import java.nio.ByteOrder;
  */
 class SessiondDisableEventCommand extends SessiondCommand {
 
+       /**
+        * Response sent when the disable-event command asks to disable an
+        * unknown event.
+        */
+       private static final LttngAgentResponse DISABLE_EVENT_FAILURE_RESPONSE = new LttngAgentResponse() {
+               @Override
+               public ReturnCode getReturnCode() {
+                       return ReturnCode.CODE_UNKNOWN_LOGGER_NAME;
+               }
+       };
+
        /** Event name to disable from the tracing session */
        private final String eventName;
 
@@ -48,14 +59,10 @@ class SessiondDisableEventCommand extends SessiondCommand {
                return (success ? LttngAgentResponse.SUCESS_RESPONSE : DISABLE_EVENT_FAILURE_RESPONSE);
        }
 
-       /**
-        * Response sent when the disable-event command asks to disable an
-        * unknown event.
-        */
-       private static final LttngAgentResponse DISABLE_EVENT_FAILURE_RESPONSE = new LttngAgentResponse() {
-               @Override
-               public ReturnCode getReturnCode() {
-                       return ReturnCode.CODE_UNKNOWN_LOGGER_NAME;
-               }
-       };
+       @Override
+       public String toString() {
+               return "SessiondDisableEventCommand["
+                               + "eventName=" + eventName
+                               +"]";
+       }
 }
index 54fcb4c0042821a21f50a08564971f2b57ff8881..089c36c0a44f60313cedc84e8f4c86975af2a22e 100644 (file)
@@ -75,4 +75,13 @@ class SessiondEnableEventCommand extends SessiondCommand {
                boolean success = agent.eventEnabled(rule);
                return (success ? LttngAgentResponse.SUCESS_RESPONSE : LttngAgentResponse.FAILURE_RESPONSE);
        }
+
+       @Override
+       public String toString() {
+               return "SessiondEnableEventCommand["
+                               + "eventName=" + eventName
+                               + ", logLevel=" + logLevelFilter.toString()
+                               + ", filterString=" + filterString
+                               +"]";
+       }
 }
This page took 0.028986 seconds and 4 git commands to generate.