Skip to content

Commit

Permalink
Merge pull request #5471 from DataDog/jb/track_liveheap_size_cfg
Browse files Browse the repository at this point in the history
Add a config to enable/disable live heap size tracking
  • Loading branch information
jbachorik authored Jun 27, 2023
2 parents d133260 + ef10885 commit 974bf64
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import static com.datadog.profiling.ddprof.DatadogProfilerConfig.getWallInterval;
import static com.datadog.profiling.ddprof.DatadogProfilerConfig.isAllocationProfilingEnabled;
import static com.datadog.profiling.ddprof.DatadogProfilerConfig.isCpuProfilerEnabled;
import static com.datadog.profiling.ddprof.DatadogProfilerConfig.isLiveHeapSizeTrackingEnabled;
import static com.datadog.profiling.ddprof.DatadogProfilerConfig.isMemoryLeakProfilingEnabled;
import static com.datadog.profiling.ddprof.DatadogProfilerConfig.isSpanNameContextAttributeEnabled;
import static com.datadog.profiling.ddprof.DatadogProfilerConfig.isWallClockProfilerEnabled;
Expand Down Expand Up @@ -338,7 +339,7 @@ String cmdStartProfiling(Path file) throws IllegalStateException {
cmd.append('a');
}
if (profilingModes.contains(MEMLEAK)) {
cmd.append('l');
cmd.append(isLiveHeapSizeTrackingEnabled(configProvider) ? 'L' : 'l');
}
}
String cmdString = cmd.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import static datadog.trace.api.config.ProfilingConfig.PROFILING_DATADOG_PROFILER_LIVEHEAP_ENABLED;
import static datadog.trace.api.config.ProfilingConfig.PROFILING_DATADOG_PROFILER_LIVEHEAP_ENABLED_DEFAULT;
import static datadog.trace.api.config.ProfilingConfig.PROFILING_DATADOG_PROFILER_LIVEHEAP_INTERVAL;
import static datadog.trace.api.config.ProfilingConfig.PROFILING_DATADOG_PROFILER_LIVEHEAP_TRACK_HEAPSIZE;
import static datadog.trace.api.config.ProfilingConfig.PROFILING_DATADOG_PROFILER_LIVEHEAP_TRACK_HEAPSIZE_DEFAFULT;
import static datadog.trace.api.config.ProfilingConfig.PROFILING_DATADOG_PROFILER_LOG_LEVEL;
import static datadog.trace.api.config.ProfilingConfig.PROFILING_DATADOG_PROFILER_LOG_LEVEL_DEFAULT;
import static datadog.trace.api.config.ProfilingConfig.PROFILING_DATADOG_PROFILER_MEMLEAK_CAPACITY;
Expand Down Expand Up @@ -164,6 +166,13 @@ public static boolean isMemoryLeakProfilingEnabled() {
return isMemoryLeakProfilingEnabled(ConfigProvider.getInstance());
}

public static boolean isLiveHeapSizeTrackingEnabled(ConfigProvider configProvider) {
return getBoolean(
configProvider,
PROFILING_DATADOG_PROFILER_LIVEHEAP_TRACK_HEAPSIZE,
PROFILING_DATADOG_PROFILER_LIVEHEAP_TRACK_HEAPSIZE_DEFAFULT);
}

public static long getMemleakInterval(ConfigProvider configProvider) {
long maxheap = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getMax();
long memleakIntervalDefault =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ void testStartCmd(boolean cpu, boolean wall, boolean alloc, boolean memleak) thr
assertTrue(cmd.matches(".*?memory=[0-9]+b?:.*?a.*"), cmd);
}
if (profiler.enabledModes().contains(ProfilingMode.MEMLEAK)) {
assertTrue(cmd.matches(".*?memory=[0-9]+b?:.*?l.*"), cmd);
assertTrue(cmd.matches(".*?memory=[0-9]+b?:.*?[lL].*"), cmd);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ public final class ProfilingConfig {
public static final String PROFILING_DATADOG_PROFILER_LIVEHEAP_CAPACITY =
"profiling.ddprof.liveheap.capacity";
public static final int PROFILING_DATADOG_PROFILER_LIVEHEAP_CAPACITY_DEFAULT = 1024;
public static final String PROFILING_DATADOG_PROFILER_LIVEHEAP_TRACK_HEAPSIZE =
"profiling.ddprof.liveheap.track_size.enabled";
public static final boolean PROFILING_DATADOG_PROFILER_LIVEHEAP_TRACK_HEAPSIZE_DEFAFULT = true;
public static final String PROFILING_ENDPOINT_COLLECTION_ENABLED =
"profiling.endpoint.collection.enabled";
public static final boolean PROFILING_ENDPOINT_COLLECTION_ENABLED_DEFAULT = true;
Expand Down

0 comments on commit 974bf64

Please sign in to comment.