Skip to content

Commit

Permalink
counter.core: Generalize the counterAnalysis to take ITmfCounterAspect
Browse files Browse the repository at this point in the history
[Changed] Allowed ITmfCounterAspect populate counterAnalysis

Signed-off-by: Reza Rouhghalandari <[email protected]>
  • Loading branch information
Rezix93 committed Jul 31, 2024
1 parent c8509f5 commit e444a3c
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import java.util.logging.Logger;

import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.tracecompass.analysis.counters.core.aspects.CounterAspect;
import org.eclipse.tracecompass.analysis.counters.core.aspects.ITmfCounterAspect;
import org.eclipse.tracecompass.common.core.log.TraceCompassLog;
import org.eclipse.tracecompass.common.core.log.TraceCompassLogUtils;
Expand Down Expand Up @@ -76,8 +75,8 @@ public static CounterStateProvider create(ITmfTrace trace) {
Iterable<ITmfEventAspect<?>> 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<? extends ITmfEventAspect<?>> parentAspectClass : counterAspect.getGroups()) {

// Avoid creating the same aggregated aspect multiple times
Expand Down Expand Up @@ -122,8 +121,8 @@ 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);
Expand All @@ -147,8 +146,9 @@ protected void eventHandle(@NonNull ITmfEvent event) {
* Grouped counter aspect
* @param rootQuark
* Key to a relative root of the state system
* @since 3.0
*/
protected void handleGroupedCounterAspect(ITmfEvent event, ITmfStateSystemBuilder ss, CounterAspect aspect, int rootQuark) {
protected void handleGroupedCounterAspect(ITmfEvent event, ITmfStateSystemBuilder ss, ITmfCounterAspect aspect, int rootQuark) {
/*
* Retrieve the child quark of the counter aspect by going through its
* attribute tree in the state system. The concatenation of the aspect's
Expand All @@ -173,7 +173,7 @@ protected void handleGroupedCounterAspect(ITmfEvent event, ITmfStateSystemBuilde
handleCounterAspect(event, ss, aspect, quark);
}

private static void handleCounterAspect(ITmfEvent event, ITmfStateSystemBuilder ss, CounterAspect aspect, int rootQuark) {
private static void handleCounterAspect(ITmfEvent event, ITmfStateSystemBuilder ss, ITmfCounterAspect aspect, int rootQuark) {
int quark = ss.getQuarkRelativeAndAdd(rootQuark, aspect.getName());
Number eventContent = aspect.resolve(event);
if (eventContent != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ public boolean equals(@Nullable Object obj) {
* @return the type of this counter
* @since 2.1
*/
@Override
public CounterType getType() {
return fType;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public CounterAspect(String fieldName, String label, CounterType type, Class<? e
*
* @return the groups
*/
@Override
public Class<? extends ITmfEventAspect<?>>[] getGroups() {
return fGroups;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -52,4 +53,23 @@ default boolean isHiddenByDefault() {
default boolean isCumulative() {
return true;
}
/**
* Get the groups
*
* @return the groups
* @since 2.2
*/
default Class<? extends ITmfEventAspect<?>>[] getGroups(){
return new Class[0];
}
/**
* Gets the type of this counter
*
* @return the type of this counter
* @since 2.2
*/
default CounterType getType() {
return CounterType.LONG;
}

}

0 comments on commit e444a3c

Please sign in to comment.