Skip to content

Commit 62ebfb6

Browse files
committed
Fix too many issues to name them all
1 parent 8092d87 commit 62ebfb6

File tree

9 files changed

+702
-298
lines changed

9 files changed

+702
-298
lines changed

README.md

+56-19
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,24 @@ Loader for AsyncProfiler
22
========================
33

44
Packages [async-profiler](https://github.com/jvm-profiling-tools/async-profiler) releases in a JAR
5-
with a `AsyncProfilerLoader` that loads the suitable native library for the current platform.
5+
with a `AsyncProfilerLoader` (version 2+) that loads the suitable native library for the current platform.
66

77
This is usable as a java agent (same arguments as the async-profiler agent) and as the basis for other libraries.
88
The real rationale behind this library is that the async-profiler is a nice tool, but it cannot be easily integrated
99
into other Java based tools.
1010

11-
Take the `all` build and you have a JAR that provides the important features of async-profiler on all supported platforms:
11+
The wrapper is tested against all relevant tests of the async-profiler tool, ensuring that it has the same behavior.
12+
13+
Take the `all` build and you have a JAR that provides the important features of async-profiler on all supported
14+
platforms.
1215

1316
A changelog can be found at the async-profiler repository, as this library should rarely change itself.
1417

18+
_This project assumes that you used async-profiler before, if not, don't worry, you can still use this project,
19+
but be aware that it's documentation refers you to the async-profiler documentation a lot._
20+
21+
_fdtransfer is currently not supported, feel free to create an issue if you need it._
22+
1523
Supported Platforms
1624
-------------------
1725

@@ -30,27 +38,29 @@ Commands
3038

3139
The following is a more in-depth description of the commands of `java -jar ap-loader.jar`.
3240

33-
Be aware that it is recommended to use run the JVM with the
34-
`-XX:+UnlockDiagnosticVMOptions -XX:+DebugNonSafepoints` flags when attaching to a running JVM.
41+
Be aware that it is recommended to use run the JVM with the
42+
`-XX:+UnlockDiagnosticVMOptions -XX:+DebugNonSafepoints` flags.
3543
This improves the accuracy of the profiler.
3644

3745
Overview over the commands:
3846

3947
```sh
4048
Usage: java -jar ap-loader.jar <command> [args]
4149
Commands:
42-
help show this help
43-
jattach run the included jattach binary
44-
profiler run the included profiler.sh
45-
supported fails if this JAR does not include a profiler for the current OS and architecture
46-
converter run the included converter JAR
47-
version version of the included async-profiler
48-
clear clear the directory used for storing extracted files
50+
help show this help
51+
jattach run the included jattach binary
52+
profiler run the included profiler.sh
53+
agentpath prints the path of the extracted async-profiler agent
54+
jattachpath prints the path of the extracted jattach binary
55+
supported fails if this JAR does not include a profiler for the current OS and architecture
56+
converter run the included converter JAR
57+
version version of the included async-profiler
58+
clear clear the directory used for storing extracted files
4959
```
5060
5161
### jattach
5262
53-
`java -jar ap-loader.jar jattach` is equivalent to calling the suitable `jattach` binary
63+
`java -jar ap-loader.jar jattach` is equivalent to calling the suitable `jattach` binary
5464
from [GitHub](https://github.com/apangin/jattach)>:
5565
5666
```sh
@@ -67,6 +77,7 @@ java -jar ap-loader.jar jattach <pid> jcmd "help -all"
6777
See the [GitHub page of jattach](https://github.com/apangin/jattach) for more details.
6878
6979
### profiler
80+
7081
`java -jar ap-loader.jar profiler` is equivalent to calling the suitable `profiler.sh`:
7182
7283
```sh
@@ -97,7 +108,7 @@ java -jar ap-loader.jar converter jfr2flame <input.jfr> <output.html>
97108
98109
The available converters depend on the included async-profiler version.
99110
Call `java -jar converter` to a list of available converters, see
100-
[the source code on GitHub](https://github.com/jvm-profiling-tools/async-profiler/blob/master/src/converter/Main.java)
111+
[the source code on GitHub](https://github.com/jvm-profiling-tools/async-profiler/blob/master/src/converter/Main.java)
101112
for more details.
102113
103114
### clear
@@ -127,18 +138,21 @@ Using in Java code
127138
Then you can use the `AsyncProfilerLoader` class to load the native library:
128139
129140
```java
130-
AsyncProfiler profiler + one.profiler.AsyncProfilerLoader.load();
141+
AsyncProfiler profiler = one.profiler.AsyncProfilerLoader.load();
131142
```
132143
133-
`AsyncProfiler` is the [main API class](https://github.com/jvm-profiling-tools/async-profiler/blob/master/src/api/one/profiler/AsyncProfiler.java)
144+
`AsyncProfiler` is
145+
the [main API class](https://github.com/jvm-profiling-tools/async-profiler/blob/master/src/api/one/profiler/AsyncProfiler.java)
134146
from the async-profiler.jar.
135147
136148
The API of the `AsyncProfilerLoader` can be used to execute all commands the CLI programmatically.
137149
138150
### Snapsshots
151+
139152
We currently only release to snapshop, as the API is not stable yet.
140153
141154
```xml
155+
142156
<dependency>
143157
<groupId>me.bechberger</groupId>
144158
<artifactId>ap-loader</artifactId>
@@ -147,7 +161,9 @@ We currently only release to snapshop, as the API is not stable yet.
147161
```
148162
149163
For example for the all variant of version 2.8.3:
164+
150165
```xml
166+
151167
<dependency>
152168
<groupId>me.bechberger</groupId>
153169
<artifactId>ap-loader</artifactId>
@@ -156,7 +172,9 @@ For example for the all variant of version 2.8.3:
156172
```
157173
158174
You also have to add the snapshot repository:
175+
159176
```xml
177+
160178
<repositories>
161179
<repository>
162180
<id>snapshots</id>
@@ -171,7 +189,6 @@ You also have to add the snapshot repository:
171189
</repositories>
172190
```
173191
174-
175192
Build and test
176193
--------------
177194
@@ -187,21 +204,41 @@ unzip -o async-profiler-2.8.3-macos.zip -d ap-releases
187204
# build the JAR for the release
188205
# maven might throw warnings, related to the project version setting,
189206
# but the alternative solutions don't work, so we ignore the warning for now
190-
mvn -Dproject.versionPlatform=2.8.3-macos assembly:single
207+
mvn -Dproject.versionPlatform=2.8.3-macos package assembly:single
191208
# use it
192209
java -jar target/ap-loader-2.8.3-macos-full.jar ...
193210
# build the all JAR
194-
mvn -Dproject.versionPlatform=2.8.3-all -f pom_all.xml assembly:single
211+
mvn -Dproject.versionPlatform=2.8.3-all -f pom_all.xml package assembly:single
195212
```
196213
197214
Development
198215
-----------
199216
This project is written in Java 8, to support all relevant platforms.
200-
The feature set should not increase beyond what is currently:
217+
The feature set should not increase beyond what is currently:
201218
Just build your library on top of it. But I'm of course happy for bug reports and fixes.
202219
203220
The code is formatted using [google-java-format](https://github.com/google/google-java-format).
204221
222+
### bin/releaser.py
223+
224+
```sh
225+
Usage:
226+
python3 ./bin/releaser.py <command> ... <command> [release or current if not present]
227+
228+
Commands:
229+
current_version print the youngest released version of async-profiler
230+
versions print all released versions of async-profiler (supported by this project)
231+
download download and prepare the folders for the given release
232+
build build the wrappers for the given release
233+
test test the given release
234+
deploy deploy the wrappers for the given release, i.e., use "mvn deploy"
235+
clear clear the ap-releases and target folders for a fresh start
236+
237+
Environment variables:
238+
JAVA_VERSIONS comma-separated list of Java versions to test with
239+
(in the form of sdkman! version names, e.g. 17.0.1-sapmchn)
240+
```
241+
205242
License
206243
-------
207244
Apache 2.0

bin/copy_all_libs.sh

100644100755
+14-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
#! /bin/sh
2-
# ./copy_all_libs.sh <base_dir> <artifact version, like 2.8.3-all
2+
# ./copy_all_libs.sh <base_dir> <artifact version, like 2.8.3-all>
33

44
set -e
55

6+
OWN_DIR=$(dirname "$0")
7+
68
# extract the version without the platform suffix
79
version=$(echo "$2" | cut -d '-' -f 1)
810
echo "version: $version"
911
cd "$1" || exit 1
12+
rm -fr target/classes/libs
1013
mkdir -p target/classes/libs
1114
for f in ap-releases/async-profiler-$version-*; do
1215
if (echo "$f" | grep 'code' || echo "$f" | grep ".tar.gz" || echo "$f" | grep ".zip"); then
@@ -16,17 +19,19 @@ for f in ap-releases/async-profiler-$version-*; do
1619
platform=$(echo "$f" | cut -d '-' -f 5-10)
1720
# copy the library
1821
echo "Copying $f/build/libasyncProfiler.so for platform $platform"
19-
cp "$f/build/libasyncProfiler.so" "target/classes/libs/libasyncProfiler-$platform.so"
22+
cp "$f/build/libasyncProfiler.so" "target/classes/libs/libasyncProfiler-$version-$platform.so"
2023
echo "Copying $f/build/jattach for platform $platform"
21-
cp "$f/build/jattach" "target/classes/libs/jattach-$platform"
22-
echo "Copying $f/profiler.sh for platform $platform"
23-
cp "$f/profiler.sh" "target/classes/libs/profiler-$platform.sh"
24+
cp "$f/build/jattach" "target/classes/libs/jattach-$version-$platform"
2425
done
2526
first_folder=$(echo ap-releases/async-profiler-$version-linux* | cut -d " " -f 1)
26-
# copy the converter
27+
# copy the converter and profile.sh
2728
echo "Copy $first_folder/build/converter.jar"
28-
cp "$first_folder/build/converter.jar" "target/classes/libs/converter.jar"
29+
cp "$first_folder/build/converter.jar" "target/classes/libs/converter-$version.jar"
30+
echo "Copy $first_folder/profiler.sh"
31+
cp "$first_folder/profiler.sh" "target/classes/libs/profiler-$version.sh"
32+
python3 "$OWN_DIR/profile_processor.py" "target/classes/libs/profiler-$version.sh"
2933
# extract the async-profiler JAR
3034
echo "Extracting $first_folder/build/async-profiler.jar"
31-
ls target/classes/libs >target/classes/libs/index
32-
unzip -o $first_folder/build/async-profiler* "*.class" -d target/classes
35+
python3 "$OWN_DIR/timestamp.py" > "target/classes/libs/ap-timestamp-$version"
36+
echo "$version" > target/classes/libs/ap-version
37+
unzip -o "$first_folder/build/async-profiler*" "*.class" -d "target/classes"

bin/copy_libs.sh

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#! /bin/sh
2+
# ./copy_libs.sh <base_dir> <artifact version, like 2.8.3-macos>
3+
4+
set -e
5+
6+
BASEDIR="$1"
7+
VERSION_PLATFORM=$2
8+
AP_RELEASE="ap-releases/async-profiler-$VERSION_PLATFORM"
9+
OWN_DIR=$(dirname "$0")
10+
11+
cd "$BASEDIR" || exit 1
12+
13+
version=$(echo "$2" | cut -d '-' -f 1)
14+
rm -fr target/classes/libs
15+
mkdir -p target/classes/libs
16+
cp "$AP_RELEASE/build/libasyncProfiler.so" \
17+
"target/classes/libs/libasyncProfiler-$VERSION_PLATFORM.so"
18+
cp "$AP_RELEASE/build/jattach" \
19+
"target/classes/libs/jattach-$VERSION_PLATFORM"
20+
21+
python3 "$OWN_DIR/timestamp.py" > "target/classes/libs/ap-timestamp-$version"
22+
echo "$version" > target/classes/libs/ap-version
23+
24+
echo "Copy $AP_RELEASE/build/converter.jar"
25+
cp "$AP_RELEASE/build/converter.jar" "target/classes/libs/converter-$version.jar"
26+
echo "Copy $AP_RELEASE/profiler.sh"
27+
cp "$AP_RELEASE/profiler.sh" "target/classes/libs/profiler-$version.sh"
28+
python3 "$OWN_DIR/profile_processor.py" "target/classes/libs/profiler-$version.sh"
29+
echo "Extracting $AP_RELEASE/build/async-profiler.jar"
30+
unzip -o "ap-releases/async-profiler-$VERSION_PLATFORM/build/async-profiler.jar" \
31+
"*.class" -d "target/classes"

bin/profile_processor.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/python3
2+
"""
3+
./profile_processor.py FILE
4+
"""
5+
6+
import sys
7+
8+
with open(sys.argv[1], "r") as f:
9+
content = f.read()
10+
content = content.replace("JATTACH=$SCRIPT_DIR/build/jattach", "").replace("PROFILER=$SCRIPT_DIR/build/libasyncProfiler.so", "")
11+
with open(sys.argv[1], "w") as f:
12+
f.write(content)

0 commit comments

Comments
 (0)