Skip to content

Commit

Permalink
Allow adjusting of lead detection sampling interval. (netty#8568)
Browse files Browse the repository at this point in the history
Motivation:

We should allow adjustment of the leak detecting sampling interval when in SAMPLE mode.

Modifications:

Added new int property io.netty.leakDetection.samplingInterval

Result:

Be able to consume changes made by the user.
  • Loading branch information
tjake authored and normanmaurer committed Nov 16, 2018
1 parent abc8a08 commit 63dc1f5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
9 changes: 6 additions & 3 deletions common/src/main/java/io/netty/util/ResourceLeakDetector.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,12 @@ public class ResourceLeakDetector<T> {
private static final String PROP_TARGET_RECORDS = "io.netty.leakDetection.targetRecords";
private static final int DEFAULT_TARGET_RECORDS = 4;

private static final String PROP_SAMPLING_INTERVAL = "io.netty.leakDetection.samplingInterval";
// There is a minor performance benefit in TLR if this is a power of 2.
private static final int DEFAULT_SAMPLING_INTERVAL = 128;

private static final int TARGET_RECORDS;
static final int SAMPLING_INTERVAL;

/**
* Represents the level of resource leak detection.
Expand Down Expand Up @@ -117,6 +122,7 @@ static Level parseLevel(String levelStr) {
Level level = Level.parseLevel(levelStr);

TARGET_RECORDS = SystemPropertyUtil.getInt(PROP_TARGET_RECORDS, DEFAULT_TARGET_RECORDS);
SAMPLING_INTERVAL = SystemPropertyUtil.getInt(PROP_SAMPLING_INTERVAL, DEFAULT_SAMPLING_INTERVAL);

ResourceLeakDetector.level = level;
if (logger.isDebugEnabled()) {
Expand All @@ -125,9 +131,6 @@ static Level parseLevel(String levelStr) {
}
}

// There is a minor performance benefit in TLR if this is a power of 2.
static final int DEFAULT_SAMPLING_INTERVAL = 128;

/**
* @deprecated Use {@link #setLevel(Level)} instead.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static void setResourceLeakDetectorFactory(ResourceLeakDetectorFactory fa
* @return a new instance of {@link ResourceLeakDetector}
*/
public final <T> ResourceLeakDetector<T> newResourceLeakDetector(Class<T> resource) {
return newResourceLeakDetector(resource, ResourceLeakDetector.DEFAULT_SAMPLING_INTERVAL);
return newResourceLeakDetector(resource, ResourceLeakDetector.SAMPLING_INTERVAL);
}

/**
Expand Down Expand Up @@ -90,7 +90,7 @@ public abstract <T> ResourceLeakDetector<T> newResourceLeakDetector(
*/
@SuppressWarnings("deprecation")
public <T> ResourceLeakDetector<T> newResourceLeakDetector(Class<T> resource, int samplingInterval) {
return newResourceLeakDetector(resource, ResourceLeakDetector.DEFAULT_SAMPLING_INTERVAL, Long.MAX_VALUE);
return newResourceLeakDetector(resource, ResourceLeakDetector.SAMPLING_INTERVAL, Long.MAX_VALUE);
}

/**
Expand Down

0 comments on commit 63dc1f5

Please sign in to comment.