< prev index next >

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

Print this page




  35 import java.text.MessageFormat;
  36 import java.util.Arrays;
  37 import java.util.Collection;
  38 import java.util.List;
  39 import java.util.concurrent.Callable;
  40 import java.util.concurrent.FutureTask;
  41 import java.util.concurrent.RunnableFuture;
  42 
  43 import org.openjdk.jmc.common.IDisplayable;
  44 import org.openjdk.jmc.common.item.Aggregators;
  45 import org.openjdk.jmc.common.item.IItemCollection;
  46 import org.openjdk.jmc.common.item.IItemFilter;
  47 import org.openjdk.jmc.common.item.ItemFilters;
  48 import org.openjdk.jmc.common.unit.IQuantity;
  49 import org.openjdk.jmc.common.unit.ITypedQuantity;
  50 import org.openjdk.jmc.common.unit.LinearUnit;
  51 import org.openjdk.jmc.common.unit.UnitLookup;
  52 import org.openjdk.jmc.common.util.IPreferenceValueProvider;
  53 import org.openjdk.jmc.common.util.TypedPreference;
  54 import org.openjdk.jmc.flightrecorder.JfrAttributes;

  55 import org.openjdk.jmc.flightrecorder.rules.IRule;
  56 import org.openjdk.jmc.flightrecorder.rules.Result;
  57 import org.openjdk.jmc.flightrecorder.rules.util.RulesToolkit;
  58 import org.openjdk.jmc.flightrecorder.rules.util.RulesToolkit.EventAvailability;
  59 
  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                 }
 101                 return new Result(this, 0, Messages.JfxPulseDurationRule_OK);
 102         }
 103 
 104         @Override
 105         public RunnableFuture<Result> evaluate(final IItemCollection items, final IPreferenceValueProvider valueProvider) {
 106                 FutureTask<Result> evaluationTask = new FutureTask<>(new Callable<Result>() {
 107                         @Override
 108                         public Result call() throws Exception {
 109                                 return getResult(items, valueProvider);
 110                         }




  35 import java.text.MessageFormat;
  36 import java.util.Arrays;
  37 import java.util.Collection;
  38 import java.util.List;
  39 import java.util.concurrent.Callable;
  40 import java.util.concurrent.FutureTask;
  41 import java.util.concurrent.RunnableFuture;
  42 
  43 import org.openjdk.jmc.common.IDisplayable;
  44 import org.openjdk.jmc.common.item.Aggregators;
  45 import org.openjdk.jmc.common.item.IItemCollection;
  46 import org.openjdk.jmc.common.item.IItemFilter;
  47 import org.openjdk.jmc.common.item.ItemFilters;
  48 import org.openjdk.jmc.common.unit.IQuantity;
  49 import org.openjdk.jmc.common.unit.ITypedQuantity;
  50 import org.openjdk.jmc.common.unit.LinearUnit;
  51 import org.openjdk.jmc.common.unit.UnitLookup;
  52 import org.openjdk.jmc.common.util.IPreferenceValueProvider;
  53 import org.openjdk.jmc.common.util.TypedPreference;
  54 import org.openjdk.jmc.flightrecorder.JfrAttributes;
  55 import org.openjdk.jmc.flightrecorder.ext.jfx.JfxVersionUtil.JavaFxEventAvailability;
  56 import org.openjdk.jmc.flightrecorder.rules.IRule;
  57 import org.openjdk.jmc.flightrecorder.rules.Result;
  58 import org.openjdk.jmc.flightrecorder.rules.util.RulesToolkit;

  59 
  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                 JavaFxEventAvailability availability = JfxVersionUtil.getAvailability(items);
  80                 if (availability == JavaFxEventAvailability.None) {
  81                         // Could possibly check the JVM version for better suggestions here, but not very important
  82                         return RulesToolkit.getEventAvailabilityResult(this, items,
  83                                         RulesToolkit.getEventAvailability(items, JfxConstants.TYPE_ID_PULSE_PHASE_12),
  84                                         JfxConstants.TYPE_ID_PULSE_PHASE_12);
  85                 }
  86 
  87                 IQuantity targetFramerate = valueProvider.getPreferenceValue(CONFIG_TARGET_FRAME_RATE);
  88                 ITypedQuantity<LinearUnit> targetPhaseTime = UnitLookup.MILLISECOND
  89                                 .quantity(1000.0 / targetFramerate.longValue());
  90                 IItemFilter longDurationFilter = ItemFilters.more(JfrAttributes.DURATION, targetPhaseTime);
  91                 IItemFilter longPhasesFilter = ItemFilters.and(longDurationFilter,
  92                                 ItemFilters.type(JfxVersionUtil.getPulseTypeId(availability)));
  93                 IQuantity longPhases = items.getAggregate(Aggregators.count(longPhasesFilter));
  94                 IQuantity allPhases = items
  95                                 .getAggregate(Aggregators.count(ItemFilters.type(JfxVersionUtil.getPulseTypeId(availability))));
  96                 if (longPhases != null && longPhases.doubleValue() > 0) {
  97                         double ratioOfLongPhases = longPhases.ratioTo(allPhases);
  98                         double mappedScore = RulesToolkit.mapExp100(ratioOfLongPhases, 0.05, 0.5);
  99                         mappedScore = mappedScore < 1 ? 1 : mappedScore;
 100                         return new Result(this, mappedScore,
 101                                         MessageFormat.format(Messages.JfxPulseDurationRule_WARNING,
 102                                                         UnitLookup.PERCENT_UNITY.quantity(ratioOfLongPhases).displayUsing(IDisplayable.AUTO),
 103                                                         targetPhaseTime.displayUsing(IDisplayable.AUTO)),
 104                                         MessageFormat.format(Messages.JfxPulseDurationRule_WARNING_LONG, targetFramerate));
 105                 }
 106                 return new Result(this, 0, Messages.JfxPulseDurationRule_OK);
 107         }
 108 
 109         @Override
 110         public RunnableFuture<Result> evaluate(final IItemCollection items, final IPreferenceValueProvider valueProvider) {
 111                 FutureTask<Result> evaluationTask = new FutureTask<>(new Callable<Result>() {
 112                         @Override
 113                         public Result call() throws Exception {
 114                                 return getResult(items, valueProvider);
 115                         }


< prev index next >