Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
Expand All @@ -37,6 +38,7 @@
import org.eclipse.tracecompass.tmf.core.model.ITableColumnDescriptor;
import org.eclipse.tracecompass.tmf.core.model.filters.FilterTimeQueryFilter;
import org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeModel;
import org.eclipse.tracecompass.tmf.core.response.ITmfResponse;
import org.eclipse.tracecompass.tmf.core.response.TmfModelResponse;
import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
import org.eclipse.tracecompass.tmf.tests.stubs.trace.xml.TmfXmlTraceStub;
Expand Down Expand Up @@ -74,14 +76,14 @@ public class SegmentStoreStatisticsDataProviderTest extends AbstractSegmentStore

private static final @NonNull List<@NonNull StatisticsHolder> EXPECTED_STATS_FULL = Arrays.asList(
new StatisticsHolder("", 0, -1, 0, 65534, 32767.0, 18918.46, 65535, 2147385345.0, 0, 0, 65534, 131068),
new StatisticsHolder("Total", 3, 0, 0, 65534, 32767.0, 18918.46, 65535, 2147385345.0, 0, 0, 65534, 131068),
new StatisticsHolder("even", 4, 3, 0, 65534, 32767.0, 18918.90, 32768, 1073709056.0, 0, 0, 65534, 131068),
new StatisticsHolder("odd", 5, 3, 1, 65533, 32767.0, 18918.32, 32767, 1073676289.0, 1, 2, 65533, 131066));
new StatisticsHolder("Total", 4, 0, 0, 65534, 32767.0, 18918.46, 65535, 2147385345.0, 0, 0, 65534, 131068),
new StatisticsHolder("even", 5, 4, 0, 65534, 32767.0, 18918.90, 32768, 1073709056.0, 0, 0, 65534, 131068),
new StatisticsHolder("odd", 6, 4, 1, 65533, 32767.0, 18918.32, 32767, 1073676289.0, 1, 2, 65533, 131066));

private static final @NonNull List<@NonNull StatisticsHolder> EXPECTED_STATS_SELECTION = Arrays.asList(
new StatisticsHolder("Selection", 6, 0, 512, 4096, 2304.0, 1035.04, 3585, 8259840.0, 512, 1024, 4096, 8192),
new StatisticsHolder("even", 7, 6, 512, 4096, 2304.0, 1035.48, 1793, 4131072.0, 512, 1024, 4096, 8192),
new StatisticsHolder("odd", 8, 6, 513, 4095, 2304.0, 1034.9, 1792, 4128768.0, 513, 1026, 4095, 8190));
new StatisticsHolder("Selection", 7, 0, 512, 4096, 2304.0, 1035.04, 3585, 8259840.0, 512, 1024, 4096, 8192),
new StatisticsHolder("even", 8, 7, 512, 4096, 2304.0, 1035.48, 1793, 4131072.0, 512, 1024, 4096, 8192),
new StatisticsHolder("odd", 9, 7, 513, 4095, 2304.0, 1034.9, 1792, 4128768.0, 513, 1026, 4095, 8190));

private static final List<@NonNull List<@NonNull String>> LIST_OF_EXPECTED_LABELS_WITH_MAPPER_FULL = Arrays.asList(
Arrays.asList("My", "0", "65534", "32767.0", "18918.46928268775", "65535", "2.147385345E9", "[0,0]", "[65534,131068]"),
Expand All @@ -91,9 +93,9 @@ public class SegmentStoreStatisticsDataProviderTest extends AbstractSegmentStore

private static final @NonNull List<@NonNull StatisticsHolder> EXPECTED_STATS_WITH_MAPPER_FULL = Arrays.asList(
new StatisticsHolder("My", 1, -1, 0, 65534, 32767.0, 18918.46, 65535, 2147385345.0, 0, 0, 65534, 131068),
new StatisticsHolder("MyTotal", 9, 1, 0, 65534, 32767.0, 18918.46, 65535, 2147385345.0, 0, 0, 65534, 131068),
new StatisticsHolder("Myeven", 10, 9, 0, 65534, 32767.0, 18918.90, 32768, 1073709056.0, 0, 0, 65534, 131068),
new StatisticsHolder("Myodd", 11, 9, 1, 65533, 32767.0, 18918.32, 32767, 1073676289.0, 1, 2, 65533, 131066));
new StatisticsHolder("MyTotal", 10, 1, 0, 65534, 32767.0, 18918.46, 65535, 2147385345.0, 0, 0, 65534, 131068),
new StatisticsHolder("Myeven", 11, 10, 0, 65534, 32767.0, 18918.90, 32768, 1073709056.0, 0, 0, 65534, 131068),
new StatisticsHolder("Myodd", 12, 10, 1, 65533, 32767.0, 18918.32, 32767, 1073676289.0, 1, 2, 65533, 131066));

private static final String USER_DEFINED_EXTRA_HEADER = "userDefinedHeader";
private static final String USER_DEFINED_EXTRA_VALUE = "userDefinedValue";
Expand All @@ -107,16 +109,17 @@ public class SegmentStoreStatisticsDataProviderTest extends AbstractSegmentStore
.collect(Collectors.toList());
private static final @NonNull List<@NonNull StatisticsHolderUserDefined> EXPECTED_STATS_FULL_USER_DEFINED = Arrays.asList(
new StatisticsHolderUserDefined("", 2, -1, 0, 65534, 32767.0, 18918.46, 65535, 2147385345.0, 0, 0, 65534, 131068, USER_DEFINED_EXTRA_VALUE),
new StatisticsHolderUserDefined("Total", 12, 2, 0, 65534, 32767.0, 18918.46, 65535, 2147385345.0, 0, 0, 65534, 131068, USER_DEFINED_EXTRA_VALUE),
new StatisticsHolderUserDefined("even", 13, 12, 0, 65534, 32767.0, 18918.90, 32768, 1073709056.0, 0, 0, 65534, 131068, USER_DEFINED_EXTRA_VALUE),
new StatisticsHolderUserDefined("odd", 14, 12, 1, 65533, 32767.0, 18918.32, 32767, 1073676289.0, 1, 2, 65533, 131066, USER_DEFINED_EXTRA_VALUE));
new StatisticsHolderUserDefined("Total", 13, 2, 0, 65534, 32767.0, 18918.46, 65535, 2147385345.0, 0, 0, 65534, 131068, USER_DEFINED_EXTRA_VALUE),
new StatisticsHolderUserDefined("even", 14, 13, 0, 65534, 32767.0, 18918.90, 32768, 1073709056.0, 0, 0, 65534, 131068, USER_DEFINED_EXTRA_VALUE),
new StatisticsHolderUserDefined("odd", 15, 13, 1, 65533, 32767.0, 18918.32, 32767, 1073676289.0, 1, 2, 65533, 131066, USER_DEFINED_EXTRA_VALUE));

private static List<ITableColumnDescriptor> fExpectedDescriptors;
private static List<ITableColumnDescriptor> fExpectedDescriptorsUserDefined;

private static SegmentStoreStatisticsDataProvider fTestDataProvider;
private static SegmentStoreStatisticsDataProvider fTestDataProvider2;
private static SegmentStoreStatisticsDataProvider fTestDataProviderWithUserDefinedAspect;
private static SegmentStoreStatisticsDataProvider fTestDataProviderWithModuleError;

private static TmfXmlTraceStub fTrace;

Expand Down Expand Up @@ -170,6 +173,10 @@ public String getName() {
}
};
fTestDataProviderWithUserDefinedAspect = new SegmentStoreStatisticsDataProvider(trace, fixture, "org.eclipse.tracecompass.analysis.timing.core.tests.segmentstore", Arrays.asList(userDefinedAspect));

fixture = getValidSegmentStats(fTrace, true);
fTestDataProviderWithModuleError = new SegmentStoreStatisticsDataProvider(trace, fixture, "org.eclipse.tracecompass.analysis.timing.core.tests.segmentstore");

}

/**
Expand All @@ -189,6 +196,10 @@ public static void cleanup() {
fTestDataProviderWithUserDefinedAspect.dispose();
}

if (fTestDataProviderWithModuleError != null) {
fTestDataProviderWithModuleError.dispose();
}

if (fTrace != null) {
fTrace.dispose();
}
Expand Down Expand Up @@ -341,11 +352,40 @@ public void testFetchTreeWithUserDefinedAspectsFullRange() {
EXPECTED_STATS_FULL_USER_DEFINED.size());
}

/**
* Verify that data provider query returns FAILED if analysis failed.
*/
@Test
public void testModuleExecutionError() {
long start = 1024;
long end = 4096;
FilterTimeQueryFilter filter = new FilterTimeQueryFilter(start, end, 2, true);
Map<@NonNull String, @NonNull Object> fetchParameters = FetchParametersUtils.filteredTimeQueryToMap(filter);
TmfModelResponse<@NonNull TmfTreeModel<@NonNull SegmentStoreStatisticsModel>> response = fTestDataProviderWithModuleError.fetchTree(fetchParameters, new NullProgressMonitor());
assertNotNull(response);
assertEquals(ITmfResponse.Status.FAILED, response.getStatus());
TmfTreeModel<@NonNull SegmentStoreStatisticsModel> treeModel = response.getModel();
assertNull(treeModel);
}


// ------------------------------------------------------------------------
// Helpers
// ------------------------------------------------------------------------
private static @NonNull StubSegmentStatisticsAnalysis getValidSegmentStats(@NonNull ITmfTrace trace) throws TmfAnalysisException {
StubSegmentStatisticsAnalysis fixture = new StubSegmentStatisticsAnalysis();
return getValidSegmentStats(trace, false);
}

private static @NonNull StubSegmentStatisticsAnalysis getValidSegmentStats(@NonNull ITmfTrace trace, boolean moduleError) throws TmfAnalysisException {
StubSegmentStatisticsAnalysis fixture = new StubSegmentStatisticsAnalysis() {
@Override
public boolean executeAnalysis(@NonNull IProgressMonitor monitor) throws TmfAnalysisException {
if (moduleError) {
throw new TmfAnalysisException("Failure");
}
return super.executeAnalysis(monitor);
}
};
fixture.setTrace(trace);
fixture.getDependentAnalyses();
fixture.schedule();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.osgi.util.NLS;
import org.eclipse.tracecompass.analysis.timing.core.segmentstore.SegmentStoreStatisticsModel;
import org.eclipse.tracecompass.analysis.timing.core.segmentstore.statistics.AbstractSegmentStatisticsAnalysis;
import org.eclipse.tracecompass.analysis.timing.core.statistics.IStatistics;
Expand Down Expand Up @@ -116,17 +117,26 @@ public SegmentStoreStatisticsDataProvider(ITmfTrace trace, IStatisticsAnalysis p
fModule = provider instanceof IAnalysisModule ? (IAnalysisModule) provider : null;
}

@SuppressWarnings("null")
@Override
public TmfModelResponse<TmfTreeModel<SegmentStoreStatisticsModel>> fetchTree(Map<String, Object> fetchParameters, @Nullable IProgressMonitor monitor) {
IAnalysisModule module = fModule;
boolean success = true;
if (module != null) {
if (monitor != null) {
module.waitForCompletion(monitor);
if (monitor.isCanceled()) {
success = module.waitForCompletion(monitor);
if (monitor.isCanceled() && module.getFailureCause() == null) {
return new TmfModelResponse<>(null, Status.CANCELLED, CommonStatusMessage.TASK_CANCELLED);
}
} else {
module.waitForCompletion();
success = module.waitForCompletion();
if (!success && module.getFailureCause() == null) {
return new TmfModelResponse<>(null, Status.CANCELLED, CommonStatusMessage.TASK_CANCELLED);
}
}

if (!success && module.getFailureCause() != null) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What should we do in case of failure but the failure cause is null?

@bhufmann bhufmann Sep 2, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be not detected because waitForCompletion returns a single boolean. We only can detect failure if failure cause is not null. So, I guess it's mandatory with the current implementation.

return new TmfModelResponse<>(null, Status.FAILED, NLS.bind(CommonStatusMessage.ANALYSIS_EXECUTION_FAILED, module.getFailureCause()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,17 @@ public final class CommonStatusMessage {
* A possible detailed message for a
* {@link org.eclipse.tracecompass.tmf.core.response.ITmfResponse.Status#FAILED}
* status
* @since 10.1
*/
public static final String ANALYSIS_INITIALIZATION_FAILED = Objects.requireNonNull(Messages.CommonStatusMessage_AnalysisInitializationFailed);

/**
* A possible detailed message for a
* {@link org.eclipse.tracecompass.tmf.core.response.ITmfResponse.Status#FAILED}
* status with error cause for failed analysis execution
*/
public static final String ANALYSIS_EXECUTION_FAILED = Objects.requireNonNull(Messages.CommonStatusMessage_AnalysisExecutionFailed);

/**
* A possible detailed message for a
* {@link org.eclipse.tracecompass.tmf.core.response.ITmfResponse.Status#FAILED}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ public class Messages extends NLS {
*/
public static @Nullable String CommonStatusMessage_AnalysisInitializationFailed;

/**
* Detailed message for failed status cause by an analysis initialization failure
* @since 10.1
*/
public static @Nullable String CommonStatusMessage_AnalysisExecutionFailed;

/**
* Detailed message for failed status cause by trying to access to statesystem
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ CommonStatusMessage_Running=Running
CommonStatusMessage_Completed=Completed
CommonStatusMessage_TaskCancelled=Task has been cancelled
CommonStatusMessage_AnalysisInitializationFailed=Initialization of module failed
CommonStatusMessage_AnalysisExecutionFailed=Failed executing analysis caused by {0}
CommonStatusMessage_StateSystemFailed=Getting statesystem failed
CommonStatusMessage_IncorrectQueryInterval=Incorrect query interval. Start time must be smaller than end time
CommonStatusMessage_IncorrectQueryParameters=Incorrect query parameters
Loading