60 import org.openjdk.jmc.flightrecorder.rules.Severity;
61 import org.openjdk.jmc.flightrecorder.rules.jdk.messages.internal.Messages;
62 import org.openjdk.jmc.flightrecorder.rules.util.JfrRuleTopics;
63 import org.openjdk.jmc.flightrecorder.rules.util.RulesToolkit;
64 import org.openjdk.jmc.flightrecorder.rules.util.RulesToolkit.EventAvailability;
65
66 public class FileReadRule implements IRule {
67
68 public static final TypedPreference<IQuantity> READ_WARNING_LIMIT = new TypedPreference<>(
69 "io.file.read.warning.limit", //$NON-NLS-1$
70 Messages.getString(Messages.FileReadRule_CONFIG_WARNING_LIMIT),
71 Messages.getString(Messages.FileReadRule_CONFIG_WARNING_LIMIT_LONG), UnitLookup.TIMESPAN,
72 UnitLookup.MILLISECOND.quantity(4000));
73
74 private static final List<TypedPreference<?>> CONFIG_ATTRIBUTES = Arrays
75 .<TypedPreference<?>> asList(READ_WARNING_LIMIT);
76 private static final String RESULT_ID = "FileRead"; //$NON-NLS-1$
77
78 private Result getResult(IItemCollection items, IPreferenceValueProvider vp) {
79 EventAvailability eventAvailability = RulesToolkit.getEventAvailability(items, JdkTypeIDs.FILE_READ);
80 if (eventAvailability == EventAvailability.UNAVAILABLE || eventAvailability == EventAvailability.DISABLED) {
81 return RulesToolkit.getEventAvailabilityResult(this, items, eventAvailability, JdkTypeIDs.FILE_READ);
82 }
83
84 IQuantity warningLimit = vp.getPreferenceValue(READ_WARNING_LIMIT);
85 IQuantity infoLimit = warningLimit.multiply(0.5);
86
87 IItem longestEvent = items.apply(JdkFilters.FILE_READ)
88 .getAggregate(Aggregators.itemWithMax(JfrAttributes.DURATION));
89
90 // Aggregate of all file read events - if null, then we had no events
91 if (longestEvent == null) {
92 return new Result(this, 0, Messages.getString(Messages.FileReadRuleFactory_TEXT_NO_EVENTS), null,
93 JdkQueries.FILE_READ);
94 }
95 IQuantity longestDuration = RulesToolkit.getValue(longestEvent, JfrAttributes.DURATION);
96 String peakDuration = longestDuration.displayUsing(IDisplayable.AUTO);
97 double score = RulesToolkit.mapExp100(longestDuration.doubleValueIn(UnitLookup.SECOND),
98 infoLimit.doubleValueIn(UnitLookup.SECOND), warningLimit.doubleValueIn(UnitLookup.SECOND));
99
100 if (Severity.get(score) == Severity.WARNING || Severity.get(score) == Severity.INFO) {
|
60 import org.openjdk.jmc.flightrecorder.rules.Severity;
61 import org.openjdk.jmc.flightrecorder.rules.jdk.messages.internal.Messages;
62 import org.openjdk.jmc.flightrecorder.rules.util.JfrRuleTopics;
63 import org.openjdk.jmc.flightrecorder.rules.util.RulesToolkit;
64 import org.openjdk.jmc.flightrecorder.rules.util.RulesToolkit.EventAvailability;
65
66 public class FileReadRule implements IRule {
67
68 public static final TypedPreference<IQuantity> READ_WARNING_LIMIT = new TypedPreference<>(
69 "io.file.read.warning.limit", //$NON-NLS-1$
70 Messages.getString(Messages.FileReadRule_CONFIG_WARNING_LIMIT),
71 Messages.getString(Messages.FileReadRule_CONFIG_WARNING_LIMIT_LONG), UnitLookup.TIMESPAN,
72 UnitLookup.MILLISECOND.quantity(4000));
73
74 private static final List<TypedPreference<?>> CONFIG_ATTRIBUTES = Arrays
75 .<TypedPreference<?>> asList(READ_WARNING_LIMIT);
76 private static final String RESULT_ID = "FileRead"; //$NON-NLS-1$
77
78 private Result getResult(IItemCollection items, IPreferenceValueProvider vp) {
79 EventAvailability eventAvailability = RulesToolkit.getEventAvailability(items, JdkTypeIDs.FILE_READ);
80 if (eventAvailability == EventAvailability.UNKNOWN || eventAvailability == EventAvailability.DISABLED) {
81 return RulesToolkit.getEventAvailabilityResult(this, items, eventAvailability, JdkTypeIDs.FILE_READ);
82 }
83
84 IQuantity warningLimit = vp.getPreferenceValue(READ_WARNING_LIMIT);
85 IQuantity infoLimit = warningLimit.multiply(0.5);
86
87 IItem longestEvent = items.apply(JdkFilters.FILE_READ)
88 .getAggregate(Aggregators.itemWithMax(JfrAttributes.DURATION));
89
90 // Aggregate of all file read events - if null, then we had no events
91 if (longestEvent == null) {
92 return new Result(this, 0, Messages.getString(Messages.FileReadRuleFactory_TEXT_NO_EVENTS), null,
93 JdkQueries.FILE_READ);
94 }
95 IQuantity longestDuration = RulesToolkit.getValue(longestEvent, JfrAttributes.DURATION);
96 String peakDuration = longestDuration.displayUsing(IDisplayable.AUTO);
97 double score = RulesToolkit.mapExp100(longestDuration.doubleValueIn(UnitLookup.SECOND),
98 infoLimit.doubleValueIn(UnitLookup.SECOND), warningLimit.doubleValueIn(UnitLookup.SECOND));
99
100 if (Severity.get(score) == Severity.WARNING || Severity.get(score) == Severity.INFO) {
|