Skip to content

gustavotemple/async-profiler-examples

Repository files navigation

async-profiler-examples

Build

Run (https://stackoverflow.com/a/52404325):

$./gradlew bootJar

Async Profiler files

setup_profiler.sh

#!/bin/sh
if [ "$(whoami)" != "root" ]; then exit 1; fi
sh -c "echo 1 > /proc/sys/kernel/perf_event_paranoid"
sh -c "echo 0 > /proc/sys/kernel/kptr_restrict"
cd /root
if [ ! -d "async-profiler" ]; then git clone https://github.com/jvm-profiling-tools/async-profiler.git; fi
make -C async-profiler
async-profiler/profiler.sh --version

Run:

sudo sh ./setup_profiler.sh

Dockerfile

FROM openjdk:11
USER root
WORKDIR /root
VOLUME /tmp
VOLUME /root/async-profiler
COPY my.jar my.jar
EXPOSE 8080
CMD ["sh", "-c", "java ${MY_ARGS} -jar my.jar"]

docker-compose.yml

version: '3'
services:
  app:
    image: app
    ports:
      - "8080:8080"
    volumes:
      - /tmp:/tmp
      - /root/async-profiler:/root/async-profiler
    security_opt:
      - seccomp:unconfined
    environment:
      - MY_ARGS=-XX:+PreserveFramePointer -XX:+UnlockDiagnosticVMOptions -XX:+DebugNonSafepoints

Run:

docker swarm init
docker build -t app -f Dockerfile .
docker stack rm test
docker stack deploy --compose-file docker-compose.yml test
docker stats

Run:

sudo ps -ef | grep "java" | grep "PreserveFramePointer" \
 | grep -v "sbt.ForkMain" | grep -v "grep" \
 | awk '{print $2}' \
 | sudo xargs -I pid /root/async-profiler/profiler.sh -d 60 -f /tmp/title.svg --title title -e itimer pid

Gatling Project

AsyncProfiler call:

Debug Gatling:

Notes

  • async-profiler should be run from the host by a privileged user.
  • Make sure that the target container can access libasyncProfiler.so by the same absolute path as on the host.
  • /tmp directory of Java process should be physically the same directory as /tmp of your shell.
  • Some JVMs do not provide attach mode. The attach mode is supported for e.g. Oracle JDK, OpenJDK HotSpot, and IBM JDK based on OpenJ9.
  • It is possible to profile a JVM running in a Docker from inside its container and from its host system.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published