Skip to content

Commit b432db8

Browse files
committed
Support async-profiler 3.0, fix #20
1 parent b1265ec commit b432db8

File tree

5 files changed

+473
-195
lines changed

5 files changed

+473
-195
lines changed

README.md

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ Loader for AsyncProfiler
44
[![Maven Central](https://img.shields.io/maven-central/v/me.bechberger/ap-loader-all)](https://search.maven.org/search?q=ap-loader) [![GitHub](https://img.shields.io/github/license/jvm-profiling-tools/ap-loader)](https://github.com/jvm-profiling-tools/ap-loader/blob/main/LICENSE)
55

66
Packages [async-profiler](https://github.com/jvm-profiling-tools/async-profiler) releases in a JAR
7-
with an `AsyncProfilerLoader` (version 2.* and 1.8.*) that loads the suitable native library for the current platform.
7+
with an `AsyncProfilerLoader` (version 3.*, 2.* and 1.8.*)
8+
that loads the suitable native library for the current platform.
9+
10+
*In 3.* it also includes the latest [jattach](https://github.com/apangin/jattach) binary. This was previously
11+
part of async-profiler.*
812

913
This is usable as a Java agent (same arguments as the async-profiler agent) and as the basis for other libraries.
1014
The real rationale behind this library is that the async-profiler is a nice tool, but it cannot be easily integrated
@@ -46,11 +50,11 @@ from maven central, e.g:
4650
<dependency>
4751
<groupId>me.bechberger</groupId>
4852
<artifactId>ap-loader-all</artifactId>
49-
<version>2.9-7</version>
53+
<version>3.0-8</version>
5054
</dependency>
5155
```
5256

53-
Others are of course available, see [maven central](https://central.sonatype.com/artifact/me.bechberger/ap-loader-all/2.9-7).
57+
Others are of course available, see [maven central](https://central.sonatype.com/artifact/me.bechberger/ap-loader-all/3.0-8).
5458

5559
You can also use [JBang](https://jbang.dev) to simplify the usage of ap-loader. There are examples in documentation below.
5660

@@ -230,7 +234,7 @@ The latest `all` version can be added via:
230234
<dependency>
231235
<groupId>me.bechberger</groupId>
232236
<artifactId>ap-loader-all</artifactId>
233-
<version>2.9-7</version>
237+
<version>3.0-8</version>
234238
</dependency>
235239
```
236240
@@ -244,16 +248,16 @@ It requires a platform supported by async-profiler and Python 3.6+.
244248
245249
```sh
246250
# download the release sources and binaries
247-
python3 ./bin/releaser.py download 2.9
251+
python3 ./bin/releaser.py download 3.0
248252

249253
# build the JAR for the release
250254
# maven might throw warnings, related to the project version setting,
251255
# but the alternative solutions don't work, so we ignore the warning for now
252-
mvn -Dproject.vversion=2.9 -Dproject.subrelease=7 -Dproject.platform=macos package assembly:single
256+
mvn -Dproject.vversion=3.0 -Dproject.subrelease=7 -Dproject.platform=macos package assembly:single
253257
# use it
254-
java -jar target/ap-loader-macos-2.9-7-full.jar ...
258+
java -jar target/ap-loader-macos-3.0-8-full.jar ...
255259
# build the all JAR
256-
mvn -Dproject.vversion=2.9 -Dproject.subrelease=7 -Dproject.platform=all package assembly:single
260+
mvn -Dproject.vversion=3.0 -Dproject.subrelease=7 -Dproject.platform=all package assembly:single
257261
```
258262
259263
Development
@@ -298,6 +302,14 @@ And the following for a new async-profiler release:
298302
Changelog
299303
---------
300304
305+
### v8
306+
307+
- Support for [async-profiler 3.0](https://github.com/async-profiler/async-profiler/releases/tag/v3.0)
308+
- Breaking changes with async-profiler 3.0:
309+
- async-profiler 3.0 changed the meaning of the `--lib` option from `--lib path full path to libasyncProfiler.so in the container`
310+
to `-l, --lib prepend library names`, so the `AsyncProfilerLoader` will throw an UnsupportedOperation exception
311+
when using the `--lib` option with a path argument and async-profiler 3.0 or higher
312+
301313
### v7
302314
303315
- Drop dev.dirs:directories dependency #13 (thanks to @jsjant for spotting the potential licensing issue and fixing it in #14)

bin/copy_all_libs.sh

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,5 @@ for f in ap-releases/async-profiler-$version-*; do
1818
# extract the platform suffix
1919
platform=$(echo "$f" | cut -d '-' -f 5-10)
2020
# copy the library
21-
echo "Copying $f/build/libasyncProfiler.so for platform $platform"
22-
cp "$f/build/libasyncProfiler.so" "target/classes/libs/libasyncProfiler-$version-$platform.so"
23-
echo "Copying $f/build/jattach for platform $platform"
24-
cp "$f/build/jattach" "target/classes/libs/jattach-$version-$platform"
25-
done
26-
first_folder=$(echo ap-releases/async-profiler-$version-linux* | cut -d " " -f 1)
27-
# copy the profile.sh
28-
echo "Copy $first_folder/profiler.sh"
29-
cp "$first_folder/profiler.sh" "target/classes/libs/profiler-$version.sh"
30-
python3 "$OWN_DIR/profile_processor.py" "target/classes/libs/profiler-$version.sh"
31-
32-
python3 "$OWN_DIR/timestamp.py" > "target/classes/libs/ap-timestamp-$version"
33-
echo "$version" > target/classes/libs/ap-version
34-
35-
echo "Copy Java sources"
36-
python3 "$OWN_DIR/copy_java_sources.py" "$BASEDIR" "$VERSION_PLATFORM"
21+
$OWN_DIR/copy_libs.sh "$1" "$version-$platform" no-clean
22+
done

bin/copy_libs.sh

Lines changed: 58 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#! /bin/sh
2-
# ./copy_libs.sh <base_dir> <artifact version, like 2.8.3-macos>
2+
# ./copy_libs.sh <base_dir> <artifact version, like 2.8.3-macos> [no-clean]
33

44
set -e
55

@@ -11,20 +11,65 @@ OWN_DIR=$(dirname "$0")
1111
cd "$BASEDIR" || exit 1
1212

1313
version=$(echo "$2" | cut -d '-' -f 1)
14-
rm -fr target/classes/libs
14+
major_version=$(echo "$version" | cut -d '.' -f 1)
15+
minor_version=$(echo "$version" | cut -d '.' -f 2)
16+
if [ -z "$3" ]; then
17+
rm -fr target/classes/libs
18+
fi
1519
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"
2020

21-
python3 "$OWN_DIR/timestamp.py" > "target/classes/libs/ap-timestamp-$version"
22-
echo "$version" > target/classes/libs/ap-version
21+
# if version is smaller than 2.10:
22+
if ([ "$major_version" -le 2 ] && [ "$minor_version" -lt 10 ]); then
23+
echo "Copy $AP_RELEASE/build/libasyncProfiler.so"
24+
cp "$AP_RELEASE/build/libasyncProfiler.so" \
25+
"target/classes/libs/libasyncProfiler-$VERSION_PLATFORM.so"
26+
cp "$AP_RELEASE/build/jattach" \
27+
"target/classes/libs/jattach-$VERSION_PLATFORM"
2328

24-
echo "Copy $AP_RELEASE/profiler.sh"
25-
cp "$AP_RELEASE/profiler.sh" "target/classes/libs/profiler-$version.sh"
26-
python3 "$OWN_DIR/profile_processor.py" "target/classes/libs/profiler-$version.sh"
29+
cp "$AP_RELEASE/build/libasyncProfiler.so" \
30+
"target/classes/libs/libasyncProfiler-$VERSION_PLATFORM.so"
2731

28-
echo "Copy Java sources"
29-
python3 "$OWN_DIR/copy_java_sources.py" "$BASEDIR" "$VERSION_PLATFORM"
32+
echo "libasyncProfiler-$VERSION_PLATFORM.so" > target/classes/libs/ap-profile-lib-$VERSION_PLATFORM
3033

34+
cp "$AP_RELEASE/build/jattach" \
35+
"target/classes/libs/jattach-$VERSION_PLATFORM"
36+
37+
python3 "$OWN_DIR/timestamp.py" > "target/classes/libs/ap-timestamp-$version"
38+
echo "$version" > target/classes/libs/ap-version
39+
40+
echo "Copy $AP_RELEASE/profiler.sh"
41+
cp "$AP_RELEASE/profiler.sh" "target/classes/libs/profiler-$version.sh"
42+
python3 "$OWN_DIR/profile_processor.py" "target/classes/libs/profiler-$version.sh"
43+
44+
echo "profiler-$version.sh" > target/classes/libs/ap-profile-script-$VERSION_PLATFORM
45+
46+
echo "Copy Java sources"
47+
python3 "$OWN_DIR/copy_java_sources.py" "$BASEDIR" "$VERSION_PLATFORM"
48+
49+
else
50+
# test endings ".so" and ".dylib" in a loop
51+
for ending in "so" "dylib"; do
52+
# if the file exists, copy it
53+
if [ -f "$AP_RELEASE/lib/libasyncProfiler.$ending" ]; then
54+
echo "Copy $AP_RELEASE/lib/libasyncProfiler.$ending"
55+
cp "$AP_RELEASE/lib/libasyncProfiler.$ending" \
56+
"target/classes/libs/libasyncProfiler-$VERSION_PLATFORM.$ending"
57+
echo "libasyncProfiler-$VERSION_PLATFORM.$ending" > target/classes/libs/ap-profile-lib-$VERSION_PLATFORM
58+
fi
59+
done
60+
61+
cp "$AP_RELEASE/build/jattach" \
62+
"target/classes/libs/jattach-$VERSION_PLATFORM"
63+
64+
python3 "$OWN_DIR/timestamp.py" > "target/classes/libs/ap-timestamp-$version"
65+
echo "$version" > target/classes/libs/ap-version
66+
67+
echo "Copy $AP_RELEASE/bin/asprof"
68+
cp "$AP_RELEASE/bin/asprof" "target/classes/libs/asprof-$VERSION_PLATFORM"
69+
70+
echo "asprof-$VERSION_PLATFORM" > target/classes/libs/ap-profile-script-$VERSION_PLATFORM
71+
72+
echo "Copy Java sources"
73+
python3 "$OWN_DIR/copy_java_sources.py" "$BASEDIR" "$VERSION_PLATFORM"
74+
75+
fi

0 commit comments

Comments
 (0)