Skip to content

Commit 989934b

Browse files
authored
java: Allow different gProfiler versions to use different APs (#137)
By embedding AP version in the AP dir, we will have different dirs for different AP releases.
1 parent 933b92e commit 989934b

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

gprofiler/java.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ def jattach_path() -> str:
5555
return resource_path("java/jattach")
5656

5757

58+
@functools.lru_cache(maxsize=1)
59+
def get_ap_version() -> str:
60+
return Path(resource_path("java/async-profiler-version")).read_text()
61+
62+
5863
class AsyncProfiledProcess:
5964
"""
6065
Represents a process profiled with async-profiler.
@@ -73,7 +78,9 @@ def __init__(self, process: Process, storage_dir: str):
7378
# multiple times into the process)
7479
# without depending on storage_dir here, we maintain the same path even if gProfiler is re-run,
7580
# because storage_dir changes between runs.
76-
self._ap_dir = os.path.join(TEMPORARY_STORAGE_PATH, "async-profiler")
81+
# we embed the async-profiler version in the path, so future gprofiler versions which use another version
82+
# of AP case use it (will be loaded as a different DSO)
83+
self._ap_dir = os.path.join(TEMPORARY_STORAGE_PATH, f"async-profiler-{get_ap_version()}")
7784
self._ap_dir_host = resolve_proc_root_links(self._process_root, self._ap_dir)
7885

7986
self._libap_path_host = os.path.join(self._ap_dir_host, "libasyncProfiler.so")

scripts/async_profiler_build.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,14 @@
55
#
66
set -euo pipefail
77

8-
git clone --depth 1 -b v2.0g3 https://github.com/Granulate/async-profiler.git && cd async-profiler && git reset --hard 51447a849d686e899c1cd393e83f0f7c41685d95
8+
VERSION=v2.0g3
9+
OUTPUT=async-profiler-2.0-linux-x64.tar.gz
10+
11+
git clone --depth 1 -b "$VERSION" https://github.com/Granulate/async-profiler.git && cd async-profiler && git reset --hard 51447a849d686e899c1cd393e83f0f7c41685d95
912
make release
13+
14+
# add a version file to the build directory
15+
echo -n "$VERSION" > async-profiler-version
16+
gunzip "$OUTPUT"
17+
tar -rf "${OUTPUT%.gz}" --transform s,^,async-profiler-2.0-linux-x64/build/, async-profiler-version
18+
gzip "${OUTPUT%.gz}"

0 commit comments

Comments
 (0)