diff --git a/gprofiler/java.py b/gprofiler/java.py index 519051deb..1512c8cea 100644 --- a/gprofiler/java.py +++ b/gprofiler/java.py @@ -55,6 +55,11 @@ def jattach_path() -> str: return resource_path("java/jattach") +@functools.lru_cache(maxsize=1) +def get_ap_version() -> str: + return Path(resource_path("java/async-profiler-version")).read_text() + + class AsyncProfiledProcess: """ Represents a process profiled with async-profiler. @@ -73,7 +78,9 @@ def __init__(self, process: Process, storage_dir: str): # multiple times into the process) # without depending on storage_dir here, we maintain the same path even if gProfiler is re-run, # because storage_dir changes between runs. - self._ap_dir = os.path.join(TEMPORARY_STORAGE_PATH, "async-profiler") + # we embed the async-profiler version in the path, so future gprofiler versions which use another version + # of AP case use it (will be loaded as a different DSO) + self._ap_dir = os.path.join(TEMPORARY_STORAGE_PATH, f"async-profiler-{get_ap_version()}") self._ap_dir_host = resolve_proc_root_links(self._process_root, self._ap_dir) self._libap_path_host = os.path.join(self._ap_dir_host, "libasyncProfiler.so") diff --git a/scripts/async_profiler_build.sh b/scripts/async_profiler_build.sh index 6f3ed8d8e..cb8e09f34 100755 --- a/scripts/async_profiler_build.sh +++ b/scripts/async_profiler_build.sh @@ -5,5 +5,14 @@ # set -euo pipefail -git clone --depth 1 -b v2.0g3 https://github.com/Granulate/async-profiler.git && cd async-profiler && git reset --hard 51447a849d686e899c1cd393e83f0f7c41685d95 +VERSION=v2.0g3 +OUTPUT=async-profiler-2.0-linux-x64.tar.gz + +git clone --depth 1 -b "$VERSION" https://github.com/Granulate/async-profiler.git && cd async-profiler && git reset --hard 51447a849d686e899c1cd393e83f0f7c41685d95 make release + +# add a version file to the build directory +echo -n "$VERSION" > async-profiler-version +gunzip "$OUTPUT" +tar -rf "${OUTPUT%.gz}" --transform s,^,async-profiler-2.0-linux-x64/build/, async-profiler-version +gzip "${OUTPUT%.gz}"