8221569: JFR tool produces incorrect output when both --categories and --events are specified
Co-authored-by: Erik Gahlin <erik.gahlin@oracle.com> Reviewed-by: mgronlun
This commit is contained in:
parent
1355621a42
commit
032fff8042
@ -107,13 +107,23 @@ final class Print extends Command {
|
||||
int stackDepth = 5;
|
||||
EventPrintWriter eventWriter = null;
|
||||
int optionCount = options.size();
|
||||
boolean foundEventFilter = false;
|
||||
boolean foundCategoryFilter = false;
|
||||
while (optionCount > 0) {
|
||||
if (acceptFilterOption(options, "--events")) {
|
||||
if (foundEventFilter) {
|
||||
throw new UserSyntaxException("use --events event1,event2,event3 to include multiple events");
|
||||
}
|
||||
foundEventFilter = true;
|
||||
String filter = options.remove();
|
||||
warnForWildcardExpansion("--events", filter);
|
||||
eventFilter = addEventFilter(filter, eventFilter);
|
||||
}
|
||||
if (acceptFilterOption(options, "--categories")) {
|
||||
if (foundCategoryFilter) {
|
||||
throw new UserSyntaxException("use --categories category1,category2 to include multiple categories");
|
||||
}
|
||||
foundCategoryFilter = true;
|
||||
String filter = options.remove();
|
||||
warnForWildcardExpansion("--categories", filter);
|
||||
eventFilter = addCategoryFilter(filter, eventFilter);
|
||||
@ -137,6 +147,8 @@ final class Print extends Command {
|
||||
}
|
||||
if (optionCount == options.size()) {
|
||||
// No progress made
|
||||
checkCommonError(options, "--event", "--events");
|
||||
checkCommonError(options, "--category", "--categories");
|
||||
throw new UserSyntaxException("unknown option " + options.peek());
|
||||
}
|
||||
optionCount = options.size();
|
||||
@ -157,6 +169,12 @@ final class Print extends Command {
|
||||
pw.flush();
|
||||
}
|
||||
|
||||
private void checkCommonError(Deque<String> options, String typo, String correct) throws UserSyntaxException {
|
||||
if (typo.equals(options.peek())) {
|
||||
throw new UserSyntaxException("unknown option " + typo + ", did you mean " + correct + "?");
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean acceptFormatterOption(Deque<String> options, EventPrintWriter eventWriter, String expected) throws UserSyntaxException {
|
||||
if (expected.equals(options.peek())) {
|
||||
if (eventWriter != null) {
|
||||
@ -179,7 +197,7 @@ final class Print extends Command {
|
||||
|
||||
private static Predicate<EventType> addCategoryFilter(String filterText, Predicate<EventType> eventFilter) throws UserSyntaxException {
|
||||
List<String> filters = explodeFilter(filterText);
|
||||
return recurseIfPossible(eventType -> {
|
||||
Predicate<EventType> newFilter = recurseIfPossible(eventType -> {
|
||||
for (String category : eventType.getCategoryNames()) {
|
||||
for (String filter : filters) {
|
||||
if (match(category, filter)) {
|
||||
@ -192,6 +210,7 @@ final class Print extends Command {
|
||||
}
|
||||
return false;
|
||||
});
|
||||
return eventFilter == null ? newFilter : eventFilter.or(newFilter);
|
||||
}
|
||||
|
||||
private static String acronomify(String multipleWords) {
|
||||
@ -210,7 +229,7 @@ final class Print extends Command {
|
||||
|
||||
private static Predicate<EventType> addEventFilter(String filterText, final Predicate<EventType> eventFilter) throws UserSyntaxException {
|
||||
List<String> filters = explodeFilter(filterText);
|
||||
return recurseIfPossible(eventType -> {
|
||||
Predicate<EventType> newFilter = recurseIfPossible(eventType -> {
|
||||
for (String filter : filters) {
|
||||
String fullEventName = eventType.getName();
|
||||
if (match(fullEventName, filter)) {
|
||||
@ -223,6 +242,7 @@ final class Print extends Command {
|
||||
}
|
||||
return false;
|
||||
});
|
||||
return eventFilter == null ? newFilter : eventFilter.or(newFilter);
|
||||
}
|
||||
|
||||
private static boolean match(String text, String filter) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user