public class RulesToolkit extends Object
Modifier and Type | Class and Description |
---|---|
static class |
RulesToolkit.EventAvailability
Knowledge about the state of affairs of an event type in an IItemCollection.
|
Modifier and Type | Field and Description |
---|---|
static String |
REC_SETTING_NAME_PERIOD |
static String |
REC_SETTING_PERIOD_EVERY_CHUNK |
Constructor and Description |
---|
RulesToolkit() |
Modifier and Type | Method and Description |
---|---|
static <T> double |
calculateBalanceScore(List<MapToolkit.IntEntry<T>> array)
Calculates a balance for entries, where later elements get a higher relevance than earlier
elements.
|
static <T> 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.
|
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 Map<IRule,Future<Result>> |
evaluateParallel(Collection<IRule> rules,
IItemCollection items,
IPreferenceValueProvider preferences,
int nThreads)
Evaluates a collection of rules in parallel threads.
|
static String |
findMatches(String typeId,
IItemCollection items,
IAttribute<String> attribute,
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 Collection<String> |
getAllTopics()
Retrieves all topics that have rules associated with them.
|
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 String |
getEnabledEventTypesRecommendation(IItemCollection items,
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,
String... typeIds)
Checks the event availability for the event types.
|
static Result |
getEventAvailabilityResult(IRule rule,
IItemCollection items,
RulesToolkit.EventAvailability eventAvailability,
String... typeIds)
Returns a proper result for the availability problem.
|
static Map<String,String> |
getFlightRecorderOptions(IItemCollection items)
Convenience method for parsing the -XX:FlightRecorderOptions JVM flag.
|
static JavaVersion |
getJavaSpecVersion(IItemCollection items)
Gets the Java version for the recording the provided
IItemCollection represents. |
static JavaVersion |
getJavaVersion(IItemCollection items) |
static JavaVersion |
getJavaVersion(String vmInfoVersionString) |
static RulesToolkit.EventAvailability |
getLeastAvailable(RulesToolkit.EventAvailability... availabilites)
Returns the least available EventAvailability from the ones provided.
|
static Result |
getMissingAttributeResult(IRule rule,
IType<IItem> type,
IAttribute<?> attribute)
Gets a
Result object representing a not applicable result due to a missing attribute. |
static Result |
getNotApplicableResult(IRule rule,
String message)
Creates a
Result object with a generic not applicable (N/A) result for a given rule
with a specified message. |
static String |
getPeriodIfGreaterThan(IItemCollection items,
IQuantity minPeriod,
String... typeIds)
If possible, gets the longest period setting that is longer than the specified minimum period
for the given event types.
|
static Result |
getRuleRequiresAtLeastOneEventTypeResult(IRule rule,
String... typeIds)
Creates a
Result object describing that at least one of the specified event types
must be present in the rule's input. |
static String |
getSecondFrameInMostCommonTrace(IItemCollection items)
Gets the second frame in the most common stack trace.
|
static IQuantity |
getSettingMaxPeriod(IItemCollection items,
String... typeIds)
Gets the maximum period setting for the specified event types in the given item collection.
|
static IItemFilter |
getSettingsFilter(String settingsName,
String... typeIds)
Gets a filter for a specific setting for the provided types.
|
static 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 Result |
getTooFewEventsResult(IRule rule)
|
static IType<IItem> |
getType(IItemCollection items,
String typeId)
Gets the
IType representation of a specific event type in an IItemCollection . |
static String |
getTypesWithZeroThreshold(IItemCollection items,
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
|
static boolean |
isEventsEnabled(IItemCollection items,
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. |
static double |
leastSquareMemory(Iterator<? extends IItem> items,
IMemberAccessor<IQuantity,IItem> timeField,
IMemberAccessor<IQuantity,IItem> memField) |
static double |
mapExp(double value,
double ceiling,
double x1,
double y1) |
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 IQuantity |
parsePersistedJvmTimespan(String persistedValue)
Converts a value persisted as a string by the JVM into an
IQuantity . |
static Map<String,Integer> |
sortMap(Map<String,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 String |
toRatioPercentString(IQuantity antecedent,
IQuantity consequent)
Same calculation as
toRatioPercent(IQuantity, IQuantity) but it returns
the percentage as a string instead. |
public static final String REC_SETTING_NAME_PERIOD
public static final String REC_SETTING_PERIOD_EVERY_CHUNK
public static double leastSquareMemory(Iterator<? extends IItem> items, IMemberAccessor<IQuantity,IItem> timeField, IMemberAccessor<IQuantity,IItem> memField)
public static String findMatches(String typeId, IItemCollection items, IAttribute<String> attribute, 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(String settingsName, String... typeIds)
settingsName
- the specific setting to findtypeIds
- the ids of the types to find the setting forpublic static IQuantity getSettingMaxPeriod(IItemCollection items, String... typeIds)
items
- the items to find the period setting intypeIds
- the event type ids to find settings forpublic static String getPeriodIfGreaterThan(IItemCollection items, IQuantity minPeriod, 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(String persistedValue) throws QuantityConversionException
IQuantity
.persistedValue
- the persisted value to convertIQuantity
QuantityConversionException
public static String getTypesWithZeroThreshold(IItemCollection items, String... typeIds)
items
- the item collection to searchtypeIds
- the event type ids to find thresholds forpublic static boolean isEventsEnabled(IItemCollection items, 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.public static RulesToolkit.EventAvailability getEventAvailability(IItemCollection items, 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 RulesToolkit.EventAvailability getLeastAvailable(RulesToolkit.EventAvailability... availabilites)
RulesToolkit.EventAvailability
.public static Result getEventAvailabilityResult(IRule rule, IItemCollection items, RulesToolkit.EventAvailability eventAvailability, String... typeIds)
rule
- the rule for which this result will be generateditems
- the items for which the availability was testedeventAvailability
- the availability making the rule N/AtypeIds
- the types for which the availability was testedpublic static Result getTooFewEventsResult(IRule rule)
Result
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 Result
object forpublic static Result getNotApplicableResult(IRule rule, String message)
Result
object with a generic not applicable (N/A) result for a given rule
with a specified message.rule
- the rule to create a Result
object formessage
- the description of the resultpublic static Result getRuleRequiresAtLeastOneEventTypeResult(IRule rule, String... typeIds)
Result
object describing that at least one of the specified event types
must be present in the rule's input.rule
- the rule to create a Result
object fortypeIds
- the ids of the event types required for this rulepublic static String getEnabledEventTypesRecommendation(IItemCollection items, 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.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> 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(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 curvepublic static JavaVersion getJavaVersion(String vmInfoVersionString)
vmInfoVersionString
- the JVM version information as presented in the VM information events, containing
both the JVM and JDK version numbers.public static IType<IItem> getType(IItemCollection items, 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 Result getMissingAttributeResult(IRule rule, IType<IItem> type, IAttribute<?> attribute)
Result
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 frompublic 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 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 Collection<String> getAllTopics()
public static Map<IRule,Future<Result>> evaluateParallel(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.evaluate(IItemCollection, IPreferenceValueProvider)
. 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 String getSecondFrameInMostCommonTrace(IItemCollection items)
items
- the item collection to build the aggregated stack trace onpublic static Map<String,String> getFlightRecorderOptions(IItemCollection items)
IItemCollection
.items
- an item collection containing at least one JdkTypeIDs.STRING_FLAG
event
with the value "FlightRecorderOptions"public static String getShortRecordingInfo(IItemCollection items, IQuantity shortRecordingLimit)
items
- the item collection to get recording range fromshortRecordingLimit
- limit for a short recordingCopyright © 2020. All rights reserved.