Search in sources :

Example 1 with ITmfTreeXYDataProvider

use of org.eclipse.tracecompass.tmf.core.model.xy.ITmfTreeXYDataProvider in project tracecompass by tracecompass.

the class TmfTreeXYCompositeDataProvider method create.

/**
 * Return a composite {@link ITmfTreeXYDataProvider} from a list of traces.
 *
 * @param traces
 *            A list of traces from which to generate a provider.
 * @param title
 *            Chart's title
 * @param id
 *            the provider's ID
 * @param secondaryId
 *            The provider's secondaryId
 * @return null if the non of the traces returns a provider, the provider if the
 *         lists only return one, else a {@link TmfTreeXYCompositeDataProvider}
 *         encapsulating the providers
 */
@Nullable
public static ITmfTreeXYDataProvider<ITmfTreeDataModel> create(Collection<ITmfTrace> traces, String title, String id, @Nullable String secondaryId) {
    String providerId = secondaryId == null ? id : id + ':' + secondaryId;
    List<@NonNull ITmfTreeXYDataProvider<ITmfTreeDataModel>> providers = new ArrayList<>();
    for (ITmfTrace child : traces) {
        ITmfTreeXYDataProvider<ITmfTreeDataModel> provider = DataProviderManager.getInstance().getDataProvider(child, providerId, ITmfTreeXYDataProvider.class);
        if (provider != null) {
            providers.add(provider);
        }
    }
    if (providers.isEmpty()) {
        return null;
    } else if (providers.size() == 1) {
        return providers.get(0);
    }
    return new TmfTreeXYCompositeDataProvider<>(providers, title, providerId);
}
Also used : ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) ITmfTreeDataModel(org.eclipse.tracecompass.tmf.core.model.tree.ITmfTreeDataModel) ArrayList(java.util.ArrayList) ITmfTreeXYDataProvider(org.eclipse.tracecompass.tmf.core.model.xy.ITmfTreeXYDataProvider) Nullable(org.eclipse.jdt.annotation.Nullable)

Example 2 with ITmfTreeXYDataProvider

use of org.eclipse.tracecompass.tmf.core.model.xy.ITmfTreeXYDataProvider in project tracecompass by tracecompass.

the class DataProviderManagerTest method testGetter.

/**
 * Test different get methods
 */
@SuppressWarnings("unchecked")
@Test
public void testGetter() {
    ITmfTrace trace = fKernelTrace;
    assertNotNull(trace);
    ITmfTreeXYDataProvider<@NonNull ITmfTreeDataModel> dp = DataProviderManager.getInstance().getExistingDataProvider(trace, CPU_USAGE_DP_ID, ITmfTreeXYDataProvider.class);
    assertNull(dp);
    dp = DataProviderManager.getInstance().getOrCreateDataProvider(trace, CPU_USAGE_DP_ID, ITmfTreeXYDataProvider.class);
    assertNotNull(dp);
    ITmfTreeXYDataProvider<@NonNull ITmfTreeDataModel> dp2 = DataProviderManager.getInstance().getExistingDataProvider(trace, CPU_USAGE_DP_ID, ITmfTreeXYDataProvider.class);
    assertNotNull(dp2);
    assertTrue(dp == dp2);
    ITmfTreeXYDataProvider<@NonNull ITmfTreeDataModel> dp3 = DataProviderManager.getInstance().getOrCreateDataProvider(trace, CPU_USAGE_DP_ID, ITmfTreeXYDataProvider.class);
    assertNotNull(dp3);
    assertTrue(dp == dp3);
    assertTrue(dp == dp2);
}
Also used : ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) ITmfTreeDataModel(org.eclipse.tracecompass.tmf.core.model.tree.ITmfTreeDataModel) ITmfTreeXYDataProvider(org.eclipse.tracecompass.tmf.core.model.xy.ITmfTreeXYDataProvider) Test(org.junit.Test)

Example 3 with ITmfTreeXYDataProvider

use of org.eclipse.tracecompass.tmf.core.model.xy.ITmfTreeXYDataProvider in project tracecompass by tracecompass.

the class CounterDataProviderFactory method createProvider.

/**
 * @since 2.0
 */
@Override
@Nullable
public ITmfTreeXYDataProvider<? extends ITmfTreeDataModel> createProvider(ITmfTrace trace) {
    Collection<ITmfTrace> traces = TmfTraceManager.getTraceSet(trace);
    if (traces.size() == 1) {
        List<ITmfTreeXYDataProvider<TmfTreeDataModel>> dataProviders = new ArrayList<>();
        for (CounterAnalysis module : TmfTraceUtils.getAnalysisModulesOfClass(trace, CounterAnalysis.class)) {
            ITmfTrace subTrace = module.getTrace();
            ITmfTreeXYDataProvider<TmfTreeDataModel> provider = CounterDataProvider.create(Objects.requireNonNull(subTrace), module);
            if (provider != null) {
                dataProviders.add(provider);
            }
        }
        if (dataProviders.isEmpty()) {
            return null;
        } else if (dataProviders.size() == 1) {
            return dataProviders.get(0);
        }
        return new TmfTreeXYCompositeDataProvider<>(dataProviders, TITLE, CounterDataProvider.ID);
    }
    return TmfTreeXYCompositeDataProvider.create(traces, TITLE, CounterDataProvider.ID);
}
Also used : ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) TmfTreeXYCompositeDataProvider(org.eclipse.tracecompass.internal.tmf.core.model.xy.TmfTreeXYCompositeDataProvider) CounterAnalysis(org.eclipse.tracecompass.analysis.counters.core.CounterAnalysis) ArrayList(java.util.ArrayList) ITmfTreeXYDataProvider(org.eclipse.tracecompass.tmf.core.model.xy.ITmfTreeXYDataProvider) ITmfTreeDataModel(org.eclipse.tracecompass.tmf.core.model.tree.ITmfTreeDataModel) TmfTreeDataModel(org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeDataModel) Nullable(org.eclipse.jdt.annotation.Nullable)

Aggregations

ITmfTreeDataModel (org.eclipse.tracecompass.tmf.core.model.tree.ITmfTreeDataModel)3 ITmfTreeXYDataProvider (org.eclipse.tracecompass.tmf.core.model.xy.ITmfTreeXYDataProvider)3 ITmfTrace (org.eclipse.tracecompass.tmf.core.trace.ITmfTrace)3 ArrayList (java.util.ArrayList)2 Nullable (org.eclipse.jdt.annotation.Nullable)2 CounterAnalysis (org.eclipse.tracecompass.analysis.counters.core.CounterAnalysis)1 TmfTreeXYCompositeDataProvider (org.eclipse.tracecompass.internal.tmf.core.model.xy.TmfTreeXYCompositeDataProvider)1 TmfTreeDataModel (org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeDataModel)1 Test (org.junit.Test)1