Skip to content

Commit d0b8401

Browse files
committed
tmf: Refactor virtual table data provider column implementation
Make virtual table data providers return their columns in a column descriptors list returned by new method fetchColumns(). Add column id to the ITableColumnDescriptor interface. Update ITmfVirtualTableDataProvider implementations accordingly, e.g. TmfEventTableDataProvider and SegmentStoreTableDataProvider. Deprecate fetchTree() in ITmfVirtualTableDataProvider. [Added] New method fetchColumns() in ITmfVirtualTableDataProvider [Added] New method getId() in ITableColumnDescriptor [Deprecated] Deprecate fetchTree() in ITmfVirtualTableDataProvider Signed-off-by: Patrick Tasse <patrick.tasse@gmail.com>
1 parent 261ea15 commit d0b8401

10 files changed

Lines changed: 199 additions & 246 deletions

File tree

analysis/org.eclipse.tracecompass.analysis.timing.core.tests/src/org/eclipse/tracecompass/analysis/timing/core/tests/segmentstore/SegmentStoreTableDataProviderExperimentTest.java

Lines changed: 56 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**********************************************************************
2-
* Copyright (c) 2022, 2024 Ericsson
2+
* Copyright (c) 2022, 2025 Ericsson
33
*
44
* All rights reserved. This program and the accompanying materials are
55
* made available under the terms of the Eclipse Public License 2.0 which
@@ -24,7 +24,6 @@
2424
import java.util.LinkedHashMap;
2525
import java.util.List;
2626
import java.util.Map;
27-
import java.util.Objects;
2827

2928
import org.eclipse.core.runtime.IProgressMonitor;
3029
import org.eclipse.jdt.annotation.NonNull;
@@ -33,6 +32,7 @@
3332
import org.eclipse.tracecompass.analysis.timing.core.segmentstore.SegmentStoreAnalysisModule;
3433
import org.eclipse.tracecompass.analysis.timing.core.tests.stubs.segmentstore.StubSegmentStoreProvider;
3534
import org.eclipse.tracecompass.internal.analysis.timing.core.segmentstore.SegmentStoreTableDataProvider;
35+
import org.eclipse.tracecompass.internal.provisional.tmf.core.model.TableColumnDescriptor;
3636
import org.eclipse.tracecompass.internal.provisional.tmf.core.model.filters.VirtualTableQueryFilter;
3737
import org.eclipse.tracecompass.internal.provisional.tmf.core.model.table.ITmfVirtualTableDataProvider;
3838
import org.eclipse.tracecompass.internal.provisional.tmf.core.model.table.ITmfVirtualTableModel;
@@ -44,12 +44,12 @@
4444
import org.eclipse.tracecompass.segmentstore.core.ISegment;
4545
import org.eclipse.tracecompass.segmentstore.core.ISegmentStore;
4646
import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule;
47+
import org.eclipse.tracecompass.tmf.core.dataprovider.DataType;
4748
import org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException;
4849
import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
4950
import org.eclipse.tracecompass.tmf.core.model.CoreFilterProperty;
50-
import org.eclipse.tracecompass.tmf.core.model.filters.TimeQueryFilter;
51-
import org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeDataModel;
52-
import org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeModel;
51+
import org.eclipse.tracecompass.tmf.core.model.ITableColumnDescriptor;
52+
import org.eclipse.tracecompass.tmf.core.model.tree.ITmfTreeDataModel;
5353
import org.eclipse.tracecompass.tmf.core.response.ITmfResponse;
5454
import org.eclipse.tracecompass.tmf.core.response.TmfModelResponse;
5555
import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
@@ -114,9 +114,9 @@ public boolean setTrace(@NonNull ITmfTrace trace) throws TmfAnalysisException {
114114
}
115115
}
116116

117-
private static ITmfVirtualTableDataProvider<@NonNull TmfTreeDataModel, @NonNull VirtualTableLine> fMainDataProvider;
118-
private static ITmfVirtualTableDataProvider<@NonNull TmfTreeDataModel, @NonNull VirtualTableLine> fDataProvider;
119-
private static ITmfVirtualTableDataProvider<@NonNull TmfTreeDataModel, @NonNull VirtualTableLine> fInvalidDataProvider;
117+
private static ITmfVirtualTableDataProvider<@NonNull ITmfTreeDataModel, @NonNull VirtualTableLine> fMainDataProvider;
118+
private static ITmfVirtualTableDataProvider<@NonNull ITmfTreeDataModel, @NonNull VirtualTableLine> fDataProvider;
119+
private static ITmfVirtualTableDataProvider<@NonNull ITmfTreeDataModel, @NonNull VirtualTableLine> fInvalidDataProvider;
120120

121121
private static final String START_TIME_COLUMN_NAME = "Start Time";
122122
private static final String END_TIME_COLUMN_NAME = "End Time";
@@ -175,45 +175,43 @@ public static void init() throws TmfAnalysisException {
175175
}
176176

177177
private static Map<String, Long> fetchColumnId() {
178-
TmfTreeModel<@NonNull TmfTreeDataModel> columns = fMainDataProvider.fetchTree(FetchParametersUtils.timeQueryToMap(new TimeQueryFilter(0, 0, 1)), null).getModel();
178+
List<@NonNull ITableColumnDescriptor> columns = fMainDataProvider.fetchColumns(Collections.emptyMap(), null).getModel();
179179
if (columns == null) {
180180
return Collections.emptyMap();
181181
}
182-
List<@NonNull TmfTreeDataModel> columnEntries = columns.getEntries();
183-
assertEquals(START_TIME_COLUMN_NAME, columnEntries.get(0).getName());
184-
assertEquals(END_TIME_COLUMN_NAME, columnEntries.get(1).getName());
185-
assertEquals(DURATION_COLUMN_NAME, columnEntries.get(2).getName());
186-
assertEquals(StubSegmentStoreProvider.STUB_COLUMN_NAME, columnEntries.get(3).getName());
187-
assertEquals(TRACE_COLUMN_NAME, columnEntries.get(4).getName());
188-
assertEquals(NS_TIME_COLUMN_NAME, columnEntries.get(5).getName());
182+
assertEquals(START_TIME_COLUMN_NAME, columns.get(0).getText());
183+
assertEquals(END_TIME_COLUMN_NAME, columns.get(1).getText());
184+
assertEquals(DURATION_COLUMN_NAME, columns.get(2).getText());
185+
assertEquals(StubSegmentStoreProvider.STUB_COLUMN_NAME, columns.get(3).getText());
186+
assertEquals(TRACE_COLUMN_NAME, columns.get(4).getText());
187+
assertEquals(NS_TIME_COLUMN_NAME, columns.get(5).getText());
189188

190189
Map<String, Long> expectedColumns = new LinkedHashMap<>();
191-
for (TmfTreeDataModel column : columnEntries) {
192-
expectedColumns.put(column.getName(), column.getId());
190+
for (ITableColumnDescriptor column : columns) {
191+
expectedColumns.put(column.getText(), column.getId());
193192
}
194193
return expectedColumns;
195194
}
196195

197196
private static Map<String, Long> fetchSingleTraceColumnId() {
198-
TmfTreeModel<@NonNull TmfTreeDataModel> columns = fDataProvider.fetchTree(FetchParametersUtils.timeQueryToMap(new TimeQueryFilter(0, 0, 1)), null).getModel();
197+
List<@NonNull ITableColumnDescriptor> columns = fDataProvider.fetchColumns(Collections.emptyMap(), null).getModel();
199198
if (columns == null) {
200199
return Collections.emptyMap();
201200
}
202-
List<@NonNull TmfTreeDataModel> columnEntries = columns.getEntries();
203-
assertEquals(START_TIME_COLUMN_NAME, columnEntries.get(0).getName());
204-
assertEquals(END_TIME_COLUMN_NAME, columnEntries.get(1).getName());
205-
assertEquals(DURATION_COLUMN_NAME, columnEntries.get(2).getName());
206-
assertEquals(StubSegmentStoreProvider.STUB_COLUMN_NAME, columnEntries.get(3).getName());
207-
assertEquals(NS_TIME_COLUMN_NAME, columnEntries.get(4).getName());
201+
assertEquals(START_TIME_COLUMN_NAME, columns.get(0).getText());
202+
assertEquals(END_TIME_COLUMN_NAME, columns.get(1).getText());
203+
assertEquals(DURATION_COLUMN_NAME, columns.get(2).getText());
204+
assertEquals(StubSegmentStoreProvider.STUB_COLUMN_NAME, columns.get(3).getText());
205+
assertEquals(NS_TIME_COLUMN_NAME, columns.get(4).getText());
208206

209207
Map<String, Long> expectedColumns = new LinkedHashMap<>();
210-
for (TmfTreeDataModel column : columnEntries) {
211-
expectedColumns.put(column.getName(), column.getId());
208+
for (ITableColumnDescriptor column : columns) {
209+
expectedColumns.put(column.getText(), column.getId());
212210
}
213211
return expectedColumns;
214212
}
215213

216-
private static ITmfVirtualTableDataProvider<@NonNull TmfTreeDataModel, @NonNull VirtualTableLine> getDataProvider(@NonNull TmfExperimentStub experiment) throws TmfAnalysisException {
214+
private static ITmfVirtualTableDataProvider<@NonNull ITmfTreeDataModel, @NonNull VirtualTableLine> getDataProvider(@NonNull TmfExperimentStub experiment) throws TmfAnalysisException {
217215
IAnalysisModule m = new SegmentStoreAnalysisModule(experiment);
218216
try {
219217
experiment.addAnalysisModule(m);
@@ -279,19 +277,17 @@ public void testMainDataProviderFetchColumn() {
279277
assertNotNull(traceColumnId);
280278
assertNotNull(nsTimeColumnId);
281279

282-
List<@NonNull TmfTreeDataModel> expectedColumnEntries = Arrays.asList(
283-
new TmfTreeDataModel(startTimeColumnId, -1, Collections.singletonList(START_TIME_COLUMN_NAME)),
284-
new TmfTreeDataModel(endTimeColumnId, -1, Collections.singletonList(END_TIME_COLUMN_NAME)),
285-
new TmfTreeDataModel(durationColumnId, -1, Collections.singletonList(DURATION_COLUMN_NAME)),
286-
new TmfTreeDataModel(customColumnId, -1, Collections.singletonList(StubSegmentStoreProvider.STUB_COLUMN_NAME)),
287-
new TmfTreeDataModel(traceColumnId, -1, Collections.singletonList(TRACE_COLUMN_NAME)),
288-
new TmfTreeDataModel(nsTimeColumnId, -1, Collections.singletonList(NS_TIME_COLUMN_NAME)));
289-
290-
TmfModelResponse<@NonNull TmfTreeModel<@NonNull TmfTreeDataModel>> response = fMainDataProvider.fetchTree(FetchParametersUtils.timeQueryToMap(new TimeQueryFilter(0, 0, 1)), null);
291-
TmfTreeModel<@NonNull TmfTreeDataModel> currentColumnModel = response.getModel();
292-
assertNotNull(currentColumnModel);
293-
List<@NonNull TmfTreeDataModel> currentColumnEntries = Objects.requireNonNull(currentColumnModel).getEntries();
294-
assertEquals(expectedColumnEntries, currentColumnEntries);
280+
List<@NonNull ITableColumnDescriptor> expectedColumns = Arrays.asList(
281+
new TableColumnDescriptor.Builder().setId(startTimeColumnId).setText(START_TIME_COLUMN_NAME).setTooltip("Start time of the segment").setDataType(DataType.TIMESTAMP).build(),
282+
new TableColumnDescriptor.Builder().setId(endTimeColumnId).setText(END_TIME_COLUMN_NAME).setTooltip("End time of the segment").setDataType(DataType.TIMESTAMP).build(),
283+
new TableColumnDescriptor.Builder().setId(durationColumnId).setText(DURATION_COLUMN_NAME).setTooltip("Segment duration").setDataType(DataType.DURATION).build(),
284+
new TableColumnDescriptor.Builder().setId(customColumnId).setText(StubSegmentStoreProvider.STUB_COLUMN_NAME).setTooltip("Stub segment column information").setDataType(DataType.STRING).build(),
285+
new TableColumnDescriptor.Builder().setId(traceColumnId).setText(TRACE_COLUMN_NAME).setDataType(DataType.STRING).build(),
286+
new TableColumnDescriptor.Builder().setId(nsTimeColumnId).setText(NS_TIME_COLUMN_NAME).setTooltip("Start time of the segment in nano seconds").setDataType(DataType.NUMBER).build());
287+
288+
List<@NonNull ITableColumnDescriptor> currentColumns = fMainDataProvider.fetchColumns(Collections.emptyMap(), null).getModel();
289+
assertNotNull(currentColumns);
290+
assertEquals(expectedColumns, currentColumns);
295291
}
296292

297293
/**
@@ -314,18 +310,16 @@ public void testSingleTraceExperimentDataProviderFetchColumn() {
314310
assertNotNull(customColumnId);
315311
assertNotNull(nsTimeColumnId);
316312

317-
List<@NonNull TmfTreeDataModel> expectedColumnEntries = Arrays.asList(
318-
new TmfTreeDataModel(startTimeColumnId, -1, Collections.singletonList(START_TIME_COLUMN_NAME)),
319-
new TmfTreeDataModel(endTimeColumnId, -1, Collections.singletonList(END_TIME_COLUMN_NAME)),
320-
new TmfTreeDataModel(durationColumnId, -1, Collections.singletonList(DURATION_COLUMN_NAME)),
321-
new TmfTreeDataModel(customColumnId, -1, Collections.singletonList(StubSegmentStoreProvider.STUB_COLUMN_NAME)),
322-
new TmfTreeDataModel(nsTimeColumnId, -1, Collections.singletonList(NS_TIME_COLUMN_NAME)));
323-
324-
TmfModelResponse<@NonNull TmfTreeModel<@NonNull TmfTreeDataModel>> response = fDataProvider.fetchTree(FetchParametersUtils.timeQueryToMap(new TimeQueryFilter(0, 0, 1)), null);
325-
TmfTreeModel<@NonNull TmfTreeDataModel> currentColumnModel = response.getModel();
326-
assertNotNull(currentColumnModel);
327-
List<@NonNull TmfTreeDataModel> currentColumnEntries = Objects.requireNonNull(currentColumnModel).getEntries();
328-
assertEquals(expectedColumnEntries, currentColumnEntries);
313+
List<@NonNull ITableColumnDescriptor> expectedColumns = Arrays.asList(
314+
new TableColumnDescriptor.Builder().setId(startTimeColumnId).setText(START_TIME_COLUMN_NAME).setTooltip("Start time of the segment").setDataType(DataType.TIMESTAMP).build(),
315+
new TableColumnDescriptor.Builder().setId(endTimeColumnId).setText(END_TIME_COLUMN_NAME).setTooltip("End time of the segment").setDataType(DataType.TIMESTAMP).build(),
316+
new TableColumnDescriptor.Builder().setId(durationColumnId).setText(DURATION_COLUMN_NAME).setTooltip("Segment duration").setDataType(DataType.DURATION).build(),
317+
new TableColumnDescriptor.Builder().setId(customColumnId).setText(StubSegmentStoreProvider.STUB_COLUMN_NAME).setTooltip("Stub segment column information").setDataType(DataType.STRING).build(),
318+
new TableColumnDescriptor.Builder().setId(nsTimeColumnId).setText(NS_TIME_COLUMN_NAME).setTooltip("Start time of the segment in nano seconds").setDataType(DataType.NUMBER).build());
319+
320+
List<@NonNull ITableColumnDescriptor> currentColumns = fDataProvider.fetchColumns(Collections.emptyMap(), null).getModel();
321+
assertNotNull(currentColumns);
322+
assertEquals(expectedColumns, currentColumns);
329323
}
330324

331325
/**
@@ -343,17 +337,15 @@ public void testInvalidExperimentDataProviderFetchColumn() {
343337
assertNotNull(durationColumnId);
344338
assertNotNull(nsTimeColumnId);
345339

346-
List<@NonNull TmfTreeDataModel> expectedColumnEntries = Arrays.asList(
347-
new TmfTreeDataModel(startTimeColumnId, -1, Collections.singletonList(START_TIME_COLUMN_NAME)),
348-
new TmfTreeDataModel(endTimeColumnId, -1, Collections.singletonList(END_TIME_COLUMN_NAME)),
349-
new TmfTreeDataModel(durationColumnId, -1, Collections.singletonList(DURATION_COLUMN_NAME)),
350-
new TmfTreeDataModel(nsTimeColumnId, -1, Collections.singletonList(NS_TIME_COLUMN_NAME)));
351-
352-
TmfModelResponse<@NonNull TmfTreeModel<@NonNull TmfTreeDataModel>> response = fInvalidDataProvider.fetchTree(FetchParametersUtils.timeQueryToMap(new TimeQueryFilter(0, 0, 1)), null);
353-
TmfTreeModel<@NonNull TmfTreeDataModel> currentColumnModel = response.getModel();
354-
assertNotNull(currentColumnModel);
355-
List<@NonNull TmfTreeDataModel> currentColumnEntries = Objects.requireNonNull(currentColumnModel).getEntries();
356-
assertEquals(expectedColumnEntries, currentColumnEntries);
340+
List<@NonNull ITableColumnDescriptor> expectedColumns = Arrays.asList(
341+
new TableColumnDescriptor.Builder().setId(startTimeColumnId).setText(START_TIME_COLUMN_NAME).setTooltip("Start time of the segment").setDataType(DataType.TIMESTAMP).build(),
342+
new TableColumnDescriptor.Builder().setId(endTimeColumnId).setText(END_TIME_COLUMN_NAME).setTooltip("End time of the segment").setDataType(DataType.TIMESTAMP).build(),
343+
new TableColumnDescriptor.Builder().setId(durationColumnId).setText(DURATION_COLUMN_NAME).setTooltip("Segment duration").setDataType(DataType.DURATION).build(),
344+
new TableColumnDescriptor.Builder().setId(nsTimeColumnId).setText(NS_TIME_COLUMN_NAME).setTooltip("Start time of the segment in nano seconds").setDataType(DataType.NUMBER).build());
345+
346+
List<@NonNull ITableColumnDescriptor> currentColumns = fInvalidDataProvider.fetchColumns(Collections.emptyMap(), null).getModel();
347+
assertNotNull(currentColumns);
348+
assertEquals(expectedColumns, currentColumns);
357349
}
358350

359351
/**

0 commit comments

Comments
 (0)