< prev index next >

application/org.openjdk.jmc.flightrecorder.ext.jfx/src/main/java/org/openjdk/jmc/flightrecorder/ext/jfx/JfxPulseDurationRule.java

Print this page




  60 public class JfxPulseDurationRule implements IRule {
  61         private static final String RESULT_ID = "pulseDuration"; //$NON-NLS-1$
  62 
  63         /*
  64          * TODO: Add detection for if the recording was from an embedded JVM for 33.34ms (30 Hz) target.
  65          * This preference is a workaround because it was deemed too time consuming to add automatic
  66          * detection.
  67          */
  68         // FIXME: This should really be in Hz, but could not find it in the UnitLookup. Using count for now.
  69         public static final TypedPreference<IQuantity> CONFIG_TARGET_FRAME_RATE = new TypedPreference<>(
  70                         "jfr.pulse.target.framerate", //$NON-NLS-1$
  71                         Messages.JfxPulseDurationRule_CAPTION_PREFERENCE_TARGET_FRAME_RATE,
  72                         Messages.JfxPulseDurationRule_DESCRIPTION_PREFERENCE_TARGET_FRAME_RATE, UnitLookup.NUMBER,
  73                         UnitLookup.NUMBER_UNITY.quantity(60));
  74 
  75         private static final List<TypedPreference<?>> CONFIG_ATTRIBUTES = Arrays
  76                         .<TypedPreference<?>> asList(CONFIG_TARGET_FRAME_RATE);
  77 
  78         private Result getResult(IItemCollection items, IPreferenceValueProvider valueProvider) {
  79                 EventAvailability eventAvailability = RulesToolkit.getEventAvailability(items, JfxConstants.JFX_PULSE_ID);
  80                 if (eventAvailability == EventAvailability.DISABLED || eventAvailability == EventAvailability.UNAVAILABLE
  81                                 || eventAvailability == EventAvailability.NONE) {
  82                         return RulesToolkit.getEventAvailabilityResult(this, items, eventAvailability, JfxConstants.JFX_PULSE_ID);
  83                 }
  84                 IQuantity targetFramerate = valueProvider.getPreferenceValue(CONFIG_TARGET_FRAME_RATE);
  85                 ITypedQuantity<LinearUnit> targetPhaseTime = UnitLookup.MILLISECOND
  86                                 .quantity(1000.0 / targetFramerate.longValue());
  87                 IItemFilter longDurationFilter = ItemFilters.more(JfrAttributes.DURATION, targetPhaseTime);
  88                 IItemFilter longPhasesFilter = ItemFilters.and(longDurationFilter, ItemFilters.type(JfxConstants.JFX_PULSE_ID));
  89                 IQuantity longPhases = items.getAggregate(Aggregators.count(longPhasesFilter));
  90                 IQuantity allPhases = items.getAggregate(Aggregators.count(ItemFilters.type(JfxConstants.JFX_PULSE_ID)));
  91                 if (longPhases != null && longPhases.doubleValue() > 0) {
  92                         double ratioOfLongPhases = longPhases.ratioTo(allPhases);
  93                         double mappedScore = RulesToolkit.mapExp100(ratioOfLongPhases, 0.05, 0.5);
  94                         mappedScore = mappedScore < 1 ? 1 : mappedScore;
  95                         return new Result(this, mappedScore,
  96                                         MessageFormat.format(Messages.JfxPulseDurationRule_WARNING,
  97                                                         UnitLookup.PERCENT_UNITY.quantity(ratioOfLongPhases).displayUsing(IDisplayable.AUTO),
  98                                                         targetPhaseTime.displayUsing(IDisplayable.AUTO)),
  99                                         MessageFormat.format(Messages.JfxPulseDurationRule_WARNING_LONG, targetFramerate));
 100                 }




  60 public class JfxPulseDurationRule implements IRule {
  61         private static final String RESULT_ID = "pulseDuration"; //$NON-NLS-1$
  62 
  63         /*
  64          * TODO: Add detection for if the recording was from an embedded JVM for 33.34ms (30 Hz) target.
  65          * This preference is a workaround because it was deemed too time consuming to add automatic
  66          * detection.
  67          */
  68         // FIXME: This should really be in Hz, but could not find it in the UnitLookup. Using count for now.
  69         public static final TypedPreference<IQuantity> CONFIG_TARGET_FRAME_RATE = new TypedPreference<>(
  70                         "jfr.pulse.target.framerate", //$NON-NLS-1$
  71                         Messages.JfxPulseDurationRule_CAPTION_PREFERENCE_TARGET_FRAME_RATE,
  72                         Messages.JfxPulseDurationRule_DESCRIPTION_PREFERENCE_TARGET_FRAME_RATE, UnitLookup.NUMBER,
  73                         UnitLookup.NUMBER_UNITY.quantity(60));
  74 
  75         private static final List<TypedPreference<?>> CONFIG_ATTRIBUTES = Arrays
  76                         .<TypedPreference<?>> asList(CONFIG_TARGET_FRAME_RATE);
  77 
  78         private Result getResult(IItemCollection items, IPreferenceValueProvider valueProvider) {
  79                 EventAvailability eventAvailability = RulesToolkit.getEventAvailability(items, JfxConstants.JFX_PULSE_ID);
  80                 if (eventAvailability == EventAvailability.DISABLED || eventAvailability == EventAvailability.UNKNOWN
  81                                 || eventAvailability == EventAvailability.NONE) {
  82                         return RulesToolkit.getEventAvailabilityResult(this, items, eventAvailability, JfxConstants.JFX_PULSE_ID);
  83                 }
  84                 IQuantity targetFramerate = valueProvider.getPreferenceValue(CONFIG_TARGET_FRAME_RATE);
  85                 ITypedQuantity<LinearUnit> targetPhaseTime = UnitLookup.MILLISECOND
  86                                 .quantity(1000.0 / targetFramerate.longValue());
  87                 IItemFilter longDurationFilter = ItemFilters.more(JfrAttributes.DURATION, targetPhaseTime);
  88                 IItemFilter longPhasesFilter = ItemFilters.and(longDurationFilter, ItemFilters.type(JfxConstants.JFX_PULSE_ID));
  89                 IQuantity longPhases = items.getAggregate(Aggregators.count(longPhasesFilter));
  90                 IQuantity allPhases = items.getAggregate(Aggregators.count(ItemFilters.type(JfxConstants.JFX_PULSE_ID)));
  91                 if (longPhases != null && longPhases.doubleValue() > 0) {
  92                         double ratioOfLongPhases = longPhases.ratioTo(allPhases);
  93                         double mappedScore = RulesToolkit.mapExp100(ratioOfLongPhases, 0.05, 0.5);
  94                         mappedScore = mappedScore < 1 ? 1 : mappedScore;
  95                         return new Result(this, mappedScore,
  96                                         MessageFormat.format(Messages.JfxPulseDurationRule_WARNING,
  97                                                         UnitLookup.PERCENT_UNITY.quantity(ratioOfLongPhases).displayUsing(IDisplayable.AUTO),
  98                                                         targetPhaseTime.displayUsing(IDisplayable.AUTO)),
  99                                         MessageFormat.format(Messages.JfxPulseDurationRule_WARNING_LONG, targetFramerate));
 100                 }


< prev index next >