From 87a6529f27ef2090e0dbb130af6b0904959d911a Mon Sep 17 00:00:00 2001 From: Reza Rouhghalandari Date: Wed, 31 Jul 2024 16:46:30 -0400 Subject: [PATCH] counter.core: Generalize the counterAnalysis to take ITmfCounterAspect [Changed] Allowed ITmfCounterAspect populate counterAnalysis Signed-off-by: Reza Rouhghalandari --- .../META-INF/MANIFEST.MF | 5 ++- .../counters/core/CounterStateProvider.java | 37 +++++++++++++++---- .../core/aspects/AbstractCounterAspect.java | 6 +-- .../counters/core/aspects/CounterAspect.java | 6 +-- .../core/aspects/ITmfCounterAspect.java | 20 ++++++++++ 5 files changed, 54 insertions(+), 20 deletions(-) diff --git a/analysis/org.eclipse.tracecompass.analysis.counters.core/META-INF/MANIFEST.MF b/analysis/org.eclipse.tracecompass.analysis.counters.core/META-INF/MANIFEST.MF index abe38d5887..1ab84eefd1 100644 --- a/analysis/org.eclipse.tracecompass.analysis.counters.core/META-INF/MANIFEST.MF +++ b/analysis/org.eclipse.tracecompass.analysis.counters.core/META-INF/MANIFEST.MF @@ -2,12 +2,13 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %Bundle-Name Bundle-Vendor: %Bundle-Vendor -Bundle-Version: 2.2.1.qualifier +Bundle-Version: 2.3.0.qualifier Bundle-Localization: plugin Bundle-SymbolicName: org.eclipse.tracecompass.analysis.counters.core;singleton:=true Bundle-Activator: org.eclipse.tracecompass.internal.analysis.counters.core.Activator Bundle-ActivationPolicy: lazy -Bundle-RequiredExecutionEnvironment: JavaSE-11 +Bundle-RequiredExecutionEnvironment: JavaSE-11, + JavaSE-21 Require-Bundle: org.eclipse.core.runtime, org.eclipse.core.resources, org.eclipse.tracecompass.common.core, diff --git a/analysis/org.eclipse.tracecompass.analysis.counters.core/src/org/eclipse/tracecompass/analysis/counters/core/CounterStateProvider.java b/analysis/org.eclipse.tracecompass.analysis.counters.core/src/org/eclipse/tracecompass/analysis/counters/core/CounterStateProvider.java index aa0bf92292..b27705c304 100644 --- a/analysis/org.eclipse.tracecompass.analysis.counters.core/src/org/eclipse/tracecompass/analysis/counters/core/CounterStateProvider.java +++ b/analysis/org.eclipse.tracecompass.analysis.counters.core/src/org/eclipse/tracecompass/analysis/counters/core/CounterStateProvider.java @@ -76,8 +76,8 @@ public static CounterStateProvider create(ITmfTrace trace) { Iterable> counterAspects = TmfTraceUtils.getEventAspects(trace, ITmfCounterAspect.class); for (ITmfEventAspect counter : counterAspects) { - if (counter instanceof CounterAspect) { - CounterAspect counterAspect = (CounterAspect) counter; + if (counter instanceof ITmfCounterAspect) { + ITmfCounterAspect counterAspect = (ITmfCounterAspect) counter; for (Class> parentAspectClass : counterAspect.getGroups()) { // Avoid creating the same aggregated aspect multiple times @@ -122,14 +122,14 @@ protected void eventHandle(@NonNull ITmfEvent event) { } for (ITmfEventAspect aspect : fCounterAspects) { - if (aspect instanceof CounterAspect) { - CounterAspect counterAspect = (CounterAspect) aspect; + if (aspect instanceof ITmfCounterAspect) { + ITmfCounterAspect counterAspect = (ITmfCounterAspect) aspect; if (counterAspect.getGroups().length > 0) { int rootQuark = ss.getQuarkAbsoluteAndAdd(CounterAnalysis.GROUPED_COUNTER_ASPECTS_ATTRIB); - handleGroupedCounterAspect(event, ss, counterAspect, rootQuark); + handleGroupedCounterAspect(event, ss, rootQuark, counterAspect); } else { int rootQuark = ss.getQuarkAbsoluteAndAdd(CounterAnalysis.UNGROUPED_COUNTER_ASPECTS_ATTRIB); - handleCounterAspect(event, ss, counterAspect, rootQuark); + handleCounterAspect(event, ss, rootQuark, counterAspect); } } } @@ -147,8 +147,29 @@ protected void eventHandle(@NonNull ITmfEvent event) { * Grouped counter aspect * @param rootQuark * Key to a relative root of the state system + * @deprecated use + * {@link #handleGroupedCounterAspect(ITmfEvent, ITmfStateSystemBuilder, int, ITfmCounterAspect)} */ + @Deprecated protected void handleGroupedCounterAspect(ITmfEvent event, ITmfStateSystemBuilder ss, CounterAspect aspect, int rootQuark) { + handleGroupedCounterAspect(event, ss, rootQuark, aspect); + } + + /** + * Add the field value of a grouped counter aspect to the state system + * (override in specific implementations) + * + * @param event + * Event to process + * @param ss + * State system object to fill + * @param rootQuark + * Key to a relative root of the state system + * @param aspect + * Grouped counter aspect + * @since 2.3 + */ + protected void handleGroupedCounterAspect(ITmfEvent event, ITmfStateSystemBuilder ss, int rootQuark, ITmfCounterAspect aspect) { /* * Retrieve the child quark of the counter aspect by going through its * attribute tree in the state system. The concatenation of the aspect's @@ -170,10 +191,10 @@ protected void handleGroupedCounterAspect(ITmfEvent event, ITmfStateSystemBuilde } } - handleCounterAspect(event, ss, aspect, quark); + handleCounterAspect(event, ss, quark, aspect); } - private static void handleCounterAspect(ITmfEvent event, ITmfStateSystemBuilder ss, CounterAspect aspect, int rootQuark) { + private static void handleCounterAspect(ITmfEvent event, ITmfStateSystemBuilder ss, int rootQuark, ITmfCounterAspect aspect) { int quark = ss.getQuarkRelativeAndAdd(rootQuark, aspect.getName()); Number eventContent = aspect.resolve(event); if (eventContent != null) { diff --git a/analysis/org.eclipse.tracecompass.analysis.counters.core/src/org/eclipse/tracecompass/analysis/counters/core/aspects/AbstractCounterAspect.java b/analysis/org.eclipse.tracecompass.analysis.counters.core/src/org/eclipse/tracecompass/analysis/counters/core/aspects/AbstractCounterAspect.java index 7c0701af6f..bcd4b92c7d 100644 --- a/analysis/org.eclipse.tracecompass.analysis.counters.core/src/org/eclipse/tracecompass/analysis/counters/core/aspects/AbstractCounterAspect.java +++ b/analysis/org.eclipse.tracecompass.analysis.counters.core/src/org/eclipse/tracecompass/analysis/counters/core/aspects/AbstractCounterAspect.java @@ -104,11 +104,6 @@ public int hashCode() { return Objects.hash(fFieldName, fLabel); } - /** - * {@inheritDoc} - * - * This is a conservative equals. It only works on very identical aspects. - */ @Override public boolean equals(@Nullable Object obj) { if (this == obj) { @@ -130,6 +125,7 @@ public boolean equals(@Nullable Object obj) { * @return the type of this counter * @since 2.1 */ + @Override public CounterType getType() { return fType; } diff --git a/analysis/org.eclipse.tracecompass.analysis.counters.core/src/org/eclipse/tracecompass/analysis/counters/core/aspects/CounterAspect.java b/analysis/org.eclipse.tracecompass.analysis.counters.core/src/org/eclipse/tracecompass/analysis/counters/core/aspects/CounterAspect.java index b3dd5e6705..0470c95d55 100644 --- a/analysis/org.eclipse.tracecompass.analysis.counters.core/src/org/eclipse/tracecompass/analysis/counters/core/aspects/CounterAspect.java +++ b/analysis/org.eclipse.tracecompass.analysis.counters.core/src/org/eclipse/tracecompass/analysis/counters/core/aspects/CounterAspect.java @@ -76,11 +76,7 @@ public CounterAspect(String fieldName, String label, CounterType type, Class>[] getGroups() { return fGroups; } diff --git a/analysis/org.eclipse.tracecompass.analysis.counters.core/src/org/eclipse/tracecompass/analysis/counters/core/aspects/ITmfCounterAspect.java b/analysis/org.eclipse.tracecompass.analysis.counters.core/src/org/eclipse/tracecompass/analysis/counters/core/aspects/ITmfCounterAspect.java index d06836351e..2face5ea3d 100644 --- a/analysis/org.eclipse.tracecompass.analysis.counters.core/src/org/eclipse/tracecompass/analysis/counters/core/aspects/ITmfCounterAspect.java +++ b/analysis/org.eclipse.tracecompass.analysis.counters.core/src/org/eclipse/tracecompass/analysis/counters/core/aspects/ITmfCounterAspect.java @@ -11,6 +11,7 @@ package org.eclipse.tracecompass.analysis.counters.core.aspects; +import org.eclipse.tracecompass.analysis.counters.core.CounterType; import org.eclipse.tracecompass.tmf.core.event.aspect.ITmfEventAspect; /** @@ -52,4 +53,23 @@ default boolean isHiddenByDefault() { default boolean isCumulative() { return true; } + + /** + * Get the groups + * + * @return the groups + * @since 2.2 + */ + default Class>[] getGroups() { + return new Class[0]; + } + + /** + * Gets the type of this counter + * + * @since 2.2 + */ + default CounterType getType() { + return CounterType.LONG; + } }