org.eclipse.jdt.core.compiler.source=1.8
org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16
-org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0
+org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation=16
org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_declaration=do not insert
org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation=do not insert
org.eclipse.jdt.core.formatter.join_lines_in_comments=true
-org.eclipse.jdt.core.formatter.join_wrapped_lines=true
+org.eclipse.jdt.core.formatter.join_wrapped_lines=false
org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line=false
org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line=false
org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line=false
package org.lttng.tools;
import java.util.List;
+import java.util.Set;
/**
* Java representation of a LTTng tracing session.
*/
boolean disableAllEvents();
+ /**
+ * Get a list of events currently available (exposed by applications) in the
+ * session's domain.
+ *
+ * @return The list of available events
+ */
+ Set<String> listEvents();
+
/**
* Start tracing
*
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
"lttng", "disable-event", domain.flag(), "-a", "-s", sessionName));
}
+ @Override
+ public Set<String> listEvents() {
+ List<String> output = ShellUtils.getOutputFromCommand(true, Arrays.asList("lttng", "list", domain.flag()));
+ return output.stream()
+ .map(e -> e.trim())
+ .filter(e -> e.startsWith("- "))
+ .map(e -> e.substring(2))
+ .collect(Collectors.toSet());
+ }
+
@Override
public boolean start() {
/*
org.eclipse.jdt.core.compiler.source=1.8
org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16
-org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0
+org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation=16
org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_declaration=do not insert
org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation=do not insert
org.eclipse.jdt.core.formatter.join_lines_in_comments=true
-org.eclipse.jdt.core.formatter.join_wrapped_lines=true
+org.eclipse.jdt.core.formatter.join_wrapped_lines=false
org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line=false
org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line=false
org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line=false
--- /dev/null
+/*
+ * Copyright (C) 2015, EfficiOS Inc., Alexandre Montplaisir <alexmonthy@efficios.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+package org.lttng.ust.agent.integration.events;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.lttng.tools.ILttngSession;
+
+/**
+ * Base class for the list events command tests
+ */
+public abstract class ListEventsITBase {
+
+ protected static final String LOGGER_NAME_1 = "org.lttng";
+ protected static final String LOGGER_NAME_2 = "org.lttng.mycomponent";
+ protected static final String LOGGER_NAME_3 = "org.lttng.myothercomponent";
+
+ private ILttngSession session;
+
+ /**
+ * Common test setup
+ */
+ @Before
+ public void testSetup() {
+ session = ILttngSession.createSession(null, getDomain());
+ }
+
+ /**
+ * Common test teardown
+ */
+ @After
+ public void testTeardown() {
+ session.close();
+ }
+
+ protected abstract ILttngSession.Domain getDomain();
+
+ protected abstract void attachHandlerToLogger(int handlerIndex, int loggerIndex);
+
+ protected abstract void detachHandlerFromLogger(int handlerIndex, int loggerIndex);
+
+ /**
+ * Test with many loggers existing, but none of them having a LTTng handler
+ * attached.
+ */
+ @Test
+ public void testManyLoggersNoneAttached() {
+ /* Don't attach anything */
+ Set<String> actualEvents = session.listEvents();
+ assertTrue(actualEvents.isEmpty());
+ }
+
+ /**
+ * Test with many loggers existing, but only a subset of them has a LTTng
+ * handler attached.
+ */
+ @Test
+ public void testManyLoggersSomeAttached() {
+ attachHandlerToLogger(1, 1);
+
+ Set<String> expectedEvents = new HashSet<>(Arrays.asList(LOGGER_NAME_1));
+ Set<String> actualEvents = session.listEvents();
+
+ assertEquals(expectedEvents, actualEvents);
+ }
+
+ /**
+ * Test with many loggers existing, and all of them having a LTTng handler
+ * attached.
+ */
+ @Test
+ public void testManyLoggersAllAttached() {
+ attachHandlerToLogger(1, 1);
+ attachHandlerToLogger(2, 2);
+ attachHandlerToLogger(2, 3);
+
+ Set<String> expectedEvents = new HashSet<>(Arrays.asList(LOGGER_NAME_1, LOGGER_NAME_2, LOGGER_NAME_3));
+ Set<String> actualEvents = session.listEvents();
+
+ assertEquals(expectedEvents, actualEvents);
+ }
+
+ /**
+ * Test with some loggers having had handlers attached but then detached.
+ */
+ @Test
+ public void testLoggersSomeDetached() {
+ attachHandlerToLogger(1, 1);
+ attachHandlerToLogger(2, 2);
+
+ attachHandlerToLogger(2, 3);
+ detachHandlerFromLogger(2, 3);
+ /* Only loggers 1 and 2 will be attached */
+
+ Set<String> expectedEvents = new HashSet<>(Arrays.asList(LOGGER_NAME_1, LOGGER_NAME_2));
+ Set<String> actualEvents = session.listEvents();
+
+ assertEquals(expectedEvents, actualEvents);
+ }
+
+ /**
+ * Test with all loggers having had handlers attached and then detached.
+ */
+ @Test
+ public void testLoggersAllDetached() {
+ attachHandlerToLogger(1, 1);
+ attachHandlerToLogger(2, 2);
+ attachHandlerToLogger(2, 3);
+ detachHandlerFromLogger(1, 1);
+ detachHandlerFromLogger(2, 2);
+ detachHandlerFromLogger(2, 3);
+
+ Set<String> actualEvents = session.listEvents();
+ assertTrue(actualEvents.isEmpty());
+ }
+}
--- /dev/null
+/*
+ * Copyright (C) 2015, EfficiOS Inc., Alexandre Montplaisir <alexmonthy@efficios.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+package org.lttng.ust.agent.integration.events.jul;
+
+import static org.junit.Assume.assumeTrue;
+
+import java.io.IOException;
+import java.util.logging.Handler;
+import java.util.logging.Logger;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.lttng.tools.ILttngSession.Domain;
+import org.lttng.tools.ILttngSession;
+import org.lttng.tools.LttngToolsHelper;
+import org.lttng.ust.agent.integration.events.ListEventsITBase;
+import org.lttng.ust.agent.jul.LttngLogHandler;
+import org.lttng.ust.agent.utils.LttngUtils;
+
+/**
+ * Test suite for the list events command for the JUL domain
+ */
+public class JulListEventsIT extends ListEventsITBase {
+
+ private Logger[] loggers;
+ private Handler[] handlers;
+
+ /**
+ * Test class setup
+ */
+ @BeforeClass
+ public static void testClassSetup() {
+ /* Skip tests if we can't find the JNI library or lttng-tools */
+ assumeTrue(LttngUtils.checkForJulLibrary());
+ assumeTrue(LttngUtils.checkForLttngTools(Domain.JUL));
+
+ LttngToolsHelper.destroyAllSessions();
+ }
+
+ /**
+ * Test setup
+ *
+ * @throws SecurityException
+ * @throws IOException
+ */
+ @Before
+ public void julSetup() throws SecurityException, IOException {
+ loggers = new Logger[] {
+ Logger.getLogger(LOGGER_NAME_1),
+ Logger.getLogger(LOGGER_NAME_2),
+ Logger.getLogger(LOGGER_NAME_3)
+ };
+
+ handlers = new Handler[] {
+ new LttngLogHandler(),
+ new LttngLogHandler()
+ };
+ }
+
+ /**
+ * Test teardown. Detach and close all log handlers.
+ */
+ @After
+ public void julTeardown() {
+ for (Logger logger : loggers) {
+ for (Handler handler : handlers) {
+ logger.removeHandler(handler);
+ }
+ }
+
+ for (Handler handler : handlers) {
+ handler.close();
+ }
+ handlers = null;
+ loggers = null;
+ }
+
+ @Override
+ protected ILttngSession.Domain getDomain() {
+ return ILttngSession.Domain.JUL;
+ }
+
+ @Override
+ protected void attachHandlerToLogger(int handlerIndex, int loggerIndex) {
+ loggers[loggerIndex - 1].addHandler(handlers[handlerIndex - 1]);
+ }
+
+ @Override
+ protected void detachHandlerFromLogger(int handlerIndex, int loggerIndex) {
+ loggers[loggerIndex - 1].removeHandler(handlers[handlerIndex - 1]);
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2015, EfficiOS Inc., Alexandre Montplaisir <alexmonthy@efficios.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+package org.lttng.ust.agent.integration.events.log4j;
+
+import static org.junit.Assume.assumeTrue;
+
+import java.io.IOException;
+
+import org.apache.log4j.Appender;
+import org.apache.log4j.Logger;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.lttng.tools.ILttngSession.Domain;
+import org.lttng.tools.ILttngSession;
+import org.lttng.tools.LttngToolsHelper;
+import org.lttng.ust.agent.integration.events.ListEventsITBase;
+import org.lttng.ust.agent.log4j.LttngLogAppender;
+import org.lttng.ust.agent.utils.LttngUtils;
+
+/**
+ * Test suite for the list events command for the log4j domain
+ */
+public class Log4jListEventsIT extends ListEventsITBase {
+
+ private Logger[] loggers;
+ private Appender[] appenders;
+
+ /**
+ * Test class setup
+ */
+ @BeforeClass
+ public static void testClassSetup() {
+ /* Skip tests if we can't find the JNI library or lttng-tools */
+ assumeTrue(LttngUtils.checkForLog4jLibrary());
+ assumeTrue(LttngUtils.checkForLttngTools(Domain.LOG4J));
+
+ LttngToolsHelper.destroyAllSessions();
+ }
+
+ /**
+ * Test setup
+ *
+ * @throws SecurityException
+ * @throws IOException
+ */
+ @Before
+ public void log4jSetup() throws SecurityException, IOException {
+ loggers = new Logger[] {
+ Logger.getLogger(LOGGER_NAME_1),
+ Logger.getLogger(LOGGER_NAME_2),
+ Logger.getLogger(LOGGER_NAME_3)
+ };
+
+ appenders = new Appender[] {
+ new LttngLogAppender(),
+ new LttngLogAppender()
+ };
+ }
+
+ /**
+ * Test teardown. Detach and close all log handlers.
+ */
+ @After
+ public void log4jTeardown() {
+ for (Logger logger : loggers) {
+ for (Appender appender : appenders) {
+ logger.removeAppender(appender);
+ }
+ }
+
+ for (Appender appender : appenders) {
+ appender.close();
+ }
+ appenders = null;
+ loggers = null;
+ }
+
+ @Override
+ protected ILttngSession.Domain getDomain() {
+ return ILttngSession.Domain.LOG4J;
+ }
+
+ @Override
+ protected void attachHandlerToLogger(int handlerIndex, int loggerIndex) {
+ loggers[loggerIndex - 1].addAppender(appenders[handlerIndex - 1]);
+ }
+
+ @Override
+ protected void detachHandlerFromLogger(int handlerIndex, int loggerIndex) {
+ loggers[loggerIndex - 1].removeAppender(appenders[handlerIndex - 1]);
+ }
+
+}