Skip to content

Commit 71c0c4f

Browse files
committed
Better deployment
1 parent 62ebfb6 commit 71c0c4f

File tree

6 files changed

+282
-32
lines changed

6 files changed

+282
-32
lines changed

README.md

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,38 @@ 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` (version 2+) that loads the suitable native library for the current platform.
5+
with an `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
9-
into other Java based tools.
9+
into other Java-based tools.
1010

1111
The wrapper is tested against all relevant tests of the async-profiler tool, ensuring that it has the same behavior.
1212

13-
Take the `all` build and you have a JAR that provides the important features of async-profiler on all supported
13+
Take the [`all` build](https://github.com/parttimenerd/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
1414
platforms.
1515

16-
A changelog can be found at the async-profiler repository, as this library should rarely change itself.
16+
A changelog can be found in the async-profiler repository, as this library should rarely change itself.
1717

1818
_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._
19+
but be aware that its documentation refers you to the async-profiler documentation a lot._
2020

2121
_fdtransfer is currently not supported, feel free to create an issue if you need it._
2222

23+
Download
24+
--------
25+
26+
You can download the latest release from the
27+
[latest release page](https://github.com/parttimenerd/ap-loader/releases/latest/).
28+
As a shortcut, the wrapper for all platforms can be found
29+
[here](https://github.com/parttimenerd/ap-loader/releases/latest/download/ap-loader-all.jar).
30+
31+
It should be up to date with the latest async-profiler release, but if not, feel free to create an issue.
32+
33+
To use the library as a dependency, you can depend on `me.bechberger.ap-loader:<version>-<variant>-SNAPSHOT`
34+
from the [Sonatype OSS repository](https://s01.oss.sonatype.org/content/repositories/snapshots).
35+
See [#usage-in-java-code](Usage in Java Code) for more information.
36+
2337
Supported Platforms
2438
-------------------
2539

@@ -33,6 +47,8 @@ The JAR can be obtained in the following variants:
3347
- `macos`, `linux-x64`, ...: `jattach`, `profiler.sh` and `libasyncProfiler.so` for the given platform
3448
- `all`: all of the above
3549

50+
Regarding file sizes: The `all` variant are typically around 800KB and the individual variants around 200 to 400KB.
51+
3652
Commands
3753
--------
3854

@@ -42,7 +58,7 @@ Be aware that it is recommended to use run the JVM with the
4258
`-XX:+UnlockDiagnosticVMOptions -XX:+DebugNonSafepoints` flags.
4359
This improves the accuracy of the profiler.
4460

45-
Overview over the commands:
61+
Overview of the commands:
4662

4763
```sh
4864
Usage: java -jar ap-loader.jar <command> [args]
@@ -81,7 +97,7 @@ See the [GitHub page of jattach](https://github.com/apangin/jattach) for more de
8197
`java -jar ap-loader.jar profiler` is equivalent to calling the suitable `profiler.sh`:
8298
8399
```sh
84-
# Profile a process for a `n` seconds
100+
# Profile a process for `n` seconds
85101
java -jar ap-loader.jar profiler -d <n> <pid>
86102

87103
# Profile a process for allocation, CPU and lock events and save the results to a JFR file
@@ -122,17 +138,17 @@ Running as an agent
122138
-------------------
123139
124140
`java -javaagent:ap-loader.jar=<options>` is equivalent to `java -agentpath:libasyncProfiler.so=<options>`
125-
with the suitable library.
141+
with a suitable library.
126142
This can be used to profile a Java process from the start.
127143
128144
```sh
129-
# Profile the application and output a flamegraph
130-
java -javaagent:/path/to/libasyncProfiler.so=start,event=cpu,file=profile.html <java arguments>
145+
# Profile the application and output a flame graph
146+
java -javaagent:ap-loader.jar=start,event=cpu,file=profile.html <java arguments>
131147
```
132148
133149
See the [GitHub page of async-profiler](https://github.com/jvm-profiling-tools/async-profiler) for more details.
134150
135-
Using in Java code
151+
Usage in Java Code
136152
------------------
137153
138154
Then you can use the `AsyncProfilerLoader` class to load the native library:
@@ -145,25 +161,23 @@ AsyncProfiler profiler = one.profiler.AsyncProfilerLoader.load();
145161
the [main API class](https://github.com/jvm-profiling-tools/async-profiler/blob/master/src/api/one/profiler/AsyncProfiler.java)
146162
from the async-profiler.jar.
147163
148-
The API of the `AsyncProfilerLoader` can be used to execute all commands the CLI programmatically.
164+
The API of the `AsyncProfilerLoader` can be used to execute all commands of the CLI programmatically.
149165
150-
### Snapsshots
166+
### Snapshots
151167
152-
We currently only release to snapshop, as the API is not stable yet.
168+
We currently only release to snapshot, as the API is not stable yet.
153169
154170
```xml
155-
156171
<dependency>
157172
<groupId>me.bechberger</groupId>
158173
<artifactId>ap-loader</artifactId>
159174
<version>version-variant-SNAPSHOT</version>
160175
</dependency>
161176
```
162177
163-
For example for the all variant of version 2.8.3:
178+
For example for the `all` variant of version 2.8.3:
164179
165180
```xml
166-
167181
<dependency>
168182
<groupId>me.bechberger</groupId>
169183
<artifactId>ap-loader</artifactId>

bin/copy_java_file.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#! /bin/sh
2+
# ./copy_java_file.sh <base_dir> <artifact version, like 2.8.3-all>
3+
4+
set -e
5+
6+
OWN_DIR=$(dirname "$0")
7+
8+
# extract the version without the platform suffix
9+
version=$(echo "$2" | cut -d '-' -f 1)
10+
echo "version: $version"
11+
cd "$1" || exit 1
12+
13+
cp ap-releases/async-profiler-$version-code/src/api/one/profiler/*.java src/main/java/one/profiler

bin/releaser.py

Lines changed: 80 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
It has no dependencies, only requiring Python 3.6+ to be installed.
88
"""
99
import sys
10+
import tempfile
1011
import traceback
1112
import os
1213
import shutil
1314
import subprocess
15+
from pathlib import Path
1416
from urllib import request
1517
from typing import Any, Dict, List, Union, Tuple, Optional
1618
import json
@@ -26,7 +28,10 @@
2628
download download and prepare the folders for the given release
2729
build build the wrappers for the given release
2830
test test the given release
29-
deploy deploy the wrappers for the given release, i.e., use "mvn deploy"
31+
deploy_mvn deploy the wrappers for the given release as a snapshot to maven
32+
deploy_gh deploy the wrappers for the given release as a snapshot to GitHub
33+
deploy deploy the wrappers for the given release as a snapshot
34+
deploy_release deploy the wrappers for the given release
3035
clear clear the ap-releases and target folders for a fresh start
3136
3237
Environment variables:
@@ -282,6 +287,74 @@ def test_release(release: str):
282287
test_release_for_java(release)
283288

284289

290+
def deploy_maven_platform(release: str, platform: str, snapshot: bool):
291+
print(f"Deploy {release} for {platform} to maven")
292+
pom = "pom_all.xml" if platform == "all" else "pom.xml"
293+
cmd = f"mvn -Dproject.versionPlatform='{release}-{platform}' -Dproject.suffix='{'-SNAPSHOT' if snapshot else ''}' -f {pom} clean deploy"
294+
try:
295+
subprocess.check_call(cmd, shell=True, cwd=CURRENT_DIR, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
296+
except subprocess.CalledProcessError:
297+
os.system(
298+
f"cd {CURRENT_DIR}; {cmd}")
299+
raise
300+
301+
302+
def deploy_maven(release: str, snapshot: bool = True):
303+
print(f"Deploy {release}{' snapshot' if snapshot else ''}")
304+
for platform in get_release_platforms(release):
305+
deploy_maven_platform(release, platform, snapshot)
306+
deploy_maven_platform(release, "all", snapshot)
307+
308+
309+
def get_changelog(release: str) -> str:
310+
url = get_release(release)["html_url"]
311+
return f"_Copied from the wrapped [async-profiler release]({url}) by [Andrei Pangin](https://github.com/apangin). " \
312+
f"The source code linked below should be ignored._\n\n{get_release_info(release)}"
313+
314+
315+
def deploy_github(release: str):
316+
changelog = get_changelog(release)
317+
is_latest = release == get_most_recent_release()
318+
title = f"Loader for {release}: {get_release(release)['name']}"
319+
prerelease = get_release(release)["prerelease"]
320+
print(f"Deploy {release} ({title}) to GitHub")
321+
if not os.path.exists(f"{CURRENT_DIR}/releases/ap-loader-{release}-all.jar"):
322+
build_release(release)
323+
with tempfile.TemporaryDirectory() as d:
324+
changelog_file = f"{d}/CHANGELOG.md"
325+
with open(changelog_file, "w") as of:
326+
of.write(changelog)
327+
of.close()
328+
releases_dir = f"{CURRENT_DIR}/releases"
329+
platform_paths = []
330+
for platform in get_release_platforms(release) + ["all"]:
331+
path = f"{d}/ap-loader-{platform}.jar"
332+
shutil.copy(f"{releases_dir}/ap-loader-{release}-{platform}.jar", path)
333+
platform_paths.append(path)
334+
335+
flags_str = f"-F {changelog_file} -t '{title}' {'--latest' if is_latest else ''}" \
336+
f" {'--prerelease' if prerelease else ''}"
337+
paths_str = " ".join(f'"{p}"' for p in platform_paths)
338+
cmd = f"gh release create {release} {flags_str} {paths_str}"
339+
try:
340+
subprocess.check_call(cmd, shell=True, cwd=CURRENT_DIR, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
341+
except subprocess.CalledProcessError:
342+
# this is either a real problem or it means that the release already exists
343+
# in the latter case, we can just update it
344+
cmd = f"gh release edit {release} {flags_str}; gh release upload {release} {paths_str} --clobber"
345+
try:
346+
subprocess.check_call(cmd, shell=True, cwd=CURRENT_DIR, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
347+
except subprocess.CalledProcessError:
348+
os.system(
349+
f"cd {CURRENT_DIR}; {cmd}")
350+
351+
352+
353+
def deploy(release: str, snapshot: bool = True):
354+
deploy_maven(release, snapshot)
355+
deploy_github(release)
356+
357+
285358
def clear():
286359
shutil.rmtree(f"{CURRENT_DIR}/ap-releases", ignore_errors=True)
287360
shutil.rmtree(f"{CURRENT_DIR}/releases", ignore_errors=True)
@@ -291,8 +364,8 @@ def clear():
291364

292365

293366
def parse_cli_args() -> Tuple[List[str], Optional[str]]:
294-
available_commands = ["current_version", "versions", "download", "build", "test", "deploy",
295-
"deploy-release", "clear"]
367+
available_commands = ["current_version", "versions", "download", "build", "test", "deploy_mvn", "deploy_gh", "deploy",
368+
"deploy_release", "clear"]
296369
commands = []
297370
release = sys.argv[-1] if sys.argv[-1][0].isnumeric() else None
298371
for arg in sys.argv[1:(-1 if release else None)]:
@@ -316,6 +389,10 @@ def cli():
316389
"download": lambda: download_release(release),
317390
"build": lambda: build_release(release),
318391
"test": lambda: test_release(release),
392+
"deploy_mvn": lambda: deploy_maven(release),
393+
"deploy_gh": lambda: deploy_github(release),
394+
"deploy": lambda: deploy(release, snapshot=True),
395+
"deploy_release": lambda: deploy(release, snapshot=False),
319396
"clear": clear,
320397
}
321398
for command in commands:

pom.xml

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
55
<modelVersion>4.0.0</modelVersion>
66

7+
<name>ap-loader</name>
78
<groupId>me.bechberger</groupId>
89
<artifactId>ap-loader</artifactId>
910
<version>${project.versionPlatform}${project.suffix}</version>
11+
<url>https://github.com/parttimenerd/ap-loader</url>
1012
<licenses>
1113
<license>
1214
<name>Apache License, Version 2.0</name>
@@ -120,7 +122,7 @@
120122
<descriptorRefs>
121123
<descriptorRef>jar-with-dependencies</descriptorRef>
122124
</descriptorRefs>
123-
<finalName>${artifactId}-${project.versionPlatform}-full</finalName>
125+
<finalName>${project.artifactId}-${project.versionPlatform}-full</finalName>
124126
<appendAssemblyId>false</appendAssemblyId>
125127
</configuration>
126128
</plugin>
@@ -137,6 +139,23 @@
137139
</execution>
138140
</executions>
139141
</plugin>
142+
<plugin>
143+
<groupId>org.apache.maven.plugins</groupId>
144+
<artifactId>maven-javadoc-plugin</artifactId>
145+
<version>3.4.1</version>
146+
<executions>
147+
<execution>
148+
<id>attach-javadoc</id>
149+
<phase>deploy</phase>
150+
<goals>
151+
<goal>jar</goal>
152+
</goals>
153+
</execution>
154+
</executions>
155+
<configuration>
156+
<additionalJOption>-Xdoclint:none</additionalJOption>
157+
</configuration>
158+
</plugin>
140159
<plugin>
141160
<artifactId>maven-deploy-plugin</artifactId>
142161
<version>2.8.2</version>
@@ -151,16 +170,46 @@
151170
</executions>
152171
</plugin>
153172
<plugin>
154-
<groupId>org.simplify4u.plugins</groupId>
155-
<artifactId>sign-maven-plugin</artifactId>
156-
<version>1.0.1</version>
173+
<groupId>org.apache.maven.plugins</groupId>
174+
<artifactId>maven-gpg-plugin</artifactId>
175+
<version>1.6</version>
157176
<executions>
158177
<execution>
178+
<id>sign-artifacts</id>
179+
<phase>verify</phase>
159180
<goals>
160181
<goal>sign</goal>
161182
</goals>
162183
</execution>
163184
</executions>
185+
<configuration>
186+
<keyname>${gpg.keyname}</keyname>
187+
<passphrase>${gpg.passphrase}</passphrase>
188+
</configuration>
189+
</plugin>
190+
<plugin>
191+
<groupId>org.apache.maven.plugins</groupId>
192+
<artifactId>maven-deploy-plugin</artifactId>
193+
<version>2.8.2</version>
194+
<executions>
195+
<execution>
196+
<id>default-deploy</id>
197+
<phase>deploy</phase>
198+
<goals>
199+
<goal>deploy</goal>
200+
</goals>
201+
<configuration>
202+
<skip>true</skip>
203+
</configuration>
204+
</execution>
205+
<execution>
206+
<id>release</id>
207+
<phase>deploy</phase>
208+
<goals>
209+
<goal>deploy</goal>
210+
</goals>
211+
</execution>
212+
</executions>
164213
</plugin>
165214
</plugins>
166215
</build>

0 commit comments

Comments
 (0)