You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+29-7
Original file line number
Diff line number
Diff line change
@@ -6,10 +6,12 @@ Loader for AsyncProfiler
6
6
Packages [async-profiler](https://github.com/jvm-profiling-tools/async-profiler) releases in a JAR
7
7
with an `AsyncProfilerLoader` (version 2.* and 1.8.*) that loads the suitable native library for the current platform.
8
8
9
-
This is usable as a java agent (same arguments as the async-profiler agent) and as the basis for other libraries.
9
+
This is usable as a Java agent (same arguments as the async-profiler agent) and as the basis for other libraries.
10
10
The real rationale behind this library is that the async-profiler is a nice tool, but it cannot be easily integrated
11
11
into other Java-based tools.
12
12
13
+
The `AsyncProfilerLoader` API integrates async-profiler and jattach with a user-friendly interface (see below).
14
+
13
15
The wrapper is tested against all relevant tests of the async-profiler tool, ensuring that it has the same behavior.
14
16
15
17
Take the [`all` build](https://github.com/jvm-profiling-tools/ap-loader/releases/latest/download/ap-loader-all.jar) and you have a JAR that provides the important features of async-profiler on all supported
@@ -42,7 +44,7 @@ Or you can depend on the artifacts from maven central, they should be slightly m
42
44
<dependency>
43
45
<groupId>me.bechberger</groupId>
44
46
<artifactId>ap-loader-all</artifactId>
45
-
<version>2.9-4</version>
47
+
<version>2.9-5</version>
46
48
</dependency>
47
49
```
48
50
@@ -197,6 +199,19 @@ The API of the `AsyncProfilerLoader` can be used to execute all commands of the
197
199
198
200
The converters reside in the `one.converter` package.
199
201
202
+
Attaching a Custom Agent Programmatically
203
+
---------------------------------
204
+
A notable part of the API are the jattach related methods that allow you to call `jattach` to attach
205
+
your own native library to the currently running JVM:
206
+
207
+
```java
208
+
// extract the agent first from the resources
209
+
Path p = one.profiler.AsyncProfilerLoader.extractCustomLibraryFromResources(....getClassLoader(), "library name");
thrownewIOException("Could not find library " + fileName + " in resources");
349
+
}
350
+
if (!alternativeSource.toFile().isDirectory()) {
351
+
thrownewIOException("Could not find library " + fileName + " in resources and alternative source " + alternativeSource + " is not a directory");
352
+
}
353
+
if (alternativeSource.resolve(realFilePath).toFile().exists()) {
354
+
returnalternativeSource.resolve(realFilePath);
355
+
}
356
+
thrownewIOException("Could not find library " + fileName + " in resources and alternative source " + alternativeSource + " does not contain " + realFilePath);
0 commit comments