-
Notifications
You must be signed in to change notification settings - Fork 186
6203: Add ZGC allocation stall rule #664
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2d95955
6203: Add ZGC allocation stall rule
Suchitainf e6c3ab8
Updated the rule as per new metric allocation stall rate
Suchitainf c180558
Resolving merge conflict
Suchitainf 4b543d9
Implemented review comments
Suchitainf 1828c45
Implemented review comments
Suchitainf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
189 changes: 189 additions & 0 deletions
189
...src/main/java/org/openjdk/jmc/flightrecorder/rules/jdk/memory/ZGCAllocationStallRule.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,189 @@ | ||
/* | ||
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved. | ||
* | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* The contents of this file are subject to the terms of either the Universal Permissive License | ||
* v 1.0 as shown at https://oss.oracle.com/licenses/upl | ||
* | ||
* or the following license: | ||
* | ||
* Redistribution and use in source and binary forms, with or without modification, are permitted | ||
* provided that the following conditions are met: | ||
* | ||
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions | ||
* and the following disclaimer. | ||
* | ||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of | ||
* conditions and the following disclaimer in the documentation and/or other materials provided with | ||
* the distribution. | ||
* | ||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used to | ||
* endorse or promote products derived from this software without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR | ||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND | ||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR | ||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | ||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY | ||
* WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
package org.openjdk.jmc.flightrecorder.rules.jdk.memory; | ||
|
||
import static org.openjdk.jmc.common.unit.UnitLookup.NUMBER; | ||
import static org.openjdk.jmc.common.unit.UnitLookup.NUMBER_UNITY; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.concurrent.Callable; | ||
import java.util.concurrent.FutureTask; | ||
import java.util.concurrent.RunnableFuture; | ||
|
||
import org.openjdk.jmc.common.item.IItemCollection; | ||
import org.openjdk.jmc.common.unit.IQuantity; | ||
import org.openjdk.jmc.common.unit.UnitLookup; | ||
import org.openjdk.jmc.common.util.IPreferenceValueProvider; | ||
import org.openjdk.jmc.common.util.TypedPreference; | ||
import org.openjdk.jmc.flightrecorder.jdk.JdkAggregators; | ||
import org.openjdk.jmc.flightrecorder.jdk.JdkTypeIDs; | ||
import org.openjdk.jmc.flightrecorder.rules.IResult; | ||
import org.openjdk.jmc.flightrecorder.rules.IResultValueProvider; | ||
import org.openjdk.jmc.flightrecorder.rules.IRule; | ||
import org.openjdk.jmc.flightrecorder.rules.ResultBuilder; | ||
import org.openjdk.jmc.flightrecorder.rules.Severity; | ||
import org.openjdk.jmc.flightrecorder.rules.TypedResult; | ||
import org.openjdk.jmc.flightrecorder.rules.jdk.messages.internal.Messages; | ||
import org.openjdk.jmc.flightrecorder.rules.util.JfrRuleTopics; | ||
import org.openjdk.jmc.flightrecorder.rules.util.RulesToolkit; | ||
import org.openjdk.jmc.flightrecorder.rules.util.RulesToolkit.EventAvailability; | ||
import org.openjdk.jmc.flightrecorder.rules.util.RulesToolkit.RequiredEventsBuilder; | ||
|
||
public class ZGCAllocationStallRule implements IRule { | ||
|
||
private static final String ZGC_RESULT_ID = "ZGCAllocationStallRule"; //$NON-NLS-1$ | ||
|
||
private static final Map<String, EventAvailability> REQUIRED_EVENTS = RequiredEventsBuilder.create() | ||
.addEventType(JdkTypeIDs.ZGC_ALLOCATION_STALL, EventAvailability.AVAILABLE).build(); | ||
|
||
public static final TypedResult<IQuantity> ZGC_ALLOCATION_STALL_EVENTS = new TypedResult<>( | ||
"zgcAllocationStallCount", //$NON-NLS-1$ | ||
JdkAggregators.ZGC_ALLOCATION_STALL_COUNT, UnitLookup.NUMBER, IQuantity.class); | ||
|
||
public static final TypedResult<IQuantity> ZGC_ALLOCATION_STALL_LONGEST_DURATION = new TypedResult<>( | ||
"zgcAllocationStallLongestDuration", //$NON-NLS-1$ | ||
JdkAggregators.ZGC_ALLOCATION_STALL_COUNT, UnitLookup.TIMESPAN, IQuantity.class); | ||
|
||
public static final TypedResult<IQuantity> ZGC_ALLOCATION_STALL_TOTAL_DURATION = new TypedResult<>( | ||
"zgcAllocationStallTotalDuration", //$NON-NLS-1$ | ||
JdkAggregators.ZGC_ALLOCATION_STALL_COUNT, UnitLookup.TIMESPAN, IQuantity.class); | ||
|
||
public static final TypedResult<IQuantity> ZGC_ALLOCATION_STALL_PER_MINUTE = new TypedResult<>( | ||
"zgcAllocationStallPerMinute", //$NON-NLS-1$ | ||
Messages.getString(Messages.ZGCAllocationStallRule_RATE), | ||
Messages.getString(Messages.ZGCAllocationStallRule_RATE_LONG), UnitLookup.NUMBER, IQuantity.class); | ||
public static final TypedPreference<IQuantity> ALLOCATION_STALL_INFO_LIMIT = new TypedPreference<>( | ||
"allocation.stall.rate.info.limit", //$NON-NLS-1$ | ||
Messages.getString(Messages.ZGCAllocationStallRule_CONFIG_INFO_LIMIT), | ||
Messages.getString(Messages.ZGCAllocationStallRule_CONFIG_INFO_LIMIT_LONG), NUMBER, | ||
NUMBER_UNITY.quantity(10)); | ||
|
||
public static final TypedPreference<IQuantity> ALLOCATION_STALL_WARNING_LIMIT = new TypedPreference<>( | ||
"allocation.stall.rate.warning.limit", //$NON-NLS-1$ | ||
Messages.getString(Messages.ZGCAllocationStallRule_CONFIG_WARN_LIMIT), | ||
Messages.getString(Messages.ZGCAllocationStallRule_CONFIG_WARN_LIMIT_LONG), NUMBER, | ||
NUMBER_UNITY.quantity(100)); | ||
|
||
private static final List<TypedPreference<?>> CONFIG_ATTRIBUTES = Arrays | ||
.<TypedPreference<?>> asList(ALLOCATION_STALL_INFO_LIMIT, ALLOCATION_STALL_WARNING_LIMIT); | ||
|
||
private static final Collection<TypedResult<?>> RESULT_ATTRIBUTES = Arrays.<TypedResult<?>> asList( | ||
TypedResult.SCORE, ZGC_ALLOCATION_STALL_EVENTS, ZGC_ALLOCATION_STALL_LONGEST_DURATION, | ||
ZGC_ALLOCATION_STALL_TOTAL_DURATION, ZGC_ALLOCATION_STALL_PER_MINUTE); | ||
|
||
@Override | ||
public String getId() { | ||
return ZGC_RESULT_ID; | ||
} | ||
|
||
@Override | ||
public String getTopic() { | ||
return JfrRuleTopics.GARBAGE_COLLECTION; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return Messages.getString(Messages.ZGCAllocationStall_RULE_NAME); | ||
} | ||
|
||
@Override | ||
public Map<String, EventAvailability> getRequiredEvents() { | ||
return REQUIRED_EVENTS; | ||
} | ||
|
||
private IResult getResult( | ||
IItemCollection items, IPreferenceValueProvider valueProvider, IResultValueProvider resultProvider) { | ||
long infoLimit = valueProvider.getPreferenceValue(ALLOCATION_STALL_INFO_LIMIT).clampedLongValueIn(NUMBER_UNITY); | ||
long warningLimit = valueProvider.getPreferenceValue(ALLOCATION_STALL_WARNING_LIMIT) | ||
.clampedLongValueIn(NUMBER_UNITY); | ||
|
||
IQuantity zgcAllocationStallCount = items.getAggregate(JdkAggregators.ZGC_ALLOCATION_STALL_COUNT); | ||
IQuantity zgcAllocationStallTotalDuration = items.getAggregate(JdkAggregators.TOTAL_ZGC_ALLOCATION_STALL); | ||
IQuantity zgcAllocationStallLongestDuration = items.getAggregate(JdkAggregators.LONGEST_ZGC_ALLOCATION_STALL); | ||
if (zgcAllocationStallCount != null && zgcAllocationStallCount.doubleValue() > 0) { | ||
|
||
//Calculate time after JVM Start | ||
IQuantity timeAfterJVMStart = RulesToolkit.getEarliestStartTime(items) | ||
thegreystone marked this conversation as resolved.
Show resolved
Hide resolved
|
||
.subtract(items.getAggregate(JdkAggregators.JVM_START_TIME)); | ||
|
||
//Calculate Stall Per minute | ||
IQuantity stallPerMinute = UnitLookup.NUMBER_UNITY | ||
.quantity(zgcAllocationStallTotalDuration.doubleValueIn(UnitLookup.MINUTE) | ||
/ timeAfterJVMStart.doubleValueIn(UnitLookup.MINUTE)); | ||
|
||
double score = RulesToolkit.mapExp100(stallPerMinute.clampedLongValueIn(UnitLookup.NUMBER_UNITY), infoLimit, | ||
warningLimit); | ||
|
||
return ResultBuilder.createFor(ZGCAllocationStallRule.this, valueProvider).setSeverity(Severity.get(score)) | ||
.setSummary(Messages.getString(Messages.ZGCAllocationStall_TEXT_INFO) | ||
.concat(Messages.getString(Messages.ZGCAllocationStall_TEXT_WARN))) | ||
.addResult(TypedResult.SCORE, UnitLookup.NUMBER_UNITY.quantity(score)) | ||
.addResult(ZGC_ALLOCATION_STALL_EVENTS, zgcAllocationStallCount) | ||
.addResult(ZGC_ALLOCATION_STALL_TOTAL_DURATION, zgcAllocationStallTotalDuration) | ||
.addResult(ZGC_ALLOCATION_STALL_LONGEST_DURATION, zgcAllocationStallLongestDuration) | ||
.addResult(ZGC_ALLOCATION_STALL_PER_MINUTE, stallPerMinute).build(); | ||
|
||
} | ||
return ResultBuilder.createFor(ZGCAllocationStallRule.this, valueProvider).setSeverity(Severity.OK) | ||
.setSummary(Messages.getString(Messages.ZGCAllocationStall_TEXT_INFO) | ||
.concat(Messages.getString(Messages.ZGCAllocationStall_TEXT_OK))) | ||
.build(); | ||
} | ||
|
||
@Override | ||
public RunnableFuture<IResult> createEvaluation( | ||
final IItemCollection items, final IPreferenceValueProvider preferenceValueProvider, | ||
final IResultValueProvider dependencyResults) { | ||
FutureTask<IResult> evaluationTask = new FutureTask<>(new Callable<IResult>() { | ||
@Override | ||
public IResult call() throws Exception { | ||
return getResult(items, preferenceValueProvider, dependencyResults); | ||
} | ||
}); | ||
return evaluationTask; | ||
} | ||
|
||
@Override | ||
public Collection<TypedPreference<?>> getConfigurationAttributes() { | ||
return CONFIG_ATTRIBUTES; | ||
} | ||
|
||
@Override | ||
public Collection<TypedResult<?>> getResults() { | ||
return RESULT_ATTRIBUTES; | ||
} | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.