From f35c6aa089659c7d16867ce4eac740d30c2c0213 Mon Sep 17 00:00:00 2001 From: Alexandre Montplaisir Date: Fri, 17 Feb 2017 16:13:20 -0500 Subject: [PATCH] Log more information in the Java TCP client 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 Signed-off-by: Mathieu Desnoyers --- .../ust/agent/client/LttngAgentResponse.java | 55 +++++++++++++------ .../agent/client/LttngTcpSessiondClient.java | 43 ++++++++------- .../client/SessiondDisableEventCommand.java | 27 +++++---- .../client/SessiondEnableEventCommand.java | 9 +++ 4 files changed, 85 insertions(+), 49 deletions(-) diff --git a/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/LttngAgentResponse.java b/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/LttngAgentResponse.java index 40c38a55..3dce64b1 100644 --- a/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/LttngAgentResponse.java +++ b/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/LttngAgentResponse.java @@ -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() + + "]"; + } } diff --git a/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/LttngTcpSessiondClient.java b/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/LttngTcpSessiondClient.java index a0adceae..c035e5e2 100644 --- a/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/LttngTcpSessiondClient.java +++ b/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/LttngTcpSessiondClient.java @@ -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(); } diff --git a/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/SessiondDisableEventCommand.java b/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/SessiondDisableEventCommand.java index 43ff4026..7af4667e 100644 --- a/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/SessiondDisableEventCommand.java +++ b/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/SessiondDisableEventCommand.java @@ -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 + +"]"; + } } diff --git a/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/SessiondEnableEventCommand.java b/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/SessiondEnableEventCommand.java index 54fcb4c0..089c36c0 100644 --- a/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/SessiondEnableEventCommand.java +++ b/liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/SessiondEnableEventCommand.java @@ -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 + +"]"; + } } -- 2.34.1