ust-fd: Add close_range declaration
[lttng-ust.git] / doc / java-agent.txt
... / ...
CommitLineData
1======================
2 Using the Java agent
3======================
4
5The agent can be built in three different configurations:
6
71) Java agent with JUL support:
8
9$ ./configure --enable-java-agent-jul
10
112) Java agent with Log4j 1.x support (deprecated):
12
13$ export CLASSPATH=$CLASSPATH:/path/to/log4j.jar
14$ ./configure --enable-java-agent-log4j
15
163) Java agent with Log4j 2.x support:
17
18$ export CLASSPATH=$CLASSPATH:/path/to/log4j-core.jar:/path/to/log4j-api.jar
19$ ./configure --enable-java-agent-log4j2
20
214) Java agent with JUL + Log4j 1.x + Log4j 2.x support
22
23$ export CLASSPATH=$CLASSPATH:/path/to/log4j.jar:/path/to/log4j-core.jar:/path/to/log4j-api.jar
24$ ./configure --enable-java-agent-all
25
26To build the agent with log4j support, make sure that the log4j jar
27is in your Java classpath.
28
29The configure script will automatically detect the appropriate Java
30binaries to use in order to build the Java agent.
31
32Enabling the JUL support will build a "lttng-ust-agent-jul.jar" file. Enabling
33the log4j 1.x support will build a "lttng-ust-agent-log4j.jar" and enabling
34log4j 2.x support will build a "lttng-ust-agent-log4j2.jar". All of these jars
35depend on a third "lttng-ust-agent-common.jar", which will always be built.
36
37All these archives will be installed in the arch-agnostic "$prefix/share/java"
38path, e.g: "/usr/share/java". You need to make sure the .jar for the logging
39API you want to use (either "lttng-ust-agent-jul.jar",
40"lttng-ust-agent-log4j.jar" or "lttng-ust-agent-log4j2.jar") is on your
41application's classpath.
42
43The logging libraries require an architecture-specific shared object,
44"liblttng-ust-jul-jni.so" for JUL and "liblttng-ust-jul-log4j.so" for both
45Log4j 1.x and 2.x, which are installed by the build system when doing "make
46install". Make sure that your Java application can find this shared object, by
47using the "java.library.path" property if necessary.
48
49In order to use UST tracing in your Java application, you simply need to
50instantiate a LttngLogHandler or a LttngLogAppender (for JUL or Log4j,
51respectively), then attach it to a JUL or Log4j Logger class.
52
53Refer to the code examples in "examples/java-jul/", "examples/java-log4j/" and
54"examples/java-log4j2-*/".
55
56LTTng session daemon agents will be initialized as needed. If no session daemon
57is available, the execution will continue and the agents will retry connecting
58every 3 seconds.
59
60
61==============
62 Object model
63==============
64
65The object model of the Java agent implementation is as follows:
66
67---------
68Ownership
69---------
70Log Handlers: LttngLogHandler, LttngLogAppender
71 n handlers/appenders, managed by the application.
72 Can be created programmatically, or via a configuration file,
73 Each one registers to a specific agent singleton (one per logging API) that is loaded on-demand
74
75Agent singletons: LttngJulAgent, LttngLog4jAgent
76 Keep track of all handlers/appenders registered to them.
77 Are disposed when last handler deregisters.
78 Each agent instantiates 2 TCP clients, one for the root session daemon, one for the user one.
79 One type of TCP client class for now. TCP client may become a singleton in the future.
80
81-------
82Control
83-------
84Messages come from the session daemon through the socket connection.
85Agent passes back-reference to itself to the TCP clients.
86Clients use this reference to invoke callbacks, which modify the state of the agent (enabling/disabling events, etc.)
87
88---------
89Data path
90---------
91Log messages are generated by the application and sent to the Logger objects,
92which then send them to the Handlers.
93
94When a log event is received by a Handler (publish(LogRecord)), the handler
95checks with the agent if it should log it or not, via
96ILttngAgent#isEventEnabled() for example.
97
98Events that are logged call the native tracepoint through JNI, which generates
99a UST event. There is one type of tracepoint per domain (Jul or Logj4).
100
101-----------------------
102Filtering notifications
103-----------------------
104FilterChangeNotifier is the singleton notifier class.
105Applications implement an IFilterChangeListener, and register it to the notifier.
106
107Whenever new event rules are enabled or disabled, the relevant agent informs the
108notifier, which then sends notifications to all registered listeners by invoking
109their callbacks.
110
111Upon registration, a new listener will receive notifications for all currently
112active rules.
113
114The notifier keeps track of its own event rule refcounting, to handle the case
115of multiple sessions or multiple agents enabling identical event rules.
116
117The FilterChangeNotifier does not have threads of its own. The listeners's
118callbacks will be invoked by these threads:
119* In the case of a notification being received while a listener is already
120 registered, the callback is executed by the TCP client's thread. This
121 effectively blocks the "lttng" command line until all callbacks are processed
122 (assuming no timeouts).
123* In the case of a listener registering and receiving the currently-active
124 rules, the callbacks will be executed by the application's thread doing the
125 registerListener() call.
126
127The notifier is entirely synchronized. This ensure that if a rule is enabled
128at the same time a listener is registered, that listener does not miss or
129receive duplicate notifications.
This page took 0.024566 seconds and 4 git commands to generate.