use of org.eclipse.tracecompass.tmf.core.util.Pair in project tracecompass by tracecompass.
the class StateSystemDataProvider method addSubAttributes.
private void addSubAttributes(@Nullable IProgressMonitor monitor, Long parentId, Long startTime, Long endTime, ITmfStateSystem ss, Integer attrib) {
String name = ss.getAttributeName(attrib);
// see if the entry already exist or not
EntryModelBuilder entry = fEntryBuilder.get(parentId, name);
AttributeEntryModel.Builder attributeEntry;
if (entry instanceof AttributeEntryModel.Builder) {
attributeEntry = (AttributeEntryModel.Builder) entry;
} else {
Long id = ENTRY_ID.getAndIncrement();
attributeEntry = new AttributeEntryModel.Builder(id, parentId, name, startTime, endTime, attrib);
fEntryBuilder.put(parentId, name, attributeEntry);
}
long id = attributeEntry.getId();
Pair<ITmfStateSystem, Integer> displayQuark = new Pair<>(ss, attrib);
fIDToDisplayQuark.put(id, displayQuark);
// Add child entry
for (Integer child : ss.getSubAttributes(attrib, false)) {
if (monitor != null && monitor.isCanceled()) {
return;
}
addSubAttributes(monitor, id, startTime, endTime, ss, child);
}
// Update entry
attributeEntry.setEndTime(endTime);
fEntryBuilder.put(parentId, name, attributeEntry);
}
use of org.eclipse.tracecompass.tmf.core.util.Pair in project tracecompass by tracecompass.
the class StateSystemDataProvider method fetchTooltip.
@Override
public TmfModelResponse<Map<String, String>> fetchTooltip(Map<String, Object> fetchParameters, @Nullable IProgressMonitor monitor) {
Map<Long, Pair<ITmfStateSystem, Integer>> entries = getSelectedEntries(fetchParameters);
if (entries.size() != 1) {
// Not the expected size of tooltip, just return empty
return new TmfModelResponse<>(null, Status.COMPLETED, CommonStatusMessage.COMPLETED);
}
Entry<@NonNull Long, @NonNull Pair<ITmfStateSystem, Integer>> entry = entries.entrySet().iterator().next();
Map<String, String> tooltip = new HashMap<>();
Integer quark = Objects.requireNonNull(entry.getValue()).getSecond();
ITmfStateSystem ss = Objects.requireNonNull(entry.getValue()).getFirst();
tooltip.put(String.valueOf(Messages.QuarkColumnLabel), Integer.toString(quark));
tooltip.put(String.valueOf(Messages.AttributePathColumnLabel), ss.getFullAttributePath(quark));
tooltip.put(String.valueOf(Messages.ValueColumnLabel), getQuarkValue(fetchParameters, ss, quark));
return new TmfModelResponse<>(tooltip, Status.COMPLETED, CommonStatusMessage.COMPLETED);
}
use of org.eclipse.tracecompass.tmf.core.util.Pair in project tracecompass by tracecompass.
the class TmfTraceType method selectTraceType.
/**
* This method figures out the trace type of a given trace.
*
* @param path
* The path of trace to import (file or directory for directory traces)
* @param traceTypeHint
* the ID of a trace (like "o.e.l.specifictrace" )
* @return a list of {@link TraceTypeHelper} sorted by confidence (highest first)
*
* @throws TmfTraceImportException
* if there are errors in the trace file or no trace type found
* for a directory trace
* @since 2.0
*/
@NonNull
public static List<TraceTypeHelper> selectTraceType(String path, String traceTypeHint) throws TmfTraceImportException {
Comparator<Pair<Integer, TraceTypeHelper>> comparator = (o1, o2) -> {
// invert so that highest confidence is first
int res = o2.getFirst().compareTo(o1.getFirst());
if (res == 0) {
res = o1.getSecond().getName().compareTo(o2.getSecond().getName());
}
return res;
};
TreeSet<Pair<Integer, TraceTypeHelper>> validCandidates = new TreeSet<>(comparator);
final Iterable<TraceTypeHelper> traceTypeHelpers = TmfTraceType.getTraceTypeHelpers();
for (TraceTypeHelper traceTypeHelper : traceTypeHelpers) {
if (!traceTypeHelper.isEnabled() || traceTypeHelper.isExperimentType()) {
continue;
}
int confidence = traceTypeHelper.validateWithConfidence(path);
if (confidence >= 0) {
if (traceTypeHelper.getTraceTypeId().equals(traceTypeHint)) {
// if the trace type hint is valid, return it immediately
return Collections.singletonList(traceTypeHelper);
}
// insert in the tree map, ordered by confidence (highest confidence first) then name
Pair<Integer, TraceTypeHelper> element = new Pair<>(confidence, traceTypeHelper);
validCandidates.add(element);
}
}
List<TraceTypeHelper> returned = new ArrayList<>();
if (validCandidates.isEmpty()) {
File traceFile = new File(path);
if (traceFile.isFile()) {
return returned;
}
final String errorMsg = NLS.bind(Messages.TmfOpenTraceHelper_NoTraceTypeMatch, path);
throw new TmfTraceImportException(errorMsg);
}
if (validCandidates.size() != 1) {
List<Pair<Integer, TraceTypeHelper>> reducedCandidates = reduce(validCandidates);
if (reducedCandidates.isEmpty()) {
// $NON-NLS-1$
throw new TmfTraceImportException("Error reducing trace type candidates");
} else if (reducedCandidates.size() == 1) {
// Don't select the trace type if it has the lowest confidence
if (reducedCandidates.get(0).getFirst() > 0) {
returned.add(reducedCandidates.get(0).getSecond());
}
} else {
for (Pair<Integer, TraceTypeHelper> candidatePair : reducedCandidates) {
// Don't select the trace type if it has the lowest confidence
if (candidatePair.getFirst() > 0) {
returned.add(candidatePair.getSecond());
}
}
}
} else {
// Don't select the trace type if it has the lowest confidence
if (validCandidates.first().getFirst() > 0) {
returned.add(validCandidates.first().getSecond());
}
}
return returned;
}
use of org.eclipse.tracecompass.tmf.core.util.Pair in project tracecompass by tracecompass.
the class TracePackageImportOperation method importTraceFiles.
private IStatus importTraceFiles(TracePackageFilesElement traceFilesElement, TracePackageTraceElement traceElement, IProgressMonitor monitor) {
List<Pair<String, String>> fileNameAndLabelPairs = new ArrayList<>();
String sourceName = checkNotNull(traceFilesElement.getFileName());
String destinationName = checkNotNull(traceElement.getImportName());
fileNameAndLabelPairs.add(new Pair<>(sourceName, destinationName));
IPath containerPath = fTmfTraceFolder.getPath();
IStatus status = importFiles(getSpecifiedArchiveFile(), fileNameAndLabelPairs, containerPath, Path.EMPTY, Collections.emptyMap(), monitor);
if (!getStatus().isOK()) {
return status;
}
// We need to set the trace type before importing the supplementary files so we do it here
IResource traceRes = fTmfTraceFolder.getResource().findMember(traceElement.getDestinationElementPath());
if (traceRes == null || !traceRes.exists()) {
return new Status(IStatus.ERROR, Activator.PLUGIN_ID, MessageFormat.format(Messages.ImportTracePackageWizardPage_ErrorFindingImportedTrace, destinationName));
}
TraceTypeHelper traceType = null;
String traceTypeStr = traceElement.getTraceType();
if (traceTypeStr != null) {
traceType = TmfTraceType.getTraceType(traceTypeStr);
if (traceType == null) {
return new Status(IStatus.ERROR, Activator.PLUGIN_ID, MessageFormat.format(Messages.ImportTracePackageWizardPage_ErrorSettingTraceType, traceElement.getTraceType(), destinationName));
}
} else {
try {
monitor.subTask(MessageFormat.format(Messages.TracePackageImportOperation_DetectingTraceType, destinationName));
traceType = TmfTraceTypeUIUtils.selectTraceType(traceRes.getLocation().toOSString(), null, null);
} catch (TmfTraceImportException e) {
// Could not figure out the type
}
}
if (traceType != null) {
try {
TmfTraceTypeUIUtils.setTraceType(traceRes, traceType);
} catch (CoreException e) {
return new Status(IStatus.ERROR, Activator.PLUGIN_ID, MessageFormat.format(Messages.ImportTracePackageWizardPage_ErrorSettingTraceType, traceElement.getTraceType(), destinationName), e);
}
}
importBookmarks(traceRes, traceElement, monitor);
try {
URI uri = new File(getFileName()).toURI();
IPath entryPath = new Path(traceFilesElement.getFileName());
if (traceRes instanceof IFolder) {
entryPath = entryPath.addTrailingSeparator();
}
String sourceLocation = URIUtil.toUnencodedString(URIUtil.toJarURI(uri, entryPath));
traceRes.setPersistentProperty(TmfCommonConstants.SOURCE_LOCATION, sourceLocation);
} catch (CoreException e) {
}
return status;
}
use of org.eclipse.tracecompass.tmf.core.util.Pair in project tracecompass by tracecompass.
the class StateSystemDataProvider method getSelectedEntries.
private Map<Long, Pair<ITmfStateSystem, Integer>> getSelectedEntries(Map<String, Object> fetchParameters) {
Collection<Long> selectedItems = DataProviderParameterUtils.extractSelectedItems(fetchParameters);
if (selectedItems == null) {
return Collections.emptyMap();
}
Map<Long, Pair<ITmfStateSystem, Integer>> idToQuark = new HashMap<>();
synchronized (fEntryBuilder) {
for (Long id : selectedItems) {
Pair<ITmfStateSystem, Integer> pair = fIDToDisplayQuark.get(id);
if (pair != null) {
idToQuark.put(id, pair);
}
}
}
return idToQuark;
}
Aggregations