Skip to content

Commit 2153fe5

Browse files
author
Matt
authored
Introduce aggregated smap events (enabled by default) (#7820)
* Enable aggregated smap events by default in place of existing smap single entries * Formatting * Formatting * Modify when to use which smap recording mode * Formatting * Remove leftover debug print
1 parent cc4a74b commit 2153fe5

File tree

5 files changed

+84
-6
lines changed

5 files changed

+84
-6
lines changed

dd-java-agent/agent-profiling/profiling-controller-openjdk/src/main/java/com/datadog/profiling/controller/openjdk/OpenJdkController.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,12 +223,17 @@ ProfilingConfig.PROFILING_ALLOCATION_ENABLED, isObjectAllocationSampleAvailable(
223223
}
224224
}
225225

226-
if (configProvider.getBoolean(
226+
if (!configProvider.getBoolean(
227227
ProfilingConfig.PROFILING_SMAP_COLLECTION_ENABLED,
228228
ProfilingConfig.PROFILING_SMAP_COLLECTION_ENABLED_DEFAULT)) {
229-
enableEvent(recordingSettings, "datadog.SmapEntry", "User enabled smaps collection");
230-
} else {
231229
disableEvent(recordingSettings, "datadog.SmapEntry", "User disabled smaps collection");
230+
} else if (!configProvider.getBoolean(
231+
ProfilingConfig.PROFILING_SMAP_AGGREGATION_ENABLED,
232+
ProfilingConfig.PROFILING_SMAP_AGGREGATION_ENABLED_DEFAULT)) {
233+
disableEvent(
234+
recordingSettings,
235+
"datadog.AggregatedSmapEntry",
236+
"User disabled aggregated smaps collection");
232237
}
233238

234239
// Warn users for expensive events
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package com.datadog.profiling.controller.openjdk.events;
2+
3+
import java.util.HashMap;
4+
import java.util.List;
5+
import jdk.jfr.Category;
6+
import jdk.jfr.DataAmount;
7+
import jdk.jfr.Description;
8+
import jdk.jfr.Event;
9+
import jdk.jfr.EventType;
10+
import jdk.jfr.Label;
11+
import jdk.jfr.Name;
12+
import jdk.jfr.Period;
13+
import jdk.jfr.StackTrace;
14+
15+
@Name("datadog.AggregatedSmapEntry")
16+
@Label("Aggregated Smap Entry")
17+
@Description("Entry for the entries from the smaps file aggregated by NMT category")
18+
@Category("Datadog")
19+
@Period("beginChunk")
20+
@StackTrace(false)
21+
public class AggregatedSmapEntryEvent extends Event {
22+
@Label("NMT Category")
23+
private final String nmtCategory;
24+
25+
@Label("Resident Set Size")
26+
@DataAmount
27+
private final long rss;
28+
29+
public AggregatedSmapEntryEvent(String nmtCategory, long rss) {
30+
this.nmtCategory = nmtCategory;
31+
this.rss = rss;
32+
}
33+
34+
public static void emit() {
35+
if (EventType.getEventType(AggregatedSmapEntryEvent.class).isEnabled()) {
36+
HashMap<String, Long> aggregatedSmapEntries = new HashMap<>();
37+
List<? extends Event> collectedEvents = SmapEntryFactory.collectEvents();
38+
// A single entry should only be expected for the error cases
39+
if (collectedEvents.size() > 1) {
40+
collectedEvents.forEach(
41+
entry -> {
42+
aggregatedSmapEntries.merge(
43+
((SmapEntryEvent) entry).getNmtCategory(),
44+
((SmapEntryEvent) entry).getRss(),
45+
Long::sum);
46+
});
47+
aggregatedSmapEntries.forEach(
48+
(nmtCategory, rss) -> {
49+
new AggregatedSmapEntryEvent(nmtCategory, rss).commit();
50+
});
51+
} else {
52+
collectedEvents.forEach(Event::commit);
53+
}
54+
}
55+
}
56+
}

dd-java-agent/agent-profiling/profiling-controller-openjdk/src/main/java/com/datadog/profiling/controller/openjdk/events/SmapEntryEvent.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import jdk.jfr.Category;
44
import jdk.jfr.DataAmount;
55
import jdk.jfr.Description;
6-
import jdk.jfr.Enabled;
76
import jdk.jfr.Event;
7+
import jdk.jfr.EventType;
88
import jdk.jfr.Label;
99
import jdk.jfr.Name;
1010
import jdk.jfr.Period;
@@ -15,7 +15,6 @@
1515
@Description("Entry from the smaps file for the JVM")
1616
@Category("Datadog")
1717
@Period("beginChunk")
18-
@Enabled
1918
@StackTrace(false)
2019
public class SmapEntryEvent extends Event {
2120

@@ -241,6 +240,17 @@ public SmapEntryEvent(
241240
}
242241

243242
public static void emit() {
244-
SmapEntryFactory.collectEvents().forEach(Event::commit);
243+
if (!EventType.getEventType(AggregatedSmapEntryEvent.class).isEnabled()) {
244+
SmapEntryFactory.collectEvents().forEach(Event::commit);
245+
} else {
246+
}
247+
}
248+
249+
public long getRss() {
250+
return this.rss;
251+
}
252+
253+
public String getNmtCategory() {
254+
return this.nmtCategory;
245255
}
246256
}

dd-java-agent/agent-profiling/profiling-controller-openjdk/src/main/java/com/datadog/profiling/controller/openjdk/events/SmapEntryFactory.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ public SmapParseErrorEvent(ErrorReason reason) {
6060
public static void registerEvents() {
6161
// Make sure the periodic event is registered only once
6262
if (REGISTERED.compareAndSet(false, true) && Platform.isLinux()) {
63+
// Only one of these should ever be enabled at the same time
6364
JfrHelper.addPeriodicEvent(SmapEntryEvent.class, SmapEntryEvent::emit);
65+
JfrHelper.addPeriodicEvent(AggregatedSmapEntryEvent.class, AggregatedSmapEntryEvent::emit);
6466
try {
6567
ObjectName objectName = new ObjectName("com.sun.management:type=DiagnosticCommand");
6668
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();

dd-trace-api/src/main/java/datadog/trace/api/config/ProfilingConfig.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,11 @@ public final class ProfilingConfig {
212212

213213
public static final boolean PROFILING_SMAP_COLLECTION_ENABLED_DEFAULT = true;
214214

215+
public static final String PROFILING_SMAP_AGGREGATION_ENABLED =
216+
"profiling.smap.aggregation.enabled";
217+
218+
public static final boolean PROFILING_SMAP_AGGREGATION_ENABLED_DEFAULT = true;
219+
215220
public static final String PROFILING_QUEUEING_TIME_THRESHOLD_MILLIS =
216221
"profiling.queueing.time.threshold.millis";
217222

0 commit comments

Comments
 (0)