|
1 | | -# Java Performance Agent – Introduction |
| 1 | +# Java Performance Agent |
2 | 2 |
|
3 | | -## Overview |
| 3 | +## Introduction |
| 4 | +Java Performance Agent is a lightweight, pluggable Java agent designed to monitor, trace, and analyze the performance of Java applications in real time. It provides actionable insights into method execution times, call stacks, and resource usage, helping to identify bottlenecks and optimize application performance. |
4 | 5 |
|
5 | | -Java Performance Agent is a lightweight, pluggable Java agent designed to monitor, trace, and analyze the performance of Java applications in real time. It provides developers and operators with actionable insights into method execution times, call stacks, and resource usage, helping to identify bottlenecks and optimize application performance. |
| 6 | +## Overview |
| 7 | +Enables real-time performance monitoring and tracing for Java applications, helping to identify bottlenecks and optimize code execution. |
6 | 8 |
|
7 | 9 | ## Architecture |
8 | | - |
9 | | -The agent consists of several key components: |
10 | 10 | - **AgentEntrypoint & AgentInitializer**: Bootstrap and configure the agent at JVM startup. |
11 | 11 | - **AgentStarter & AgentStarterImpl**: Manage the lifecycle and instrumentation logic. |
12 | 12 | - **PerformanceTracer & TimerContext**: Collect and aggregate timing data for instrumented methods. |
13 | | -- **Instrumentation via ByteBuddy**: The agent uses ByteBuddy to dynamically instrument classes and methods at runtime, enabling precise and flexible performance tracing without modifying application code. |
| 13 | +- **Instrumentation via ByteBuddy**: Uses ByteBuddy to dynamically instrument classes and methods at runtime, enabling precise and flexible performance tracing without modifying application code. |
14 | 14 | - **ManagementHttpServer**: Embedded HTTP server exposing REST APIs and a web interface for trace management and visualization. |
15 | 15 | - **Handlers (GetTrace, GetTraces, DeleteTrace, StopTrace, etc.)**: REST endpoints for trace operations (start, stop, list, download, delete). |
16 | 16 | - **StaticResourceHandler**: Serves the web UI (HTML, CSS, JS) for interactive trace exploration. |
17 | 17 | - **File Writers & Utilities**: Serialize, compress, and store trace data efficiently. |
18 | 18 |
|
19 | | -## How It Works |
| 19 | +## Requirements |
| 20 | +- Java 17+ (compatible with modern JVMs) |
| 21 | +- Works with Tomcat, WildFly, and other servlet containers |
| 22 | +- No code changes required in the target application |
20 | 23 |
|
21 | | -1. **Startup**: The agent is attached to the JVM (via `-javaagent`), initializing its configuration and HTTP server. |
22 | | -2. **Instrumentation**: Classes and methods are instrumented based on filters and configuration, enabling precise timing and call tracking. |
23 | | -3. **Trace Collection**: When a trace is started (via API or UI), the agent records method execution data and call stacks. |
24 | | -4. **Trace Management**: Traces can be listed, downloaded, deleted, or stopped via REST API or the web interface. |
25 | | -5. **Analysis**: Collected traces are available for download and analysis, helping to pinpoint performance issues. |
| 24 | +## Third-party Libraries & Docker Images |
| 25 | +This project uses [ByteBuddy](https://bytebuddy.net/) for runtime instrumentation of Java classes and methods. |
| 26 | +- ByteBuddy is licensed under the Apache License, Version 2.0. [License](https://www.apache.org/licenses/LICENSE-2.0) |
| 27 | +- By using ByteBuddy, this project complies with the terms of the Apache License 2.0, including attribution and license notice. |
26 | 28 |
|
27 | | -## Usage & Integration |
| 29 | +This project uses official Docker images for: |
| 30 | +- [Apache Tomcat](https://hub.docker.com/_/tomcat) (Apache License 2.0) [License](https://www.apache.org/licenses/LICENSE-2.0) |
| 31 | +- [Wildfly](https://hub.docker.com/r/jboss/wildfly) (LGPL v2.1) [License](https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html) |
| 32 | + |
| 33 | +By using these images, you accept the terms of their respective licenses. |
28 | 34 |
|
| 35 | +## Usage & Integration |
29 | 36 | - **Attach to JVM**: Add the agent JAR to your JVM startup parameters: |
30 | 37 | ```sh |
31 | | - -javaagent:/path/to/performance-agent.jar |
| 38 | + -javaagent:/path/to/performance-agent.jar -Dcmdev.profiler.filters.path=/path/to/filters.properties |
32 | 39 | ``` |
33 | 40 | - **Configure Filters**: Use `filters.properties` to specify which classes/methods to instrument. |
34 | 41 | - **Access Web UI**: Open the embedded HTTP server (default port 8090) to interact with traces and view results. |
35 | 42 | - **API Endpoints**: The REST endpoints are primarily called by the web UI for trace management and visualization, but are also available for automation and integration with CI/CD or monitoring tools. |
36 | 43 |
|
| 44 | +## How It Works |
| 45 | +1. **Startup**: The agent is attached to the JVM (via `-javaagent`), initializing its configuration and HTTP server. |
| 46 | +2. **Instrumentation**: Classes and methods are instrumented based on filters and configuration, enabling precise timing and call tracking. |
| 47 | +3. **Trace Collection**: When a trace is started (via API or UI), the agent records method execution data and call stacks. |
| 48 | +4. **Trace Management**: Traces can be listed, downloaded, deleted, or stopped via REST API or the web interface. |
| 49 | +5. **Analysis**: Collected traces are available for download and analysis, helping to pinpoint performance issues. |
| 50 | + |
37 | 51 | ## Example REST Endpoints |
38 | 52 | - `GET /traces` – List available traces |
39 | 53 | - `POST /trace/start` – Start a new trace |
40 | 54 | - `POST /trace/stop` – Stop the current trace |
41 | 55 | - `GET /trace/{id}` – Download a trace file |
42 | 56 | - `DELETE /trace/{id}` – Delete a trace |
43 | 57 |
|
44 | | -## Requirements |
45 | | -- Java 17+ (compatible with modern JVMs) |
46 | | -- Works with Tomcat, WildFly, and other servlet containers |
47 | | -- No code changes required in the target application |
48 | | - |
49 | 58 | ## Quick Start |
50 | 59 | 1. Build the agent and your target application. |
51 | 60 | 2. Start your application with the agent attached. |
52 | 61 | 3. Access the web UI or use the REST API to manage and analyze traces. |
53 | 62 |
|
| 63 | +## How to Start |
| 64 | +To run and test the Performance Agent with Tomcat or Wildfly, follow these steps: |
| 65 | + |
| 66 | +### Tomcat 10.0 jdk17 |
| 67 | +```bash |
| 68 | +export MSYS_NO_PATHCONV=1 |
| 69 | +JAVA_TOOL_OPTIONS="-XX:-UseContainerSupport -javaagent:/usr/local/tomcat/performance-agent.jar -Dcmdev.profiler.filters.path=/usr/local/tomcat/filters.properties" |
| 70 | +mvn -q clean install |
| 71 | +rootDir=$PWD |
| 72 | +pushd test-app |
| 73 | +mvn -q clean install |
| 74 | +docker build -t test-app-tomcat -f Dockerfile-Tomcat9jdk17 . |
| 75 | +docker run -p 8080:8080 -p 8090:8090 -p 8787:8787 \ |
| 76 | + -e JAVA_TOOL_OPTIONS="${JAVA_TOOL_OPTIONS}" \ |
| 77 | + -v $rootDir/test-app/filters.properties:/usr/local/tomcat/filters.properties \ |
| 78 | + -v $rootDir/target/performance-agent.jar:/usr/local/tomcat/performance-agent.jar \ |
| 79 | + -v $rootDir/test-app/traces:/tmp/traces \ |
| 80 | + test-app-tomcat |
| 81 | +popd |
| 82 | +``` |
| 83 | + |
| 84 | +### Wildfly 28.0.0.Final-jdk17 |
| 85 | +```bash |
| 86 | +export MSYS_NO_PATHCONV=1 |
| 87 | +JAVA_TOOL_OPTIONS=" -javaagent:/opt/jboss/wildfly/performance-agent.jar -Dcmdev.profiler.filters.path=/opt/jboss/wildfly/filters.properties" |
| 88 | +mvn -q clean install |
| 89 | +rootDir=$PWD |
| 90 | +pushd test-app |
| 91 | +mvn -q clean install |
| 92 | +docker build -t test-app-wildfly -f Dockerfile-Wildfly . |
| 93 | +docker run -p 8080:8080 -p 8090:8090 -p 8787:8787 \ |
| 94 | + -e JAVA_OPTS="${JAVA_TOOL_OPTIONS}" \ |
| 95 | + -v $rootDir/test-app/filters.properties:/opt/jboss/wildfly/filters.properties \ |
| 96 | + -v $rootDir/target/performance-agent.jar:/opt/jboss/wildfly/performance-agent.jar \ |
| 97 | + -v $rootDir/test-app/traces:/tmp/traces \ |
| 98 | + test-app-wildfly |
| 99 | +popd |
| 100 | +``` |
| 101 | + |
54 | 102 | ## License & Contributions |
55 | 103 | Open source project – contributions and feedback are welcome! |
56 | | - |
57 | | -## Third-party libraries |
58 | | - |
59 | | -This project uses [ByteBuddy](https://bytebuddy.net/) for runtime instrumentation of Java classes and methods. |
60 | | - |
61 | | -ByteBuddy is licensed under the Apache License, Version 2.0. You can find the full license text at: https://www.apache.org/licenses/LICENSE-2.0 |
62 | | - |
63 | | -By using ByteBuddy, this project complies with the terms of the Apache License 2.0, including attribution and license notice. |
|
0 commit comments