Skip to content

Commit 678508f

Browse files
committed
Exposed state system through data provider factory
Added fetchStyle for state system modified mod to floor mod
1 parent 22545a7 commit 678508f

File tree

4 files changed

+95
-11
lines changed

4 files changed

+95
-11
lines changed

tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/internal/tmf/core/statesystem/provider/Messages.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ public class Messages extends NLS {
4545
/** Label for the "attribute path" column */
4646
public static @Nullable String AttributePathColumnLabel;
4747

48+
/** Data Provider factory title */
49+
public static @Nullable String StateSystemDataProviderFactory_title;
50+
51+
/** Data Provider factory help text */
52+
public static @Nullable String StateSystemDataProviderFactory_descriptionText;
53+
4854
static {
4955
// initialize resource bundle
5056
NLS.initializeMessages(BUNDLE_NAME, Messages.class);

tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/internal/tmf/core/statesystem/provider/StateSystemDataProvider.java

Lines changed: 62 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import java.util.concurrent.ConcurrentHashMap;
2727
import java.util.concurrent.atomic.AtomicLong;
2828
import java.util.function.Predicate;
29-
29+
import com.google.common.collect.ImmutableMap;
3030
import org.eclipse.core.runtime.IProgressMonitor;
3131
import org.eclipse.jdt.annotation.NonNull;
3232
import org.eclipse.jdt.annotation.Nullable;
@@ -36,8 +36,13 @@
3636
import org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException;
3737
import org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval;
3838
import org.eclipse.tracecompass.tmf.core.dataprovider.DataProviderParameterUtils;
39+
import org.eclipse.tracecompass.tmf.core.dataprovider.X11ColorUtils;
3940
import org.eclipse.tracecompass.tmf.core.model.AbstractTmfTraceDataProvider;
4041
import org.eclipse.tracecompass.tmf.core.model.CommonStatusMessage;
42+
import org.eclipse.tracecompass.tmf.core.model.IOutputStyleProvider;
43+
import org.eclipse.tracecompass.tmf.core.model.OutputElementStyle;
44+
import org.eclipse.tracecompass.tmf.core.model.OutputStyleModel;
45+
import org.eclipse.tracecompass.tmf.core.model.StyleProperties;
4146
import org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphArrow;
4247
import org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphDataProvider;
4348
import org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphRowModel;
@@ -47,7 +52,11 @@
4752
import org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphRowModel;
4853
import org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphState;
4954
import org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeModel;
55+
import org.eclipse.tracecompass.tmf.core.presentation.IPaletteProvider;
56+
import org.eclipse.tracecompass.tmf.core.presentation.RGBAColor;
57+
import org.eclipse.tracecompass.tmf.core.presentation.RotatingPaletteProvider;
5058
import org.eclipse.tracecompass.tmf.core.response.ITmfResponse.Status;
59+
import org.eclipse.tracecompass.tmf.core.response.ITmfResponse;
5160
import org.eclipse.tracecompass.tmf.core.response.TmfModelResponse;
5261
import org.eclipse.tracecompass.tmf.core.signal.TmfStartAnalysisSignal;
5362
import org.eclipse.tracecompass.tmf.core.statesystem.ITmfAnalysisModuleWithStateSystems;
@@ -70,8 +79,7 @@
7079
* @author Loic Prieur-Drevon
7180
*
7281
*/
73-
public class StateSystemDataProvider extends AbstractTmfTraceDataProvider implements ITimeGraphDataProvider<@NonNull TimeGraphEntryModel> {
74-
82+
public class StateSystemDataProvider extends AbstractTmfTraceDataProvider implements ITimeGraphDataProvider<@NonNull TimeGraphEntryModel>, IOutputStyleProvider {
7583
/**
7684
* Extension point ID.
7785
*/
@@ -107,6 +115,35 @@ public class StateSystemDataProvider extends AbstractTmfTraceDataProvider implem
107115
*/
108116
private final Set<ITmfAnalysisModuleWithStateSystems> fStartedAnalysis = Objects.requireNonNull(ConcurrentHashMap.newKeySet());
109117

118+
/** Number of colors used for State system time events */
119+
private static final int NUM_COLORS = 9;
120+
121+
private static final String UNKNOWN = "Unknown"; //$NON-NLS-1$
122+
123+
private static final String COLOR_UNKOWN = X11ColorUtils.toHexColor(192, 192, 192);
124+
125+
private static final @NonNull Map<@NonNull String, @NonNull OutputElementStyle> STYLE_MAP;
126+
127+
static {
128+
ImmutableMap.Builder<@NonNull String, @NonNull OutputElementStyle> builder = new ImmutableMap.Builder<>();
129+
IPaletteProvider fPalette = new RotatingPaletteProvider.Builder().setNbColors(NUM_COLORS).build();
130+
List<RGBAColor> colors = fPalette.get();
131+
for (int i = 0; i < colors.size(); i++) {
132+
RGBAColor rgbaColor = colors.get(i);
133+
String hexColor = X11ColorUtils.toHexColor(rgbaColor.getRed(), rgbaColor.getGreen(), rgbaColor.getBlue());
134+
Map<String, Object> fMap = ImmutableMap.of(
135+
StyleProperties.BACKGROUND_COLOR, hexColor);
136+
String key = Integer.toString(i);
137+
OutputElementStyle outputStyle = new OutputElementStyle(null, fMap);
138+
builder.put(key, outputStyle);
139+
}
140+
141+
Map<String, Object> fMapUNKOWN = ImmutableMap.of(StyleProperties.BACKGROUND_COLOR, COLOR_UNKOWN);
142+
OutputElementStyle unknownoutputStyle = new OutputElementStyle(null, fMapUNKOWN);
143+
builder.put(UNKNOWN, unknownoutputStyle);
144+
STYLE_MAP = builder.build();
145+
}
146+
110147
/**
111148
* Constructor
112149
*
@@ -184,7 +221,7 @@ private static String getQuarkValue(Map<String, Object> fetchParameters, ITmfSta
184221
return NonNullUtils.nullToEmptyString(valueString);
185222
}
186223

187-
private abstract static class EntryModelBuilder {
224+
private abstract static class EntryModelBuilder {
188225
private final long fId;
189226
private final long fParentId;
190227
private final String fName;
@@ -455,11 +492,14 @@ public int getQuark() {
455492
return new TmfModelResponse<>(null, Status.CANCELLED, CommonStatusMessage.TASK_CANCELLED);
456493
}
457494
}
458-
List<TimeGraphEntryModel> entryList = buildEntryList(monitor);
459495

496+
List<TimeGraphEntryModel> entryList = buildEntryList(monitor);
460497
Status status = fetchTreeIsComplete ? Status.COMPLETED : Status.RUNNING;
461498
String msg = fetchTreeIsComplete ? CommonStatusMessage.COMPLETED : CommonStatusMessage.RUNNING;
462-
return new TmfModelResponse<>(new TmfTreeModel<>(Collections.emptyList(), entryList), status, msg);
499+
TmfTreeModel<TimeGraphEntryModel> treeModel = new TmfTreeModel<>(Collections.emptyList(), entryList);
500+
treeModel.setAutoExpandLevel(1);
501+
502+
return new TmfModelResponse<>(treeModel, status, msg);
463503
}
464504

465505
private boolean addTrace(@Nullable IProgressMonitor monitor) {
@@ -722,6 +762,7 @@ private void waitForInitialization(ITmfTrace trace, ITmfAnalysisModuleWithStateS
722762
}
723763
}
724764
}
765+
725766
if (monitor != null && monitor.isCanceled()) {
726767
return new TmfModelResponse<>(null, Status.CANCELLED, CommonStatusMessage.TASK_CANCELLED);
727768
}
@@ -788,17 +829,22 @@ private static TimeGraphState getStateFromInterval(ITmfStateInterval statusInter
788829
long time = statusInterval.getStartTime();
789830
long duration = Math.min(statusInterval.getEndTime(), currentEndTime - 1) + 1 - time;
790831
Object o = statusInterval.getValue();
832+
// Set style for States w/ or w/o labels
833+
OutputElementStyle style = (o != null)
834+
? new OutputElementStyle(Integer.toString(Math.floorMod(String.valueOf(o).hashCode(), NUM_COLORS)))
835+
: new OutputElementStyle(UNKNOWN);
836+
791837
if (o instanceof Integer) {
792-
return new TimeGraphState(time, duration, ((Integer) o).intValue(), String.valueOf(o));
838+
return new TimeGraphState(time, duration, ((Integer) o).intValue(), String.valueOf(o), style);
793839
} else if (o instanceof Long) {
794840
long l = (long) o;
795-
return new TimeGraphState(time, duration, (int) l, "0x" + Long.toHexString(l)); //$NON-NLS-1$
841+
return new TimeGraphState(time, duration, (int) l, "0x" + Long.toHexString(l), style); //$NON-NLS-1$
796842
} else if (o instanceof String) {
797-
return new TimeGraphState(time, duration, Integer.MIN_VALUE, (String) o);
843+
return new TimeGraphState(time, duration, Integer.MIN_VALUE, (String) o, style);
798844
} else if (o instanceof Double) {
799-
return new TimeGraphState(time, duration, ((Double) o).intValue());
845+
return new TimeGraphState(time, duration, ((Double) o).intValue(), null, style);
800846
}
801-
return new TimeGraphState(time, duration, Integer.MIN_VALUE);
847+
return new TimeGraphState(time, duration, Integer.MIN_VALUE, null, style);
802848
}
803849

804850
/**
@@ -815,4 +861,9 @@ public void startedAnalysisSignalHandler(ITmfAnalysisModuleWithStateSystems modu
815861
}
816862
}
817863

864+
@Override
865+
public TmfModelResponse<OutputStyleModel> fetchStyle(Map<String, Object> fetchParameters, @Nullable IProgressMonitor monitor) {
866+
return new TmfModelResponse<>(new OutputStyleModel(STYLE_MAP), ITmfResponse.Status.COMPLETED, CommonStatusMessage.COMPLETED);
867+
}
868+
818869
}

tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/internal/tmf/core/statesystem/provider/StateSystemDataProviderFactory.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,22 @@
1111

1212
package org.eclipse.tracecompass.internal.tmf.core.statesystem.provider;
1313

14+
import java.util.Collection;
15+
import java.util.Collections;
16+
import java.util.Objects;
17+
1418
import org.eclipse.jdt.annotation.NonNull;
1519
import org.eclipse.jdt.annotation.Nullable;
20+
import org.eclipse.tracecompass.tmf.core.dataprovider.IDataProviderDescriptor;
1621
import org.eclipse.tracecompass.tmf.core.dataprovider.IDataProviderFactory;
22+
import org.eclipse.tracecompass.tmf.core.dataprovider.IDataProviderDescriptor.ProviderType;
23+
import org.eclipse.tracecompass.tmf.core.model.DataProviderDescriptor;
24+
import org.eclipse.tracecompass.tmf.core.model.timegraph.TmfTimeGraphCompositeDataProvider;
1725
import org.eclipse.tracecompass.tmf.core.model.tree.ITmfTreeDataModel;
1826
import org.eclipse.tracecompass.tmf.core.model.tree.ITmfTreeDataProvider;
1927
import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
28+
import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
29+
import org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment;
2030

2131
/**
2232
* Extension point factory for the {@link StateSystemDataProvider}
@@ -25,9 +35,24 @@
2535
*/
2636
public class StateSystemDataProviderFactory implements IDataProviderFactory {
2737

38+
private static final IDataProviderDescriptor DESCRIPTOR = new DataProviderDescriptor.Builder()
39+
.setId(StateSystemDataProvider.ID)
40+
.setName(Objects.requireNonNull(Messages.StateSystemDataProviderFactory_title))
41+
.setDescription(Objects.requireNonNull(Messages.StateSystemDataProviderFactory_descriptionText))
42+
.setProviderType(ProviderType.TIME_GRAPH)
43+
.build();
44+
2845
@Override
2946
public @Nullable ITmfTreeDataProvider<? extends ITmfTreeDataModel> createProvider(@NonNull ITmfTrace trace) {
47+
if (trace instanceof TmfExperiment) {
48+
return TmfTimeGraphCompositeDataProvider.create(TmfTraceManager.getTraceSet(trace), StateSystemDataProvider.ID);
49+
}
50+
3051
return new StateSystemDataProvider(trace);
3152
}
3253

54+
@Override
55+
public Collection<IDataProviderDescriptor> getDescriptors(@NonNull ITmfTrace trace) {
56+
return Collections.singletonList(DESCRIPTOR);
57+
}
3358
}

tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/internal/tmf/core/statesystem/provider/messages.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
# SPDX-License-Identifier: EPL-2.0
1010
###############################################################################
1111
# Column names
12+
StateSystemDataProviderFactory_title=State System Explorer
13+
StateSystemDataProviderFactory_descriptionText=Displays the states of state system attributes over time.
1214
TreeNodeColumnLabel=State System / Attribute
1315
QuarkColumnLabel=Quark
1416
ValueColumnLabel=Value

0 commit comments

Comments
 (0)