< prev index next >

core/org.openjdk.jmc.flightrecorder.rules.jdk/src/main/java/org/openjdk/jmc/flightrecorder/rules/jdk/memory/AllocationByThreadRule.java

Print this page




  56 import org.openjdk.jmc.flightrecorder.rules.jdk.dataproviders.StacktraceDataProvider;
  57 import org.openjdk.jmc.flightrecorder.rules.jdk.messages.internal.Messages;
  58 import org.openjdk.jmc.flightrecorder.rules.util.JfrRuleTopics;
  59 import org.openjdk.jmc.flightrecorder.rules.util.RulesToolkit;
  60 import org.openjdk.jmc.flightrecorder.rules.util.RulesToolkit.EventAvailability;
  61 import org.openjdk.jmc.flightrecorder.stacktrace.FrameSeparator;
  62 import org.openjdk.jmc.flightrecorder.stacktrace.FrameSeparator.FrameCategorization;
  63 import org.openjdk.jmc.flightrecorder.stacktrace.StacktraceModel;
  64 import org.openjdk.jmc.flightrecorder.stacktrace.StacktraceModel.Fork;
  65 import org.owasp.encoder.Encode;
  66 
  67 public class AllocationByThreadRule implements IRule {
  68         private static final String THREAD_RESULT_ID = "Allocations.thread"; //$NON-NLS-1$
  69 
  70         private Result getResult(IItemCollection items, IPreferenceValueProvider valueProvider) {
  71                 EventAvailability eventAvailabilityInside = RulesToolkit.getEventAvailability(items,
  72                                 JdkTypeIDs.ALLOC_INSIDE_TLAB);
  73                 EventAvailability eventAvailabilityOutside = RulesToolkit.getEventAvailability(items,
  74                                 JdkTypeIDs.ALLOC_OUTSIDE_TLAB);
  75                 if (!RulesToolkit.isEventsEnabled(eventAvailabilityInside, eventAvailabilityOutside)) {
  76                         return RulesToolkit.getNotApplicableResult(this,
  77                                         MessageFormat.format(Messages.getString(Messages.General_RULE_REQUIRES_ALL_EVENT_TYPES_ENABLED),
  78                                                         JdkTypeIDs.ALLOC_INSIDE_TLAB + "," + JdkTypeIDs.ALLOC_OUTSIDE_TLAB));
  79                 }
  80                 if (!(eventAvailabilityInside == EventAvailability.AVAILABLE
  81                                 || eventAvailabilityOutside == EventAvailability.AVAILABLE)) {
  82                         return RulesToolkit.getNotApplicableResult(this,
  83                                         MessageFormat.format(Messages.getString(Messages.General_RULE_REQUIRES_EVENTS_FROM_ONE_OF_MANY),
  84                                                         JdkTypeIDs.ALLOC_INSIDE_TLAB + "," + JdkTypeIDs.ALLOC_OUTSIDE_TLAB));
  85                 }
  86 
  87                 List<IntEntry<IMCThread>> entries = RulesToolkit.calculateGroupingScore(items.apply(JdkFilters.ALLOC_ALL),
  88                                 JfrAttributes.EVENT_THREAD);
  89                 double balance = RulesToolkit.calculateBalanceScore(entries);
  90                 IntEntry<IMCThread> mostSignificant = entries.get(entries.size() - 1);
  91                 // FIXME: Configuration attribute instead of hard coded 1000 tlabs => relevance 50
  92                 double relevance = RulesToolkit.mapExp100Y(mostSignificant.getValue(), 1000, 50);
  93                 double score = balance * relevance * 0.74; // ceiling at 74;
  94 
  95                 IItemFilter significantFilter = ItemFilters.and(JdkFilters.ALLOC_ALL,
  96                                 ItemFilters.equals(JfrAttributes.EVENT_THREAD, mostSignificant.getKey()));
  97                 StacktraceModel stacktraceModel = new StacktraceModel(false,
  98                                 new FrameSeparator(FrameCategorization.METHOD, false), items.apply(significantFilter));
  99                 Fork rootFork = stacktraceModel.getRootFork();
 100                 String relevantTraceHtmlList = rootFork.getBranchCount() == 0
 101                                 ? Messages.getString(Messages.General_NO_STACK_TRACE_AVAILABLE)
 102                                 : StacktraceDataProvider.getRelevantTraceHtmlList(rootFork.getBranch(0), rootFork.getItemsInFork());
 103                 String message = MessageFormat.format(Messages.getString(Messages.AllocationByThreadRule_TEXT_MESSAGE),
 104                                 Encode.forHtml(mostSignificant.getKey().getThreadName()), relevantTraceHtmlList);




  56 import org.openjdk.jmc.flightrecorder.rules.jdk.dataproviders.StacktraceDataProvider;
  57 import org.openjdk.jmc.flightrecorder.rules.jdk.messages.internal.Messages;
  58 import org.openjdk.jmc.flightrecorder.rules.util.JfrRuleTopics;
  59 import org.openjdk.jmc.flightrecorder.rules.util.RulesToolkit;
  60 import org.openjdk.jmc.flightrecorder.rules.util.RulesToolkit.EventAvailability;
  61 import org.openjdk.jmc.flightrecorder.stacktrace.FrameSeparator;
  62 import org.openjdk.jmc.flightrecorder.stacktrace.FrameSeparator.FrameCategorization;
  63 import org.openjdk.jmc.flightrecorder.stacktrace.StacktraceModel;
  64 import org.openjdk.jmc.flightrecorder.stacktrace.StacktraceModel.Fork;
  65 import org.owasp.encoder.Encode;
  66 
  67 public class AllocationByThreadRule implements IRule {
  68         private static final String THREAD_RESULT_ID = "Allocations.thread"; //$NON-NLS-1$
  69 
  70         private Result getResult(IItemCollection items, IPreferenceValueProvider valueProvider) {
  71                 EventAvailability eventAvailabilityInside = RulesToolkit.getEventAvailability(items,
  72                                 JdkTypeIDs.ALLOC_INSIDE_TLAB);
  73                 EventAvailability eventAvailabilityOutside = RulesToolkit.getEventAvailability(items,
  74                                 JdkTypeIDs.ALLOC_OUTSIDE_TLAB);
  75                 if (!RulesToolkit.isEventsEnabled(eventAvailabilityInside, eventAvailabilityOutside)) {
  76                         return RulesToolkit.getEventAvailabilityResult(this, items,
  77                                         RulesToolkit.getLeastAvailable(eventAvailabilityInside, eventAvailabilityOutside),
  78                                         JdkTypeIDs.ALLOC_INSIDE_TLAB, JdkTypeIDs.ALLOC_OUTSIDE_TLAB);
  79                 }
  80                 if (!(eventAvailabilityInside == EventAvailability.AVAILABLE
  81                                 || eventAvailabilityOutside == EventAvailability.AVAILABLE)) {
  82                         return RulesToolkit.getNotApplicableResult(this,
  83                                         MessageFormat.format(Messages.getString(Messages.General_RULE_REQUIRES_EVENTS_FROM_ONE_OF_MANY),
  84                                                         JdkTypeIDs.ALLOC_INSIDE_TLAB + ", " + JdkTypeIDs.ALLOC_OUTSIDE_TLAB));
  85                 }
  86 
  87                 List<IntEntry<IMCThread>> entries = RulesToolkit.calculateGroupingScore(items.apply(JdkFilters.ALLOC_ALL),
  88                                 JfrAttributes.EVENT_THREAD);
  89                 double balance = RulesToolkit.calculateBalanceScore(entries);
  90                 IntEntry<IMCThread> mostSignificant = entries.get(entries.size() - 1);
  91                 // FIXME: Configuration attribute instead of hard coded 1000 tlabs => relevance 50
  92                 double relevance = RulesToolkit.mapExp100Y(mostSignificant.getValue(), 1000, 50);
  93                 double score = balance * relevance * 0.74; // ceiling at 74;
  94 
  95                 IItemFilter significantFilter = ItemFilters.and(JdkFilters.ALLOC_ALL,
  96                                 ItemFilters.equals(JfrAttributes.EVENT_THREAD, mostSignificant.getKey()));
  97                 StacktraceModel stacktraceModel = new StacktraceModel(false,
  98                                 new FrameSeparator(FrameCategorization.METHOD, false), items.apply(significantFilter));
  99                 Fork rootFork = stacktraceModel.getRootFork();
 100                 String relevantTraceHtmlList = rootFork.getBranchCount() == 0
 101                                 ? Messages.getString(Messages.General_NO_STACK_TRACE_AVAILABLE)
 102                                 : StacktraceDataProvider.getRelevantTraceHtmlList(rootFork.getBranch(0), rootFork.getItemsInFork());
 103                 String message = MessageFormat.format(Messages.getString(Messages.AllocationByThreadRule_TEXT_MESSAGE),
 104                                 Encode.forHtml(mostSignificant.getKey().getThreadName()), relevantTraceHtmlList);


< prev index next >