RFR: 5608: Include top stack trace frames in errors and exceptions rules [v2]

Marcus Hirt hirt at openjdk.org
Fri Sep 19 11:55:29 UTC 2025


On Thu, 18 Sep 2025 18:11:46 GMT, Aymane Harmaz <duke at openjdk.org> wrote:

>> This PR includes : 
>> - Adding the most common error stack trace to the **Thrown Errors** rule
>> - Adding the most common exception to the **Thrown Exceptions** rule and its most common stack trace if **jdk.JavaExceptionThrow** event is enabled in recording configuration (for now the max number of stack trace frames displayed is 10)
>> 
>> <img width="587" height="458" alt="Screenshot 2025-09-17 at 17 30 16" src="https://github.com/user-attachments/assets/70240eef-f0c9-4231-a4e1-398e1af9f07b" />
>
> Aymane Harmaz has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Adding most common error and exceprion message

Additional review comments.

core/org.openjdk.jmc.flightrecorder.rules.jdk/src/main/java/org/openjdk/jmc/flightrecorder/rules/jdk/exceptions/ErrorRule.java line 118:

> 116: 	public static final TypedResult<String> MOST_COMMON_ERROR_STACKTRACE = new TypedResult<>(
> 117: 			"mostCommonErrorStacktrace", //$NON-NLS-1$
> 118: 			"Most Common Error Stacktrace", "The most common error stacktrace frames.", UnitLookup.PLAIN_TEXT,

In text we typically write stack trace instead of stacktrace, even if we often (and sorry about this) put STACKTRACE together in identifiers. For example, the Stack Trace view (we use capitalization / title case in views).

core/org.openjdk.jmc.flightrecorder.rules.jdk/src/main/java/org/openjdk/jmc/flightrecorder/rules/jdk/exceptions/ExceptionRule.java line 104:

> 102: 			"Most Common Exception Message", "The most common exception message.", UnitLookup.PLAIN_TEXT, String.class);
> 103: 	public static final TypedResult<String> MOST_COMMON_EXCEPTION_STACKTRACE = new TypedResult<>(
> 104: 			"mostCommonExceptionStacktrace", "Most Common Exception Stacktrace", //$NON-NLS-1$

Stack Trace

core/org.openjdk.jmc.flightrecorder.rules.jdk/src/main/java/org/openjdk/jmc/flightrecorder/rules/jdk/exceptions/ExceptionRule.java line 105:

> 103: 	public static final TypedResult<String> MOST_COMMON_EXCEPTION_STACKTRACE = new TypedResult<>(
> 104: 			"mostCommonExceptionStacktrace", "Most Common Exception Stacktrace", //$NON-NLS-1$
> 105: 			"The most common exception stacktrace frames.", UnitLookup.PLAIN_TEXT, String.class);

stack trace

core/org.openjdk.jmc.flightrecorder.rules.jdk/src/main/resources/org/openjdk/jmc/flightrecorder/rules/jdk/messages/internal/messages.properties line 236:

> 234: ErrorRule_TEXT_WARN_EXCLUDED_INFO=The following regular expression was used to exclude {excludedErrors} errors from this rule: ''{error.exclude.regexp}''.
> 235: # {mostCommonErrorMessage} is a string.
> 236: ErrorRule_TEXT_WARN_MOST_COMMON_ERROR_MESSAGE=The most common error message was : \n {mostCommonErrorMessage}

JMC avoids spacing before colon - should be "was:"

core/org.openjdk.jmc.flightrecorder.rules.jdk/src/main/resources/org/openjdk/jmc/flightrecorder/rules/jdk/messages/internal/messages.properties line 238:

> 236: ErrorRule_TEXT_WARN_MOST_COMMON_ERROR_MESSAGE=The most common error message was : \n {mostCommonErrorMessage}
> 237: # {mostCommonErrorStacktrace} is a string.
> 238: ErrorRule_TEXT_WARN_MOST_COMMON_ERROR_STACKTRACE=The most common error stackrace was : \n {mostCommonErrorStacktrace}

No space before colon.

core/org.openjdk.jmc.flightrecorder.rules.jdk/src/main/resources/org/openjdk/jmc/flightrecorder/rules/jdk/messages/internal/messages.properties line 250:

> 248: ExceptionRule_TEXT_MESSAGE=The program generated {exceptionsRate} exceptions per second during {exceptionsWindow}.
> 249: #{mostCommonExceptionMessage} is a string
> 250: ExceptionRule_TEXT_MOST_COMMON_EXCEPTION_MESSAGE=The most common exception message was : \n {mostCommonExceptionMessage}

No space before colon.

core/org.openjdk.jmc.flightrecorder.rules.jdk/src/main/resources/org/openjdk/jmc/flightrecorder/rules/jdk/messages/internal/messages.properties line 252:

> 250: ExceptionRule_TEXT_MOST_COMMON_EXCEPTION_MESSAGE=The most common exception message was : \n {mostCommonExceptionMessage}
> 251: #{mostCommonExceptionStacktrace} is a string.
> 252: ExceptionRule_TEXT_MOST_COMMON_EXCEPTION_STACKTRACE=The most common exception stacktrace was : \n {mostCommonExceptionStacktrace}

No space before colon.

core/org.openjdk.jmc.flightrecorder.rules/src/main/java/org/openjdk/jmc/flightrecorder/rules/util/RulesToolkit.java line 1443:

> 1441: 
> 1442: 	/**
> 1443: 	 * Gets the top n frame in the most common stack trace. Useful when showing what called a

Maybe clarify this a bit in the javadoc, e.g. something like:

Returns up to {@code n} frames from the single most frequent branch in the aggregated stack traces for the provided  {@code items} . 

The result starts at the frame where the event(s) occurred and includes successive caller frames, up to the requested number. This is useful to see the most frequent path leading to calling an interesting method, like for example java.lang.Integer.valueOf (aka autoboxing).


@param items the events for which to aggregate stack traces
@param n the maximum number of frames to return
@return a string representation of up to {@code n} frames, starting at the
         event site and moving toward the callers


Feel free to edit.

core/org.openjdk.jmc.flightrecorder.rules/src/main/java/org/openjdk/jmc/flightrecorder/rules/util/RulesToolkit.java line 1450:

> 1448: 	 * @return stack trace frames
> 1449: 	 */
> 1450: 	public static String getTopNFramesInMostCommonTrace(IItemCollection items, int n) {

Maybe add a small shim for people that might already use it outside of JMC?

public static String getSecondFrameInMostCommonTrace(IItemCollection items) {
	String frames = getTopNFramesInMostCommonTrace(items, 2);
	String[] parts = frames.split("\n");
	return parts.length >= 2 ? parts[1] : frames;
}

core/tests/org.openjdk.jmc.flightrecorder.rules.jdk.test/src/main/resources/baseline/JfrRuleBaseline.xml line 6295:

> 6293: The most common error message was : 
> 6294:  &lt;clinit&gt;
> 6295: The most common error stackrace was : 

Typo: "stackrace" -> "stacktrace"

-------------

Changes requested by hirt (Lead).

PR Review: https://git.openjdk.org/jmc/pull/674#pullrequestreview-3244424631
PR Review Comment: https://git.openjdk.org/jmc/pull/674#discussion_r2362644568
PR Review Comment: https://git.openjdk.org/jmc/pull/674#discussion_r2362646265
PR Review Comment: https://git.openjdk.org/jmc/pull/674#discussion_r2362645740
PR Review Comment: https://git.openjdk.org/jmc/pull/674#discussion_r2362635799
PR Review Comment: https://git.openjdk.org/jmc/pull/674#discussion_r2362636500
PR Review Comment: https://git.openjdk.org/jmc/pull/674#discussion_r2362636832
PR Review Comment: https://git.openjdk.org/jmc/pull/674#discussion_r2362637330
PR Review Comment: https://git.openjdk.org/jmc/pull/674#discussion_r2362581446
PR Review Comment: https://git.openjdk.org/jmc/pull/674#discussion_r2362629086
PR Review Comment: https://git.openjdk.org/jmc/pull/674#discussion_r2362633661


More information about the jmc-dev mailing list