Package es.urjc.etsii.grafo.metrics
Class Metrics
java.lang.Object
es.urjc.etsii.grafo.metrics.Metrics
Manages metrics instances. Example usage:
- Call
resetMetrics() to initialize a new instance of empty metrics
- Run the algorithm. Any algorithm component can get the current metrics instance using getCurrentThreadMetrics(), and add data points to it using AbstractMetric.add(long, double).
- Do something with the metrics after the algorithm finishes, for example merging (see below).
- Reset metrics before the next algorithm start executing.
Note that metrics are always ThreadLocal, which means that every thread works on its own independent copy.
Metrics are always disabled by default, and must be enabled by either the framework or manually by the user
Metrics from different threads can later be merged using merge(MetricsStorage...)
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends AbstractMetric>
voidstatic <T extends AbstractMetric>
voidstatic voidstatic voidaddCurrentObjectives(S solution) static booleanReturn true if metrics are enabled, false otherwise.static booleanReturn true if time stats are enabled, false otherwise.static voidDisable metrics and empty all internal data structuresstatic voidstatic voidEnable metricsstatic voidstatic <T extends AbstractMetric>
Tstatic <T extends AbstractMetric>
Tstatic MetricsStorageGet metrics collected by the current thread.static MetricsStoragemerge(MetricsStorage... metrics) Merge several metrics instances.static MetricsStoragemerge(Iterable<MetricsStorage> metrics) Merge several metrics instances.static <T extends AbstractMetric>
voidRegister a new metric so the framework automatically tracks itstatic <T extends AbstractMetric>
voidRegister a new metric so the framework automatically tracks itstatic voidInitialize a new metrics object for use in the current threadstatic voidresetMetrics(long referenceTime) Initialize a new metrics object for use in the current thread
-
Method Details
-
getCurrentThreadMetrics
Get metrics collected by the current thread.- Returns:
- metrics instance for the current thread
- Throws:
IllegalStateException- if the metrics have not been initialized for the current thread, or if the metrics are disabled
-
resetMetrics
public static void resetMetrics()Initialize a new metrics object for use in the current thread- Throws:
IllegalStateException- if the metrics are disabled
-
resetMetrics
public static void resetMetrics(long referenceTime) Initialize a new metrics object for use in the current thread- Parameters:
referenceTime- reference time, seeMetricsStorage(long)for a more detailed explanation.- Throws:
IllegalStateException- if the metrics are disabled
-
enableMetrics
public static void enableMetrics()Enable metrics -
disableMetrics
public static void disableMetrics()Disable metrics and empty all internal data structures -
enableTimeStats
public static void enableTimeStats() -
disableTimeStats
public static void disableTimeStats() -
areTimeStatsEnabled
public static boolean areTimeStatsEnabled()Return true if time stats are enabled, false otherwise.- Returns:
- true if time stats are enabled, false otherwise
-
areMetricsEnabled
public static boolean areMetricsEnabled()Return true if metrics are enabled, false otherwise.- Returns:
- true if metrics are enabled, false otherwise
-
get
-
get
-
register
public static <T extends AbstractMetric> void register(String metricName, Function<Long, T> initializer) Register a new metric so the framework automatically tracks it- Type Parameters:
T- metric type- Parameters:
metricName- metric nameinitializer- method to initialize the given metric
-
register
public static <T extends AbstractMetric> void register(Class<T> metric, Function<Long, T> initializer) Register a new metric so the framework automatically tracks it- Type Parameters:
T- Metric type- Parameters:
metric- metric implementation to track, must extend AbstractMetricinitializer- Method used to initialize the given metric
-
merge
Merge several metrics instances. All data points will be translated to the lowest reference point For example, if metrics A was created at 5, and metrics B reference time is 10, the returned metrics will have 5 as reference point and all data points from metrics B will have their instant incremented by 5.- Parameters:
metrics- metrics to merge- Returns:
- new metric instance containing the data of all the metrics provided, with time corrected as necessary.
-
merge
Merge several metrics instances. For example, if metrics A was created at 5, and metrics B reference time is 10, the returned metrics will have 5 as reference point and all data points from metrics B will have their instant incremented by 5.- Parameters:
metrics- metric instances- Returns:
- new metric instance containing the data of all the metrics provided, with time corrected as necessary.
-
addCurrentObjectives
-
add
-
add
-
add
-
add
-