public class RulesToolkit
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
RulesToolkit.EventAvailability
Knowledge about the state of affairs of an event type in an IItemCollection.
|
static class |
RulesToolkit.RequiredEventsBuilder |
private static class |
RulesToolkit.RuleEvaluator |
Modifier and Type | Field and Description |
---|---|
private static IAggregator<IQuantity,?> |
EARLIEST_END_TIME |
private static IAggregator<IQuantity,?> |
EARLIEST_START_TIME |
private static IAggregator<IQuantity,?> |
LATEST_END_TIME |
private static LinearUnit |
MEBIBYTES |
private static java.lang.String |
REC_SETTING_NAME_ENABLED |
static java.lang.String |
REC_SETTING_NAME_PERIOD |
private static java.lang.String |
REC_SETTING_NAME_THRESHOLD |
static java.lang.String |
REC_SETTING_PERIOD_EVERY_CHUNK |
private static IAccessorFactory<java.lang.String> |
TYPE_NAME_ACCESSOR_FACTORY |
private static java.util.regex.Pattern |
VERSION_PATTERN
Matches strings containing an identifiable version number as presented in a JVM info event.
|
Constructor and Description |
---|
RulesToolkit() |
Modifier and Type | Method and Description |
---|---|
static <T> double |
calculateBalanceScore(java.util.List<MapToolkit.IntEntry<T>> array)
Calculates a balance for entries, where later elements get a higher relevance than earlier
elements.
|
static <T> java.util.List<MapToolkit.IntEntry<T>> |
calculateGroupingScore(IItemCollection items,
IAccessorFactory<T> accessorFactory)
Each group is represented by the number of elements that belong in that group, elements are
grouped by accessor value.
|
private static IItemFilter |
createEnablementFilter(boolean enabled,
java.lang.String... typeIds) |
static IItemFilter |
createRangeFilter(IItem item)
Creates a range filter for an event.
|
static TimeRangeThreadFilter |
createThreadsAndRangesFilter(IItemCollection items)
Creates a thread and range filter for a set of related events.
|
static java.util.Map<IRule,java.util.concurrent.Future<IResult>> |
evaluateParallel(java.util.Collection<IRule> rules,
IItemCollection items,
IPreferenceValueProvider preferences,
int nThreads)
Evaluates a collection of rules in parallel threads.
|
static java.lang.String |
findMatches(java.lang.String typeId,
IItemCollection items,
IAttribute<java.lang.String> attribute,
java.lang.String match,
boolean ignoreCase)
Finds items of a specific type where the given attribute has a value matching that of the
provided match string.
|
static java.util.Collection<java.lang.String> |
getAllTopics()
Retrieves all topics that have rules associated with them.
|
private static java.util.Set<java.lang.String> |
getAvailableTypeIds(IItemCollection items) |
private static java.lang.String |
getDisabledEventTypeNames(IItemCollection items,
java.lang.String... typeIds) |
static IQuantity |
getDuration(IItem item)
Convenience method to get the duration value from a specific event.
|
static IQuantity |
getDurationInWindow(IQuantity windowStart,
IQuantity windowEnd,
IItem item)
Get the duration for item within the specified window
|
static IQuantity |
getEarliestEndTime(IItemCollection items)
Returns the earliest end time in the provided item collection.
|
static IQuantity |
getEarliestStartTime(IItemCollection items)
Returns the earliest start time in the provided item collection.
|
static java.lang.String |
getEnabledEventTypesRecommendation(IItemCollection items,
java.lang.String... typeIds)
Creates a text message informing that event types are recommended
|
static IQuantity |
getEndTime(IItem item)
Convenience method to get the end time value from a specific event.
|
static RulesToolkit.EventAvailability |
getEventAvailability(IItemCollection items,
java.lang.String... typeIds)
Checks the event availability for the event types.
|
private static java.lang.String |
getEventTypeNames(IItemCollection items) |
static java.util.Map<java.lang.String,java.lang.String> |
getFlightRecorderOptions(IItemCollection items)
Convenience method for parsing the -XX:FlightRecorderOptions JVM flag.
|
private static IQuantity |
getItemRange(IItemCollection items) |
(package private) static java.lang.String |
getJavaCommandHelpLink(JavaVersion javaVersion) |
static JavaVersion |
getJavaSpecVersion(IItemCollection items)
Gets the Java version for the recording the provided
IItemCollection represents. |
static JavaVersion |
getJavaVersion(IItemCollection items) |
static JavaVersion |
getJavaVersion(java.lang.String vmInfoVersionString) |
static IQuantity |
getLatestEndTime(IItemCollection items)
Returns the latest end time in the provided item collection.
|
static RulesToolkit.EventAvailability |
getLeastAvailable(RulesToolkit.EventAvailability... availabilites)
Returns the least available EventAvailability from the ones provided.
|
static IResult |
getMissingAttributeResult(IRule rule,
IType<IItem> type,
IAttribute<?> attribute,
IPreferenceValueProvider vp)
Gets a
IResult object representing a not applicable result due to a missing
attribute. |
static IResult |
getNotApplicableResult(IRule rule,
IPreferenceValueProvider vp,
java.lang.String message)
Creates a
IResult object with a generic not applicable (N/A) result for a given rule
with a specified message. |
private static IResult |
getNotApplicableResult(IRule rule,
IPreferenceValueProvider vp,
java.lang.String shortMessage,
java.lang.String longMessage)
Creates a
IResult object with a generic not applicable (N/A) result for a given rule
with a specified message. |
private static <T> T |
getOptionalValue(IItem item,
IAccessorFactory<T> attribute)
Returns the value, or null if no accessor is available.
|
static java.lang.String |
getPeriodIfGreaterThan(IItemCollection items,
IQuantity minPeriod,
java.lang.String... typeIds)
If possible, gets the longest period setting that is longer than the specified minimum period
for the given event types.
|
private static java.util.Set<java.lang.String> |
getPeriodSettings(IItemCollection items,
java.lang.String... typeIds) |
static java.lang.String |
getSecondFrameInMostCommonTrace(IItemCollection items)
Gets the second frame in the most common stack trace.
|
static IQuantity |
getSettingMaxPeriod(IItemCollection items,
java.lang.String... typeIds)
Gets the maximum period setting for the specified event types in the given item collection.
|
private static IQuantity |
getSettingMaxPeriod(java.lang.Iterable<java.lang.String> settingsValues) |
static IItemFilter |
getSettingsFilter(java.lang.String settingsName,
java.lang.String... typeIds)
Gets a filter for a specific setting for the provided types.
|
static java.lang.String |
getShortRecordingInfo(IItemCollection items,
IQuantity shortRecordingLimit)
Checks if the timerange spanned by the items is shorter than the limit, and returns a
informative text message if that is the case.
|
static IQuantity |
getStartTime(IItem item)
Convenience method for getting the start time value from a specific event.
|
static IMCThread |
getThread(IItem item)
Convenience method to get the event thread value from a specific event.
|
static IResult |
getTooFewEventsResult(IRule rule,
IPreferenceValueProvider vp)
|
static IType<IItem> |
getType(IItemCollection items,
java.lang.String typeId)
Gets the
IType representation of a specific event type in an IItemCollection . |
static java.lang.String |
getTypesWithZeroThreshold(IItemCollection items,
java.lang.String... typeIds)
Returns a string describing the subset of event types given which have no duration threshold
set.
|
static <T> T |
getValue(IItem item,
IAccessorFactory<T> attribute)
Gets the value of a certain attribute for a given item
|
private static boolean |
hasEvents(IItemCollection items,
java.lang.String... typeIds)
Returns true if precisely all of the event types have events.
|
private static boolean |
internalHasEvents(IItemCollection items,
java.lang.String typeId) |
private static boolean |
isEventsDisabled(IItemCollection items,
java.lang.String... typeIds)
This method checks if the provided event types were explicitly disabled by checking the
recording setting events.
|
static boolean |
isEventsEnabled(IItemCollection items,
java.lang.String... typeIds)
This method checks if the provided event types were explicitly enabled by checking the
recording setting events.
|
static boolean |
isEventsEnabled(RulesToolkit.EventAvailability... eventAvailabilities)
This method returns false if any
RulesToolkit.EventAvailability is disabled or unavailable. |
private static boolean |
isEventsKnown(IItemCollection items,
java.lang.String... typeIds)
Checks if the event types are known in the collection.
|
static double |
leastSquareMemory(java.util.Iterator<? extends IItem> items,
IMemberAccessor<IQuantity,IItem> timeField,
IMemberAccessor<IQuantity,IItem> memField) |
static double |
mapExp(double value,
double ceiling,
double x1,
double y1) |
private static double |
mapExp(double value,
double ceiling,
double x1,
double y1,
double x2,
double y2) |
static double |
mapExp100(double value,
double x1)
An exponential mapping from 0/infinity to 0/100 passing through 75 at limit.
|
static double |
mapExp100(double value,
double x1,
double x2)
An exponential mapping from 0/infinity to 0/100 passing through 25 and 75 at limits.
|
static double |
mapExp100Y(double value,
double x1,
double y1)
An exponential mapping from 0/infinity to 0/100 passing through y1 at x1.
|
static double |
mapExp74(double value,
double x1)
An exponential mapping from 0/infinity to 0/74 passing through 25 at limit.
|
static double |
mapLin100(double value,
double x1,
double x2)
An multi-linear mapping from 0/1 to 0/100 passing through 25 and 75 at limits.
|
static double |
mapSigmoid(double input,
double minimum,
double maximum,
double lowCurveFit,
double inflectionPoint,
double highCurveFit)
Maps the input value into a value between the minimum and maximum values (exclusive) using a
sigmoidal curve with the given parameters.
|
static boolean |
matchesEventAvailabilityMap(IItemCollection items,
java.util.Map<java.lang.String,RulesToolkit.EventAvailability> availabilityMap) |
static IQuantity |
parsePersistedJvmTimespan(java.lang.String persistedValue)
Converts a value persisted as a string by the JVM into an
IQuantity . |
static java.util.Map<java.lang.String,java.lang.Integer> |
sortMap(java.util.Map<java.lang.String,java.lang.Integer> map,
boolean sortAscending)
Sorts map according to values.
|
static IQuantity |
toRatioPercent(IQuantity antecedent,
IQuantity consequent)
Calculates the ratio between two
IQuantity values of compatible, linear kind and
returns it represented as a percentage. |
static java.lang.String |
toRatioPercentString(IQuantity antecedent,
IQuantity consequent)
Same calculation as
toRatioPercent(IQuantity, IQuantity) but it returns
the percentage as a string instead. |
private static final java.lang.String REC_SETTING_NAME_ENABLED
private static final java.lang.String REC_SETTING_NAME_THRESHOLD
public static final java.lang.String REC_SETTING_NAME_PERIOD
public static final java.lang.String REC_SETTING_PERIOD_EVERY_CHUNK
private static final IAccessorFactory<java.lang.String> TYPE_NAME_ACCESSOR_FACTORY
private static final LinearUnit MEBIBYTES
private static final java.util.regex.Pattern VERSION_PATTERN
private static final IAggregator<IQuantity,?> EARLIEST_START_TIME
private static final IAggregator<IQuantity,?> EARLIEST_END_TIME
private static final IAggregator<IQuantity,?> LATEST_END_TIME
public static double leastSquareMemory(java.util.Iterator<? extends IItem> items, IMemberAccessor<IQuantity,IItem> timeField, IMemberAccessor<IQuantity,IItem> memField)
public static java.lang.String findMatches(java.lang.String typeId, IItemCollection items, IAttribute<java.lang.String> attribute, java.lang.String match, boolean ignoreCase)
typeId
- the event type to find matches initems
- the set of items to searchattribute
- the attribute to matchmatch
- the pattern to findignoreCase
- whether or not to ignore case when matchingpublic static <T> T getValue(IItem item, IAccessorFactory<T> attribute)
item
- the item to get the attribute fromattribute
- the attribute to getpublic static IItemFilter getSettingsFilter(java.lang.String settingsName, java.lang.String... typeIds)
settingsName
- the specific setting to findtypeIds
- the ids of the types to find the setting forpublic static IQuantity getSettingMaxPeriod(IItemCollection items, java.lang.String... typeIds)
items
- the items to find the period setting intypeIds
- the event type ids to find settings forpublic static java.lang.String getPeriodIfGreaterThan(IItemCollection items, IQuantity minPeriod, java.lang.String... typeIds)
items
- the item collection to search throughminPeriod
- the minimum period settingtypeIds
- the event type ids to find the period setting forminPeriod
, or
null
if all periods are shorter than minPeriod
public static IQuantity parsePersistedJvmTimespan(java.lang.String persistedValue) throws QuantityConversionException
IQuantity
.persistedValue
- the persisted value to convertIQuantity
QuantityConversionException
public static java.lang.String getTypesWithZeroThreshold(IItemCollection items, java.lang.String... typeIds)
items
- the item collection to searchtypeIds
- the event type ids to find thresholds forpublic static boolean isEventsEnabled(IItemCollection items, java.lang.String... typeIds)
items
- the collection to check.typeIds
- the identifiers for the event types to check.public static boolean isEventsEnabled(RulesToolkit.EventAvailability... eventAvailabilities)
RulesToolkit.EventAvailability
is disabled or unavailable.
Otherwise true.eventAvailabilities
- the RulesToolkit.EventAvailability
to checkRulesToolkit.EventAvailability
is disabled or unavailable. Otherwise true.private static boolean isEventsDisabled(IItemCollection items, java.lang.String... typeIds)
items
- the collection to check.typeIds
- the identifiers for the event types to check.public static RulesToolkit.EventAvailability getEventAvailability(IItemCollection items, java.lang.String... typeIds)
Care should be taken when used with multiple typeIds. Use it when all of the provided typeIds are expected to have the same availability; if mixed, the lowest common availability for all types will be returned.
items
- the collection to checktypeIds
- the type identifiers to checkpublic static boolean matchesEventAvailabilityMap(IItemCollection items, java.util.Map<java.lang.String,RulesToolkit.EventAvailability> availabilityMap)
public static RulesToolkit.EventAvailability getLeastAvailable(RulesToolkit.EventAvailability... availabilites)
RulesToolkit.EventAvailability
.private static boolean isEventsKnown(IItemCollection items, java.lang.String... typeIds)
items
- the collection to checktypeIds
- the event types to checkprivate static boolean hasEvents(IItemCollection items, java.lang.String... typeIds)
items
- the events.typeIds
- the identifiers of the event types to check.public static IResult getTooFewEventsResult(IRule rule, IPreferenceValueProvider vp)
IResult
object for the given IRule
object representing a result
where there are too few events to properly evaluate a rule.rule
- the rule to create a IResult
object forpublic static IResult getNotApplicableResult(IRule rule, IPreferenceValueProvider vp, java.lang.String message)
IResult
object with a generic not applicable (N/A) result for a given rule
with a specified message.rule
- the rule to create a IResult
object formessage
- the description of the resultprivate static IResult getNotApplicableResult(IRule rule, IPreferenceValueProvider vp, java.lang.String shortMessage, java.lang.String longMessage)
IResult
object with a generic not applicable (N/A) result for a given rule
with a specified message.rule
- the rule to create a IResult
object forshortMessage
- the description of the result, as a short descriptionlongMessage
- a longer version of the description, used to explain in more detail why the rule
could not be evaluatedpublic static java.lang.String getEnabledEventTypesRecommendation(IItemCollection items, java.lang.String... typeIds)
items
- the events.typeIds
- the identifiers of the event types to check.public static JavaVersion getJavaSpecVersion(IItemCollection items)
IItemCollection
represents.items
- the recording to find the version ofpublic static JavaVersion getJavaVersion(IItemCollection items)
items
- the items to look for the JVM version in.public static double mapExp74(double value, double x1)
value
- Input value. Negative values will be treated as zero.x1
- Return 25 if value is equal to this. Must be more than zero.public static double mapExp100(double value, double x1)
value
- Input value. Negative values will be treated as zero.x1
- Return 75 if value is equal to this. Must be more than zero.public static double mapExp100Y(double value, double x1, double y1)
value
- Input value. Negative values will be treated as zero.x1
- Return y1 if value is equal to this. Must be more than zero.y1
- Return value at x1. Must be more than zero and less than 100.public static double mapExp100(double value, double x1, double x2)
value
- Input value. Negative values will be treated as zero.x1
- Return 25 if value is equal to this. Must be more than zero.x2
- Return 75 if value is equal to this. Must be more than x1.public static double mapExp(double value, double ceiling, double x1, double y1)
value
- Input value. Negative values will be treated as zero.ceiling
- Max return value. Must be more than zero.x1
- Return y1 if value is equal to this. Must be more than zero.y1
- Return value at x1. Must be more than zero and less than ceiling.private static double mapExp(double value, double ceiling, double x1, double y1, double x2, double y2)
value
- Input value. Negative values will be treated as zero.ceiling
- Max return value. Must be more than zero.x1
- Return y1 if value is equal to this. Must be more than zero.y1
- Return y1 at x1. Must be more than zero and less than y2.x2
- Return y2 if value is equal to this. Must be more than x1.y2
- Return y2 at x2. Must be more than y1 and less than ceiling.public static double mapLin100(double value, double x1, double x2)
value
- Input value. Negative values will be treated as zero.x1
- Return 25 if value is equal to this. Must be more than zero.x2
- Return 75 if value is equal to this. Must be more than x1.public static <T> java.util.List<MapToolkit.IntEntry<T>> calculateGroupingScore(IItemCollection items, IAccessorFactory<T> accessorFactory)
For example, the items {A, B, C, A, B, A, A} will become {1, 2, 4}
items
- input itemsaccessorFactory
- a factory that provides accessors for the input item typespublic static <T> double calculateBalanceScore(java.util.List<MapToolkit.IntEntry<T>> array)
For example the values 1, 1, 2, 5 will get the total score 5/9/1 + 2/9/2 + 1/9/3 + 1/9/4
array
- input valuespublic static IQuantity getDurationInWindow(IQuantity windowStart, IQuantity windowEnd, IItem item)
windowStart
- window startwindowEnd
- window enditem
- item to get duration forpublic static double mapSigmoid(double input, double minimum, double maximum, double lowCurveFit, double inflectionPoint, double highCurveFit)
input
- the value to mapminimum
- the maximum value to map to (exclusive)maximum
- the minimum value to map to (exclusive)lowCurveFit
- fitting parameter for the lower end of the curveinflectionPoint
- the inflection point of the curve (where input leads to 1/3 between min and max)highCurveFit
- fitting parameter for the higher end of the curveprivate static IQuantity getSettingMaxPeriod(java.lang.Iterable<java.lang.String> settingsValues)
private static java.util.Set<java.lang.String> getPeriodSettings(IItemCollection items, java.lang.String... typeIds)
private static java.lang.String getDisabledEventTypeNames(IItemCollection items, java.lang.String... typeIds)
private static java.lang.String getEventTypeNames(IItemCollection items)
private static IItemFilter createEnablementFilter(boolean enabled, java.lang.String... typeIds)
private static boolean internalHasEvents(IItemCollection items, java.lang.String typeId)
private static java.util.Set<java.lang.String> getAvailableTypeIds(IItemCollection items)
public static JavaVersion getJavaVersion(java.lang.String vmInfoVersionString)
vmInfoVersionString
- the JVM version information as presented in the VM information events, containing
both the JVM and JDK version numbers.static java.lang.String getJavaCommandHelpLink(JavaVersion javaVersion)
public static IType<IItem> getType(IItemCollection items, java.lang.String typeId)
IType
representation of a specific event type in an IItemCollection
.items
- the items to find the type intypeId
- the event type id to find the type object ofpublic static IResult getMissingAttributeResult(IRule rule, IType<IItem> type, IAttribute<?> attribute, IPreferenceValueProvider vp)
IResult
object representing a not applicable result due to a missing
attribute.rule
- the rule which could not be evaluatedtype
- the type of the item which is missing a required attributeattribute
- the attribute that is missingpublic static TimeRangeThreadFilter createThreadsAndRangesFilter(IItemCollection items)
items
- a collection of related items.public static IItemFilter createRangeFilter(IItem item)
item
- the event for which to create the range filterpublic static IQuantity getStartTime(IItem item)
item
- the event to get the start time frompublic static IQuantity getEndTime(IItem item)
item
- the event to get the end time frompublic static IQuantity getDuration(IItem item)
item
- the event to get the duration frompublic static IMCThread getThread(IItem item)
item
- the event to get the thread value fromprivate static <T> T getOptionalValue(IItem item, IAccessorFactory<T> attribute)
public static IQuantity toRatioPercent(IQuantity antecedent, IQuantity consequent)
IQuantity
values of compatible, linear kind and
returns it represented as a percentage.antecedent
- the antecedent (numerator) valueconsequent
- the consequent (denominator) valuepublic static java.lang.String toRatioPercentString(IQuantity antecedent, IQuantity consequent)
toRatioPercent(IQuantity, IQuantity)
but it returns
the percentage as a string instead.antecedent
- the antecedent (numerator) valueconsequent
- the consequent (denominator) valuepublic static java.util.Collection<java.lang.String> getAllTopics()
public static java.util.Map<IRule,java.util.concurrent.Future<IResult>> evaluateParallel(java.util.Collection<IRule> rules, IItemCollection items, IPreferenceValueProvider preferences, int nThreads)
future
results that are scheduled to run using the specified number of
threads.
You can use a single threaded loop over the returned futures to get
the
results.
If evaluation of a rule fails, then the get method of the corresponding future will throw an
ExecutionException
.
rules
- rules to runitems
- items to evaluatepreferences
- See
IRule.createEvaluation(IItemCollection, IPreferenceValueProvider, IResultValueProvider)
.
If null
, then default values will be used.nThreads
- The number or parallel threads to use when evaluating. If 0, then the number of
available processors will be used.public static java.lang.String getSecondFrameInMostCommonTrace(IItemCollection items)
items
- the item collection to build the aggregated stack trace onpublic static java.util.Map<java.lang.String,java.lang.String> getFlightRecorderOptions(IItemCollection items)
IItemCollection
.items
- an item collection containing at least one JdkTypeIDs.STRING_FLAG
event
with the value "FlightRecorderOptions"public static java.lang.String getShortRecordingInfo(IItemCollection items, IQuantity shortRecordingLimit)
items
- the item collection to get recording range fromshortRecordingLimit
- limit for a short recordingprivate static IQuantity getItemRange(IItemCollection items)
public static java.util.Map<java.lang.String,java.lang.Integer> sortMap(java.util.Map<java.lang.String,java.lang.Integer> map, boolean sortAscending)
map
- the map to sortsortAscending
- true if the sorting should be from lower to higher, false for higher to lowerpublic static IQuantity getEarliestStartTime(IItemCollection items)
items
- the item collection to find the earliest start time inpublic static IQuantity getEarliestEndTime(IItemCollection items)
items
- the item collection to find the earliest end time inpublic static IQuantity getLatestEndTime(IItemCollection items)
items
- the item collection to find the latest end time in