Search in sources :

Example 1 with Pair

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);
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) ITmfStateSystem(org.eclipse.tracecompass.statesystem.core.ITmfStateSystem) Pair(org.eclipse.tracecompass.tmf.core.util.Pair)

Example 2 with Pair

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);
}
Also used : HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) AtomicLong(java.util.concurrent.atomic.AtomicLong) TmfModelResponse(org.eclipse.tracecompass.tmf.core.response.TmfModelResponse) Pair(org.eclipse.tracecompass.tmf.core.util.Pair) ITmfStateSystem(org.eclipse.tracecompass.statesystem.core.ITmfStateSystem)

Example 3 with Pair

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;
}
Also used : CustomXmlTrace(org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlTrace) HashMap(java.util.HashMap) CoreException(org.eclipse.core.runtime.CoreException) Pair(org.eclipse.tracecompass.tmf.core.util.Pair) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) IStatus(org.eclipse.core.runtime.IStatus) Activator(org.eclipse.tracecompass.internal.tmf.core.Activator) Map(java.util.Map) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) CustomTxtTrace(org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtTrace) CustomTxtTraceDefinition(org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtTraceDefinition) ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) NLS(org.eclipse.osgi.util.NLS) CustomXmlTraceDefinition(org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlTraceDefinition) Collection(java.util.Collection) TmfCommonConstants(org.eclipse.tracecompass.tmf.core.TmfCommonConstants) File(java.io.File) Messages(org.eclipse.tracecompass.internal.tmf.core.project.model.Messages) List(java.util.List) IResource(org.eclipse.core.resources.IResource) Entry(java.util.Map.Entry) Platform(org.eclipse.core.runtime.Platform) Comparator(java.util.Comparator) TmfSignalManager(org.eclipse.tracecompass.tmf.core.signal.TmfSignalManager) Collections(java.util.Collections) NonNull(org.eclipse.jdt.annotation.NonNull) ArrayList(java.util.ArrayList) TreeSet(java.util.TreeSet) File(java.io.File) Pair(org.eclipse.tracecompass.tmf.core.util.Pair) NonNull(org.eclipse.jdt.annotation.NonNull)

Example 4 with Pair

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;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IStatus(org.eclipse.core.runtime.IStatus) IPath(org.eclipse.core.runtime.IPath) ArrayList(java.util.ArrayList) URI(java.net.URI) TraceTypeHelper(org.eclipse.tracecompass.tmf.core.project.model.TraceTypeHelper) TmfTraceImportException(org.eclipse.tracecompass.tmf.core.project.model.TmfTraceImportException) CoreException(org.eclipse.core.runtime.CoreException) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IResource(org.eclipse.core.resources.IResource) Pair(org.eclipse.tracecompass.tmf.core.util.Pair) IFolder(org.eclipse.core.resources.IFolder)

Example 5 with Pair

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;
}
Also used : HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) AtomicLong(java.util.concurrent.atomic.AtomicLong) Pair(org.eclipse.tracecompass.tmf.core.util.Pair) ITmfStateSystem(org.eclipse.tracecompass.statesystem.core.ITmfStateSystem)

Aggregations

Pair (org.eclipse.tracecompass.tmf.core.util.Pair)8 HashMap (java.util.HashMap)4 IStatus (org.eclipse.core.runtime.IStatus)4 ArrayList (java.util.ArrayList)3 AtomicLong (java.util.concurrent.atomic.AtomicLong)3 ITmfStateSystem (org.eclipse.tracecompass.statesystem.core.ITmfStateSystem)3 File (java.io.File)2 LinkedHashMap (java.util.LinkedHashMap)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 IFolder (org.eclipse.core.resources.IFolder)2 IResource (org.eclipse.core.resources.IResource)2 CoreException (org.eclipse.core.runtime.CoreException)2 IPath (org.eclipse.core.runtime.IPath)2 Path (org.eclipse.core.runtime.Path)2 Status (org.eclipse.core.runtime.Status)2 ITmfTrace (org.eclipse.tracecompass.tmf.core.trace.ITmfTrace)2 URI (java.net.URI)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1