Bug #933 ยป 0001-Fix-Return-the-correct-list-of-available-Java-events.patch
liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/AbstractLttngAgent.java | ||
---|---|---|
package org.lttng.ust.agent;
|
||
import java.util.HashSet;
|
||
import java.util.LinkedList;
|
||
import java.util.List;
|
||
import java.util.Map;
|
||
import java.util.NavigableMap;
|
||
... | ... | |
return decrementEventCount(eventName, enabledEvents);
|
||
}
|
||
/*
|
||
* Implementation of this method is domain-specific.
|
||
*/
|
||
@Override
|
||
public Iterable<String> listEnabledEvents() {
|
||
List<String> events = new LinkedList<String>();
|
||
if (enabledWildcards.get() > 0) {
|
||
events.add(WILDCARD);
|
||
}
|
||
for (String prefix : enabledEventPrefixes.keySet()) {
|
||
events.add(new String(prefix + WILDCARD));
|
||
}
|
||
events.addAll(enabledEvents.keySet());
|
||
return events;
|
||
}
|
||
public abstract List<String> listAvailableEvents();
|
||
@Override
|
||
public boolean isEventEnabled(String eventName) {
|
liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/ILttngTcpClientListener.java | ||
---|---|---|
package org.lttng.ust.agent.client;
|
||
import java.util.List;
|
||
import org.lttng.ust.agent.session.EventRule;
|
||
/**
|
||
... | ... | |
boolean eventDisabled(String eventName);
|
||
/**
|
||
* List the all events currently enabled in the current tracing sessions.
|
||
* List the events that are available in the agent's tracing domain.
|
||
*
|
||
* In Java terms, this means loggers that have at least one LTTng log
|
||
* handler of their corresponding domain attached.
|
||
*
|
||
* @return The list of enabled events
|
||
* @return The list of available events
|
||
*/
|
||
Iterable<String> listEnabledEvents();
|
||
List<String> listAvailableEvents();
|
||
}
|
liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/SessiondListLoggersCommand.java | ||
---|---|---|
import java.nio.ByteBuffer;
|
||
import java.nio.ByteOrder;
|
||
import java.util.ArrayList;
|
||
import java.util.List;
|
||
/**
|
||
... | ... | |
@Override
|
||
public LttngAgentResponse execute(ILttngTcpClientListener agent) {
|
||
final List<String> loggerList = new ArrayList<String>();
|
||
final List<String> loggerList = agent.listAvailableEvents();
|
||
int dataSize = 0;
|
||
for (String event : agent.listEnabledEvents()) {
|
||
loggerList.add(event);
|
||
for (String event : agent.listAvailableEvents()) {
|
||
dataSize += event.length() + 1;
|
||
}
|
||
liblttng-ust-java-agent/java/lttng-ust-agent-jul/org/lttng/ust/agent/jul/LttngJulAgent.java | ||
---|---|---|
package org.lttng.ust.agent.jul;
|
||
import java.util.ArrayList;
|
||
import java.util.Enumeration;
|
||
import java.util.List;
|
||
import java.util.logging.Handler;
|
||
import java.util.logging.LogManager;
|
||
import java.util.logging.Logger;
|
||
import org.lttng.ust.agent.AbstractLttngAgent;
|
||
/**
|
||
... | ... | |
return instance;
|
||
}
|
||
@Override
|
||
public List<String> listAvailableEvents() {
|
||
List<String> ret = new ArrayList<String>();
|
||
Enumeration<String> loggers = LogManager.getLogManager().getLoggerNames();
|
||
while (loggers.hasMoreElements()) {
|
||
String name = loggers.nextElement();
|
||
/*
|
||
* Skip the root logger. An empty string is not a valid event name
|
||
* in LTTng.
|
||
*/
|
||
if (name.equals("")) {
|
||
continue;
|
||
}
|
||
/*
|
||
* Check if that logger has at least one LTTng JUL handler attached.
|
||
*/
|
||
Logger logger = Logger.getLogger(name);
|
||
if (hasLttngHandlerAttached(logger)) {
|
||
ret.add(name);
|
||
}
|
||
}
|
||
return ret;
|
||
}
|
||
private static boolean hasLttngHandlerAttached(Logger logger) {
|
||
for (Handler handler : logger.getHandlers()) {
|
||
if (handler instanceof LttngLogHandler) {
|
||
return true;
|
||
}
|
||
}
|
||
return false;
|
||
}
|
||
}
|
liblttng-ust-java-agent/java/lttng-ust-agent-log4j/org/lttng/ust/agent/log4j/LttngLog4jAgent.java | ||
---|---|---|
package org.lttng.ust.agent.log4j;
|
||
import java.util.ArrayList;
|
||
import java.util.Enumeration;
|
||
import java.util.List;
|
||
import org.apache.log4j.Appender;
|
||
import org.apache.log4j.LogManager;
|
||
import org.apache.log4j.Logger;
|
||
import org.lttng.ust.agent.AbstractLttngAgent;
|
||
/**
|
||
... | ... | |
return instance;
|
||
}
|
||
@Override
|
||
public List<String> listAvailableEvents() {
|
||
List<String> ret = new ArrayList<String>();
|
||
@SuppressWarnings("unchecked")
|
||
Enumeration<Logger> loggers = LogManager.getCurrentLoggers();
|
||
while (loggers.hasMoreElements()) {
|
||
Logger logger = loggers.nextElement();
|
||
/*
|
||
* Check if that logger has at least one LTTng log4j appender
|
||
* attached.
|
||
*/
|
||
if (hasLttngAppenderAttached(logger)) {
|
||
ret.add(logger.getName());
|
||
}
|
||
}
|
||
return ret;
|
||
}
|
||
private static boolean hasLttngAppenderAttached(Logger logger) {
|
||
@SuppressWarnings("unchecked")
|
||
Enumeration<Appender> appenders = logger.getAllAppenders();
|
||
while (appenders.hasMoreElements()) {
|
||
Appender appender = appenders.nextElement();
|
||
if (appender instanceof LttngLogAppender) {
|
||
return true;
|
||
}
|
||
}
|
||
return false;
|
||
}
|
||
}
|