From f7a33fc3ae4246df91c4bcc0cf7f8063ea59105a Mon Sep 17 00:00:00 2001 From: Tom Sisso Date: Mon, 28 Nov 2022 09:09:24 +0200 Subject: [PATCH] add support for leak profiling --- pom.xml | 4 ++-- .../api/facade/AsyncProfilerCommandsFactory.java | 4 ++++ .../async_profiler/api/facade/ProfileRequest.java | 1 + .../facade/AsyncProfilerCommandsFactoryTest.java | 15 ++++++++++++++- 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 82f72e8..69787a2 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.taboola async-profiler-actuator-endpoint - 2.0.1_${async.profiler.version} + 2.0.2_${async.profiler.version} ${project.groupId}:${project.artifactId} Async Profiler Actuator Endpoint @@ -51,7 +51,7 @@ 4.3.23.RELEASE 1.5.20.RELEASE 1.18.10 - 2.7 + 2.9 1.8 1.8 false diff --git a/src/main/java/com/taboola/async_profiler/api/facade/AsyncProfilerCommandsFactory.java b/src/main/java/com/taboola/async_profiler/api/facade/AsyncProfilerCommandsFactory.java index 035206f..7304bba 100644 --- a/src/main/java/com/taboola/async_profiler/api/facade/AsyncProfilerCommandsFactory.java +++ b/src/main/java/com/taboola/async_profiler/api/facade/AsyncProfilerCommandsFactory.java @@ -42,6 +42,10 @@ public String createStartCommand(ProfileRequest profileRequest, String filePath) stringBuilder.append(interval); } + if (profileRequest.getEvents().contains(Events.ALLOC) && profileRequest.isLiveObjectsOnly()) { + stringBuilder.append(",live"); + } + if (profileRequest.getJfrSync() != null) { if (profileRequest.getJfrSync().isEmpty()) { stringBuilder.append(",jfrsync"); diff --git a/src/main/java/com/taboola/async_profiler/api/facade/ProfileRequest.java b/src/main/java/com/taboola/async_profiler/api/facade/ProfileRequest.java index 615c76b..2c95b55 100644 --- a/src/main/java/com/taboola/async_profiler/api/facade/ProfileRequest.java +++ b/src/main/java/com/taboola/async_profiler/api/facade/ProfileRequest.java @@ -21,6 +21,7 @@ public class ProfileRequest { Integer samplingInterval = 1; TimeUnit samplingIntervalTimeUnit = TimeUnit.MILLISECONDS; Integer allocIntervalBytes = 10_000;//relevant only for alloc event. + boolean liveObjectsOnly = true; Integer lockThresholdNanos = 1;//relevant only for lock event. boolean separateThreads = false; String includedThreads; diff --git a/src/test/java/com/taboola/async_profiler/api/facade/AsyncProfilerCommandsFactoryTest.java b/src/test/java/com/taboola/async_profiler/api/facade/AsyncProfilerCommandsFactoryTest.java index 89c55c8..644b266 100644 --- a/src/test/java/com/taboola/async_profiler/api/facade/AsyncProfilerCommandsFactoryTest.java +++ b/src/test/java/com/taboola/async_profiler/api/facade/AsyncProfilerCommandsFactoryTest.java @@ -71,7 +71,7 @@ public void testCreateStartCommandWithMultipleEvents() { profileRequest.setSamplingIntervalTimeUnit(TimeUnit.NANOSECONDS); String command = commandFactory.createStartCommand(profileRequest, file); - assertEquals("start,event=cpu,alloc=10000,lock=1,file=f,jfr,interval=1", command); + assertEquals("start,event=cpu,alloc=10000,lock=1,file=f,jfr,interval=1,live", command); } @Test @@ -94,6 +94,19 @@ public void testCreateStartCommand_whenEventIsAlloc_intervalShouldBeTakenFromInt profileRequest.setAllocIntervalBytes(2); String command = commandFactory.createStartCommand(profileRequest, file); + assertEquals("start,event=alloc,alloc=2,file=f,flamegraph,interval=1000000,live", command); + } + + @Test + public void testCreateStartCommand_whenEventIsAllocAndLiveObjectsOnlyIsFalse() { + String file = "f"; + ProfileRequest profileRequest = new ProfileRequest(); + profileRequest.setEvents(new HashSet(){{add(Events.ALLOC);}}); + profileRequest.setSamplingInterval(1); + profileRequest.setAllocIntervalBytes(2); + profileRequest.setLiveObjectsOnly(false); + String command = commandFactory.createStartCommand(profileRequest, file); + assertEquals("start,event=alloc,alloc=2,file=f,flamegraph,interval=1000000", command); }