Skip to content

Commit

Permalink
callstack: Prepare FlameChartDataProviderFactory
Browse files Browse the repository at this point in the history
Bring FlameChartDataProviderFactory from Incubator in turn. This should
start being exercised next as LttngUstCallStackAnalysis is also brought
in. Keep this for another focused change series.

[Added] o.e.t.i.a.callstack.core.instrumented.FlameChartDataProviderFactory

Change-Id: I2ad1b8829c54287739f354ed9d69381a1fc449a2
Signed-off-by: Marco Miller <marco.miller@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/c/tracecompass/org.eclipse.tracecompass/+/199591
Tested-by: Trace Compass Bot <tracecompass-bot@eclipse.org>
Tested-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
Reviewed-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
  • Loading branch information
marco-miller committed Mar 31, 2023
1 parent 6814994 commit 441d948
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<!-- TODO extension
<extension
point="org.eclipse.tracecompass.tmf.core.dataprovider">
</extension -->
<dataProviderFactory
class="org.eclipse.tracecompass.internal.analysis.callstack.core.instrumented.FlameChartDataProviderFactory"
id="org.eclipse.tracecompass.analysis.callstack.core.flamechart">
</dataProviderFactory>
</extension>
</plugin>
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*******************************************************************************
* Copyright (c) 2018 École Polytechnique de Montréal
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License 2.0 which
* accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/

package org.eclipse.tracecompass.internal.analysis.callstack.core.instrumented;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.Set;

import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.osgi.util.NLS;
import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule;
import org.eclipse.tracecompass.tmf.core.component.DataProviderConstants;
import org.eclipse.tracecompass.tmf.core.dataprovider.IDataProviderDescriptor;
import org.eclipse.tracecompass.tmf.core.dataprovider.IDataProviderDescriptor.ProviderType;
import org.eclipse.tracecompass.tmf.core.dataprovider.IDataProviderFactory;
import org.eclipse.tracecompass.tmf.core.model.DataProviderDescriptor;
import org.eclipse.tracecompass.tmf.core.model.timegraph.TmfTimeGraphCompositeDataProvider;
import org.eclipse.tracecompass.tmf.core.model.tree.ITmfTreeDataModel;
import org.eclipse.tracecompass.tmf.core.model.tree.ITmfTreeDataProvider;
import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils;

import com.google.common.collect.Iterables;

/**
* Factory for the flame chart data provider
*
* @author Geneviève Bastien
*/
public class FlameChartDataProviderFactory implements IDataProviderFactory {

@Override
public @Nullable ITmfTreeDataProvider<? extends ITmfTreeDataModel> createProvider(ITmfTrace trace) {
// Need the analysis
return null;
}

@Override
public @Nullable ITmfTreeDataProvider<? extends ITmfTreeDataModel> createProvider(ITmfTrace trace, String secondaryId) {
// Create with the trace or experiment first
ITmfTreeDataProvider<? extends ITmfTreeDataModel> provider = create(trace, secondaryId);
if (provider != null) {
return provider;
}
// Otherwise, see if it's an experiment and create a composite if that's
// the case
Collection<ITmfTrace> traces = TmfTraceManager.getTraceSet(trace);
if (traces.size() > 1) {
// Try creating a composite only if there are many traces,
// otherwise, the previous call to create should have returned the
// data provider
return TmfTimeGraphCompositeDataProvider.create(traces, FlameChartDataProvider.ID, secondaryId);
}
return null;
}

private static @Nullable ITmfTreeDataProvider<? extends ITmfTreeDataModel> create(ITmfTrace trace, String secondaryId) {
// The trace can be an experiment, so we need to know if there are
// multiple analysis modules with the same ID
Iterable<IFlameChartProvider> modules = TmfTraceUtils.getAnalysisModulesOfClass(trace, IFlameChartProvider.class);
Iterable<IFlameChartProvider> filteredModules = Iterables.filter(modules, m -> ((IAnalysisModule) m).getId().equals(secondaryId));
Iterator<IFlameChartProvider> iterator = filteredModules.iterator();
if (iterator.hasNext()) {
IFlameChartProvider module = iterator.next();
if (iterator.hasNext()) {
// More than one module, must be an experiment, return null so
// the factory can try with individual traces
return null;
}
((IAnalysisModule) module).schedule();
return new FlameChartDataProvider(trace, module, secondaryId);
}
return null;
}

@Override
public Collection<IDataProviderDescriptor> getDescriptors(ITmfTrace trace) {
Iterable<IFlameChartProvider> modules = TmfTraceUtils.getAnalysisModulesOfClass(trace, IFlameChartProvider.class);
List<IDataProviderDescriptor> descriptors = new ArrayList<>();
Set<String> existingModules = new HashSet<>();
for (IFlameChartProvider module : modules) {
IAnalysisModule analysis = module;
// Only add analysis once per trace (which could be an experiment)
if (!existingModules.contains(analysis.getId())) {
DataProviderDescriptor.Builder builder = new DataProviderDescriptor.Builder();
builder.setId(FlameChartDataProvider.ID + DataProviderConstants.ID_SEPARATOR + analysis.getId())
.setName(Objects.requireNonNull(Messages.FlameChartDataProvider_Title + " " + analysis.getName())) //$NON-NLS-1$
.setDescription(Objects.requireNonNull(NLS.bind(Messages.FlameChartDataProvider_Description, analysis.getHelpText())))
.setProviderType(ProviderType.TIME_GRAPH);
descriptors.add(builder.build());
existingModules.add(analysis.getId());
}
}
return descriptors;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ public class Messages extends NLS {
/** Title of kernel status rows */
public static @Nullable String FlameChartDataProvider_KernelStatusTitle;

/** Title of the dataprovider */
public static @Nullable String FlameChartDataProvider_Title;

/** Messages.FlameChartDataProvider_Title */
public static @Nullable String FlameChartDataProvider_Description;

static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@
FlameChartDataProvider_Symbol=Symbol
FlameChartDataProvider_ThreadId=TID
FlameChartDataProvider_KernelStatusTitle=Kernel statuses
FlameChartDataProvider_Title=FlameChart
FlameChartDataProvider_Description=Show FlameChart provided by {0}

0 comments on commit 441d948

Please sign in to comment.