The filtering on event type is replaced with filtering on trace type.
This is done because in the upcoming change to replace field-based
filtering with aspect-based filtering, the aspect list is dependent on
the trace type and not on the event type. Furthermore filtering on event
type will still be possible since an 'Event type' aspect is available.
With this patch, the narrowing of field list based on event type for
child nodes of an EVENTTYPE node is no longer supported. In the
upcoming patch the aspect list will be narrowed based on trace type for
child nodes of a TRACETYPE node.
The handling of trace type labels "category : name" is consolidated in
utility classes TmfTraceType and TraceTypeHelper.
Change-Id: Ie911e9c63ecf7e219540e038fd82e70415e2e0ee
Signed-off-by: Patrick Tasse <patrick.tasse@gmail.com>
Reviewed-on: https://git.eclipse.org/r/38514
Reviewed-by: Hudson CI
Reviewed-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
Tested-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2010, 2014 Ericsson
- *
- * All rights reserved. This program and the accompanying materials are
- * made available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Patrick Tasse - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.tracecompass.tmf.core.filter.model;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
-
-/**
- * Filter node for an event
- *
- * @version 1.0
- * @author Patrick Tasse
- */
-@SuppressWarnings("javadoc")
-public class TmfFilterEventTypeNode extends TmfFilterTreeNode {
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = super.hashCode();
- result = prime * result + ((fName == null) ? 0 : fName.hashCode());
- result = prime * result + ((fType == null) ? 0 : fType.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!super.equals(obj)) {
- return false;
- }
- if (getClass() != obj.getClass()) {
- return false;
- }
- TmfFilterEventTypeNode other = (TmfFilterEventTypeNode) obj;
- if (fName == null) {
- if (other.fName != null) {
- return false;
- }
- } else if (!fName.equals(other.fName)) {
- return false;
- }
- if (fType == null) {
- if (other.fType != null) {
- return false;
- }
- } else if (!fType.equals(other.fType)) {
- return false;
- }
- return true;
- }
-
- public static final String NODE_NAME = "EVENTTYPE"; //$NON-NLS-1$
- public static final String TYPE_ATTR = "type"; //$NON-NLS-1$
- public static final String NAME_ATTR = "name"; //$NON-NLS-1$
-
- private String fType;
- private String fName;
-
- /**
- * @param parent the parent node
- */
- public TmfFilterEventTypeNode(ITmfFilterTreeNode parent) {
- super(parent);
- }
-
- @Override
- public String getNodeName() {
- return NODE_NAME;
- }
-
- /**
- * @return the event type
- */
- public String getEventType() {
- return fType;
- }
-
- /**
- * @param type the event type
- */
- public void setEventType(String type) {
- this.fType = type;
- }
-
- /**
- * @return the category and trace type name
- */
- public String getName() {
- return fName;
- }
-
- /**
- * @param name the category and trace type name
- */
- public void setName(String name) {
- this.fName = name;
- }
-
- @Override
- public boolean matches(ITmfEvent event) {
- boolean match = false;
- if (fType.contains(":")) { //$NON-NLS-1$
- // special case for custom parsers
- if (fType.startsWith(event.getClass().getCanonicalName())) {
- if (fType.endsWith(event.getType().getName())) {
- match = true;
- }
- }
- } else {
- if (event.getClass().getCanonicalName().equals(fType)) {
- match = true;
- }
- }
- if (match) {
- // There should be at most one child
- for (ITmfFilterTreeNode node : getChildren()) {
- if (! node.matches(event)) {
- return false;
- }
- }
- return true;
- }
- return false;
- }
-
- @Override
- public List<String> getValidChildren() {
- if (getChildrenCount() == 0) {
- return super.getValidChildren();
- }
- return new ArrayList<>(0); // only one child allowed
- }
-
- @Override
- public String toString() {
- StringBuffer buf = new StringBuffer();
- buf.append("EventType is " + fName); //$NON-NLS-1$
- if (getChildrenCount() > 0) {
- buf.append(" and "); //$NON-NLS-1$
- }
- if (getChildrenCount() > 1) {
- buf.append("( "); //$NON-NLS-1$
- }
- for (int i = 0; i < getChildrenCount(); i++) {
- ITmfFilterTreeNode node = getChildren()[i];
- buf.append(node.toString());
- if (i < getChildrenCount() - 1) {
- buf.append(" and "); //$NON-NLS-1$
- }
- }
- if (getChildrenCount() > 1) {
- buf.append(" )"); //$NON-NLS-1$
- }
- return buf.toString();
- }
-}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2010, 2015 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Patrick Tasse - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.core.filter.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
+import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
+
+/**
+ * Filter node for an trace type
+ *
+ * @version 1.0
+ * @author Patrick Tasse
+ */
+@SuppressWarnings("javadoc")
+public class TmfFilterTraceTypeNode extends TmfFilterTreeNode {
+
+ public static final String NODE_NAME = "TRACETYPE"; //$NON-NLS-1$
+ public static final String TYPE_ATTR = "type"; //$NON-NLS-1$
+ public static final String NAME_ATTR = "name"; //$NON-NLS-1$
+
+ private String fTraceTypeId;
+ private Class<? extends ITmfTrace> fTraceClass;
+ private String fName;
+
+ /**
+ * @param parent the parent node
+ */
+ public TmfFilterTraceTypeNode(ITmfFilterTreeNode parent) {
+ super(parent);
+ }
+
+ @Override
+ public String getNodeName() {
+ return NODE_NAME;
+ }
+
+ /**
+ * @return the trace type id
+ */
+ public String getTraceTypeId() {
+ return fTraceTypeId;
+ }
+
+ /**
+ * @param traceTypeId the trace type id
+ */
+ public void setTraceTypeId(String traceTypeId) {
+ this.fTraceTypeId = traceTypeId;
+ }
+
+ /**
+ * @return the trace class
+ */
+ public Class<? extends ITmfTrace> getTraceClass() {
+ return fTraceClass;
+ }
+
+ /**
+ * @param traceClass the trace class
+ */
+ public void setTraceClass(Class<? extends ITmfTrace> traceClass) {
+ this.fTraceClass = traceClass;
+ }
+
+ /**
+ * @return the category and trace type name
+ */
+ public String getName() {
+ return fName;
+ }
+
+ /**
+ * @param name the category and trace type name
+ */
+ public void setName(String name) {
+ this.fName = name;
+ }
+
+ @Override
+ public boolean matches(ITmfEvent event) {
+ boolean match = false;
+ ITmfTrace trace = event.getTrace();
+ if (trace.getClass().equals(fTraceClass)) {
+ if (fTraceTypeId != null) {
+ if (fTraceTypeId.equals(trace.getTraceTypeId())) {
+ match = true;
+ }
+ } else {
+ match = true;
+ }
+ }
+ if (match) {
+ // There should be at most one child
+ for (ITmfFilterTreeNode node : getChildren()) {
+ if (! node.matches(event)) {
+ return false;
+ }
+ }
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public List<String> getValidChildren() {
+ if (getChildrenCount() == 0) {
+ return super.getValidChildren();
+ }
+ return new ArrayList<>(0); // only one child allowed
+ }
+
+ @Override
+ public String toString() {
+ StringBuffer buf = new StringBuffer();
+ buf.append("TraceType is " + fName); //$NON-NLS-1$
+ if (getChildrenCount() > 0) {
+ buf.append(" and "); //$NON-NLS-1$
+ }
+ if (getChildrenCount() > 1) {
+ buf.append("( "); //$NON-NLS-1$
+ }
+ for (int i = 0; i < getChildrenCount(); i++) {
+ ITmfFilterTreeNode node = getChildren()[i];
+ buf.append(node.toString());
+ if (i < getChildrenCount() - 1) {
+ buf.append(" and "); //$NON-NLS-1$
+ }
+ }
+ if (getChildrenCount() > 1) {
+ buf.append(" )"); //$NON-NLS-1$
+ }
+ return buf.toString();
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = super.hashCode();
+ result = prime * result + ((fName == null) ? 0 : fName.hashCode());
+ result = prime * result + ((fTraceTypeId == null) ? 0 : fTraceTypeId.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (!super.equals(obj)) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ TmfFilterTraceTypeNode other = (TmfFilterTraceTypeNode) obj;
+ if (fName == null) {
+ if (other.fName != null) {
+ return false;
+ }
+ } else if (!fName.equals(other.fName)) {
+ return false;
+ }
+ if (fTraceTypeId == null) {
+ if (other.fTraceTypeId != null) {
+ return false;
+ }
+ } else if (!fTraceTypeId.equals(other.fTraceTypeId)) {
+ return false;
+ }
+ return true;
+ }
+}
/*******************************************************************************
- * Copyright (c) 2010, 2014 Ericsson
+ * Copyright (c) 2010, 2015 Ericsson
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v1.0 which
private static final char BACKSLASH = '\\';
private static final String[] VALID_CHILDREN = {
- TmfFilterEventTypeNode.NODE_NAME,
+ TmfFilterTraceTypeNode.NODE_NAME,
TmfFilterAndNode.NODE_NAME,
TmfFilterOrNode.NODE_NAME,
TmfFilterContainsNode.NODE_NAME,
/*******************************************************************************
- * Copyright (c) 2010, 2014 Ericsson
+ * Copyright (c) 2010, 2015 Ericsson
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v1.0 which
import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterCompareNode;
import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterContainsNode;
import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterEqualsNode;
-import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterEventTypeNode;
import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterMatchesFieldNode;
import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterMatchesNode;
import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterNode;
import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterOrNode;
import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterRootNode;
+import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterTraceTypeNode;
import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterTreeNode;
import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterCompareNode.Type;
+import org.eclipse.tracecompass.tmf.core.project.model.TmfTraceType;
+import org.eclipse.tracecompass.tmf.core.project.model.TraceTypeHelper;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
*/
public class TmfFilterContentHandler extends DefaultHandler {
+ // Backward compatibility strings
+ private static final String EVENTTYPE_NODE_NAME = "EVENTTYPE"; //$NON-NLS-1$
+ private static final String NAME_ATTR = "name"; //$NON-NLS-1$
+ private static final String LTTNG_KERNEL_TRACE = "Common Trace Format : LTTng Kernel Trace"; //$NON-NLS-1$
+ private static final String LINUX_KERNEL_TRACE = "Common Trace Format : Linux Kernel Trace"; //$NON-NLS-1$
+
private ITmfFilterTreeNode fRoot = null;
private Stack<ITmfFilterTreeNode> fFilterTreeStack = null;
node = new TmfFilterNode(atts.getValue(TmfFilterNode.NAME_ATTR));
- } else if (localName.equals(TmfFilterEventTypeNode.NODE_NAME)) {
+ } else if (localName.equals(TmfFilterTraceTypeNode.NODE_NAME)) {
- node = new TmfFilterEventTypeNode(null);
- ((TmfFilterEventTypeNode) node).setEventType(atts.getValue(TmfFilterEventTypeNode.TYPE_ATTR));
- ((TmfFilterEventTypeNode) node).setName(atts.getValue(TmfFilterEventTypeNode.NAME_ATTR));
+ node = new TmfFilterTraceTypeNode(null);
+ String traceTypeId = atts.getValue(TmfFilterTraceTypeNode.TYPE_ATTR);
+ ((TmfFilterTraceTypeNode) node).setTraceTypeId(traceTypeId);
+ TraceTypeHelper helper = TmfTraceType.getTraceType(traceTypeId);
+ if (helper != null) {
+ ((TmfFilterTraceTypeNode) node).setTraceClass(helper.getTraceClass());
+ }
+ ((TmfFilterTraceTypeNode) node).setName(atts.getValue(TmfFilterTraceTypeNode.NAME_ATTR));
} else if (localName.equals(TmfFilterAndNode.NODE_NAME)) {
}
((TmfFilterCompareNode) node).setValue(atts.getValue(TmfFilterCompareNode.VALUE_ATTR));
+ // Backward compatibility with event type filter node
+ } else if (localName.equals(EVENTTYPE_NODE_NAME)) {
+
+ node = new TmfFilterTraceTypeNode(null);
+ String label = atts.getValue(NAME_ATTR);
+ if (label != null) {
+ // Backward compatibility with renamed LTTng Kernel Trace
+ if (label.equals(LTTNG_KERNEL_TRACE)) {
+ label = LINUX_KERNEL_TRACE;
+ }
+
+ String traceTypeId = TmfTraceType.getTraceTypeId(label);
+ TraceTypeHelper helper = TmfTraceType.getTraceType(traceTypeId);
+ if (helper == null) {
+ // Backward compatibility with category-less custom trace types
+ for (TraceTypeHelper h : TmfTraceType.getTraceTypeHelpers()) {
+ if (h.getName().equals(label)) {
+ label = h.getLabel();
+ helper = h;
+ break;
+ }
+ }
+ }
+ if (helper != null) {
+ ((TmfFilterTraceTypeNode) node).setTraceTypeId(helper.getTraceTypeId());
+ ((TmfFilterTraceTypeNode) node).setTraceClass(helper.getTraceClass());
+ }
+ ((TmfFilterTraceTypeNode) node).setName(label);
+ }
+
}
fFilterTreeStack.push(node);
/*******************************************************************************
- * Copyright (c) 2010, 2014 Ericsson
+ * Copyright (c) 2010, 2015 Ericsson
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v1.0 which
*
* Contributors:
* Yuriy Vashchuk (yvashchuk@gmail.com) - Initial API and implementation
+ * Patrick Tasse - Update filter nodes
*******************************************************************************/
package org.eclipse.tracecompass.tmf.core.filter.xml;
import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterCompareNode;
import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterContainsNode;
import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterEqualsNode;
-import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterEventTypeNode;
import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterMatchesFieldNode;
import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterMatchesNode;
import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterNode;
import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterOrNode;
+import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterTraceTypeNode;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
TmfFilterNode node = (TmfFilterNode) treenode;
element.setAttribute(TmfFilterNode.NAME_ATTR, node.getFilterName());
- } else if (treenode instanceof TmfFilterEventTypeNode) {
+ } else if (treenode instanceof TmfFilterTraceTypeNode) {
- TmfFilterEventTypeNode node = (TmfFilterEventTypeNode) treenode;
- element.setAttribute(TmfFilterEventTypeNode.TYPE_ATTR, node.getEventType());
- element.setAttribute(TmfFilterEventTypeNode.NAME_ATTR, node.getName());
+ TmfFilterTraceTypeNode node = (TmfFilterTraceTypeNode) treenode;
+ element.setAttribute(TmfFilterTraceTypeNode.TYPE_ATTR, node.getTraceTypeId());
+ element.setAttribute(TmfFilterTraceTypeNode.NAME_ATTR, node.getName());
} else if (treenode instanceof TmfFilterAndNode) {
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2015 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Patrick Tasse - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.core.parsers.custom;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
+import org.eclipse.tracecompass.tmf.core.trace.TmfTrace;
+
+/**
+ * Base class for custom traces.
+ *
+ * @author Patrick Tasse
+ */
+public abstract class CustomTrace extends TmfTrace {
+
+ private static final char SEPARATOR = ':';
+
+ private final String fTraceTypeId;
+
+ /**
+ * Basic constructor.
+ *
+ * @param definition
+ * Custom trace definition
+ */
+ public CustomTrace(CustomTraceDefinition definition) {
+ fTraceTypeId = buildTraceTypeId(getClass(), definition.categoryName, definition.definitionName);
+ }
+
+ /**
+ * Build the trace type id for a custom trace
+ *
+ * @param traceClass
+ * the trace class
+ * @param category
+ * the category
+ * @param definitionName
+ * the definition name
+ * @return the trace type id
+ */
+ public static @NonNull String buildTraceTypeId(Class<? extends ITmfTrace> traceClass, String category, String definitionName) {
+ return traceClass.getCanonicalName() + SEPARATOR + category + SEPARATOR + definitionName;
+ }
+
+ @Override
+ public String getTraceTypeId() {
+ return fTraceTypeId;
+ }
+}
import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
import org.eclipse.tracecompass.tmf.core.trace.ITmfContext;
import org.eclipse.tracecompass.tmf.core.trace.TmfContext;
-import org.eclipse.tracecompass.tmf.core.trace.TmfTrace;
import org.eclipse.tracecompass.tmf.core.trace.TraceValidationStatus;
import org.eclipse.tracecompass.tmf.core.trace.indexer.ITmfPersistentlyIndexable;
import org.eclipse.tracecompass.tmf.core.trace.indexer.ITmfTraceIndexer;
* @author Patrick Tassé
* @since 3.0
*/
-public class CustomTxtTrace extends TmfTrace implements ITmfPersistentlyIndexable {
+public class CustomTxtTrace extends CustomTrace implements ITmfPersistentlyIndexable {
private static final TmfLongLocation NULL_LOCATION = new TmfLongLocation(-1L);
private static final int DEFAULT_CACHE_SIZE = 100;
* Text trace definition
*/
public CustomTxtTrace(final CustomTxtTraceDefinition definition) {
+ super(definition);
fDefinition = definition;
fEventType = new CustomTxtEventType(fDefinition);
setCacheSize(DEFAULT_CACHE_SIZE);
import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
import org.eclipse.tracecompass.tmf.core.trace.ITmfContext;
import org.eclipse.tracecompass.tmf.core.trace.TmfContext;
-import org.eclipse.tracecompass.tmf.core.trace.TmfTrace;
import org.eclipse.tracecompass.tmf.core.trace.TraceValidationStatus;
import org.eclipse.tracecompass.tmf.core.trace.indexer.ITmfPersistentlyIndexable;
import org.eclipse.tracecompass.tmf.core.trace.indexer.ITmfTraceIndexer;
* @author Patrick Tassé
* @since 3.0
*/
-public class CustomXmlTrace extends TmfTrace implements ITmfPersistentlyIndexable {
+public class CustomXmlTrace extends CustomTrace implements ITmfPersistentlyIndexable {
private static final TmfLongLocation NULL_LOCATION = new TmfLongLocation(-1L);
private static final int DEFAULT_CACHE_SIZE = 100;
* Trace definition
*/
public CustomXmlTrace(final CustomXmlTraceDefinition definition) {
+ super(definition);
fDefinition = definition;
fEventType = new CustomXmlEventType(fDefinition);
fRecordInputElement = getRecordInputElement(fDefinition.rootInputElement);
/*******************************************************************************
- * Copyright (c) 2011, 2014 Ericsson, École Polytechnique de Montréal
+ * Copyright (c) 2011, 2015 Ericsson, É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 v1.0 which
import org.eclipse.core.runtime.Platform;
import org.eclipse.tracecompass.internal.tmf.core.Activator;
import org.eclipse.tracecompass.tmf.core.TmfCommonConstants;
+import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTrace;
import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtTrace;
import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtTraceDefinition;
import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlTrace;
// Constants
// ------------------------------------------------------------------
- private static final char SEPARATOR = ':';
-
/** Extension point ID */
public static final String TMF_TRACE_TYPE_ID = "org.eclipse.linuxtools.tmf.core.tracetype"; //$NON-NLS-1$
return typeElements.toArray(new IConfigurationElement[typeElements.size()]);
}
- /**
- * Retrieve the TraceTypeHelper for a given trace type ID
- *
- * @param id
- * The trace type ID
- * @return The corresponding TraceTypeHelper, or null if there is none for
- * the specified ID
- * @deprecated Use {@link #getTraceType(String)}
- */
- @Deprecated
- public static TraceTypeHelper getTraceTypeHelper(String id) {
- return TRACE_TYPES.get(id);
- }
-
/**
* Get an iterable view of the existing trace type IDs.
*
}
/**
- * Returns a list of "category:tracetype , ..."
+ * Returns a list of trace type labels "category : name", ...
*
* Returns only trace types, not experiment types
*
- * @return returns a list of "category:tracetype , ..."
+ * @return a list of trace type labels
*/
public static String[] getAvailableTraceTypes() {
return getAvailableTraceTypes(null);
}
/**
- * Returns a list of "category:tracetype , ..." sorted by given comparator.
+ * Returns a list of trace type labels "category : name", ... sorted by given comparator.
*
* Returns only trace types, not experiment types
*
* @param comparator
* Comparator class (type String) or null for alphabetical order.
- * @return sorted list according to the given comparator
+ * @return a list of trace type labels sorted according to the given comparator
*/
public static String[] getAvailableTraceTypes(Comparator<String> comparator) {
for (String key : TRACE_TYPES.keySet()) {
TraceTypeHelper tt = TRACE_TYPES.get(key);
if (!tt.isExperimentType()) {
- traceTypes.add(tt.getCategoryName() + SEPARATOR + tt.getName());
+ traceTypes.add(tt.getLabel());
}
}
private static void populateCustomTraceTypes() {
// add the custom trace types
for (CustomTxtTraceDefinition def : CustomTxtTraceDefinition.loadAll()) {
- String traceTypeId = CustomTxtTrace.class.getCanonicalName() + SEPARATOR + def.categoryName + SEPARATOR + def.definitionName;
- ITmfTrace trace = new CustomTxtTrace(def);
+ CustomTxtTrace trace = new CustomTxtTrace(def);
+ String traceTypeId = trace.getTraceTypeId();
TraceTypeHelper tt = new TraceTypeHelper(traceTypeId, def.categoryName, def.definitionName, trace, false, TraceElementType.TRACE);
TRACE_TYPES.put(traceTypeId, tt);
// Deregister trace as signal handler because it is only used for validation
TmfSignalManager.deregister(trace);
}
for (CustomXmlTraceDefinition def : CustomXmlTraceDefinition.loadAll()) {
- String traceTypeId = CustomXmlTrace.class.getCanonicalName() + SEPARATOR + def.categoryName + SEPARATOR + def.definitionName;
- ITmfTrace trace = new CustomXmlTrace(def);
+ CustomXmlTrace trace = new CustomXmlTrace(def);
+ String traceTypeId = trace.getTraceTypeId();
TraceTypeHelper tt = new TraceTypeHelper(traceTypeId, def.categoryName, def.definitionName, trace, false, TraceElementType.TRACE);
TRACE_TYPES.put(traceTypeId, tt);
// Deregister trace as signal handler because it is only used for validation
*/
public static void addCustomTraceType(Class<? extends ITmfTrace> traceClass, String category, String definitionName) {
String traceTypeId = null;
- ITmfTrace trace = null;
+ CustomTrace trace = null;
if (traceClass.equals(CustomTxtTrace.class)) {
- traceTypeId = CustomTxtTrace.class.getCanonicalName() + SEPARATOR + category + SEPARATOR + definitionName;
CustomTxtTraceDefinition def = CustomTxtTraceDefinition.load(category, definitionName);
if (def != null) {
trace = new CustomTxtTrace(def);
+ traceTypeId = trace.getTraceTypeId();
}
} else if (traceClass.equals(CustomXmlTrace.class)) {
- traceTypeId = CustomXmlTrace.class.getCanonicalName() + SEPARATOR + category + SEPARATOR + definitionName;
CustomXmlTraceDefinition def = CustomXmlTraceDefinition.load(category, definitionName);
if (def != null) {
trace = new CustomXmlTrace(def);
+ traceTypeId = trace.getTraceTypeId();
}
}
* The custom parser definition name to add or replace
*/
public static void removeCustomTraceType(Class<? extends ITmfTrace> traceClass, String category, String definitionName) {
- String traceTypeId = traceClass.getCanonicalName() + SEPARATOR + category + SEPARATOR + definitionName;
+ String traceTypeId = CustomTrace.buildTraceTypeId(traceClass, category, definitionName);
TraceTypeHelper helper = TRACE_TYPES.remove(traceTypeId);
if (helper != null) {
helper.getTrace().dispose();
return category.getAttribute(TmfTraceType.NAME_ATTR);
}
}
- return "[no category]"; //$NON-NLS-1$
+ return ""; //$NON-NLS-1$
}
/**
}
/**
- * Find the id of a trace type by its parameters
+ * Find the id of a trace type by its label "category : name"
*
- * @param category
- * like "ctf" or "custom text"
- * @param traceType
- * like "kernel"
- * @return an id like "org.eclipse.linuxtools.blabla...
+ * @param label
+ * the trace type label
+ * @return the trace type id
*/
- public static String getTraceTypeId(String category, String traceType) {
+ public static String getTraceTypeId(String label) {
for (String key : TRACE_TYPES.keySet()) {
- if (TRACE_TYPES.get(key).getCategoryName().equals(category.trim()) && TRACE_TYPES.get(key).getName().equals(traceType.trim())) {
+ if (TRACE_TYPES.get(key).getLabel().equals(label)) {
return key;
}
}
return null;
}
- /**
- * Gets the custom trace type ID from the custom trace name
- *
- * @param traceType
- * The trace type in human form (category:name)
- * @return the trace type ID or null if the trace is not a custom one
- * @deprecated Use {@link #getTraceTypeId(String, String)}
- */
- @Deprecated
- public static String getCustomTraceTypeId(String traceType) {
- String traceTypeToken[] = traceType.split(":", 2); //$NON-NLS-1$
- if (traceTypeToken.length == 2) {
- return getTraceTypeId(traceTypeToken[0], traceTypeToken[1]);
- }
- return null;
- }
-
- /**
- * Is the trace a custom (user-defined) trace type. These are the traces
- * like : text and xml defined by the custom trace wizard.
- *
- * @param traceType
- * the trace type in human form (category:name)
- * @return true if the trace is a custom type
- * @deprecated Use {@link #getTraceTypeId(String, String)} and check prefix
- */
- @Deprecated
- public static boolean isCustomTrace(String traceType) {
- String traceTypeId = getCustomTraceTypeId(traceType);
- if (traceTypeId != null) {
- return traceTypeId.startsWith(CustomTxtTrace.class.getCanonicalName() + SEPARATOR) ||
- traceTypeId.startsWith(CustomXmlTrace.class.getCanonicalName() + SEPARATOR);
- }
- return false;
- }
-
/**
* Checks if a trace is a valid directory trace
* @param path
*/
public class TraceTypeHelper {
+ private static final String SEP = " : "; //$NON-NLS-1$
+
private final String fName;
private final String fCategoryName;
private final String fTraceTypeId;
return fCategoryName;
}
+ /**
+ * Get the trace type label "category : name".
+ *
+ * @return the trace type label
+ */
+ public String getLabel() {
+ if (fCategoryName.isEmpty()) {
+ return fName;
+ }
+ return fCategoryName + SEP + fName;
+ }
+
/**
* Get the trace type id
*
* the trace event type
* @param name
* the trace name
+ * @param traceTypeId
+ * the trace type id
* @throws TmfTraceException
* If we couldn't open the trace
*/
- void initTrace(IResource resource, String path, Class<? extends ITmfEvent> type, String name) throws TmfTraceException;
+ void initTrace(IResource resource, String path, Class<? extends ITmfEvent> type, String name, String traceTypeId) throws TmfTraceException;
/**
* Validate that the trace is of the correct type. The implementation should
*/
IResource getResource();
+ /**
+ * Get the trace type id
+ *
+ * @return the trace type id
+ */
+ @Nullable String getTraceTypeId();
+
/**
* @return the trace path
*/
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.tracecompass.internal.tmf.core.Activator;
import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule;
import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModuleHelper;
// The resource used for persistent properties for this trace
private IResource fResource;
+ // The trace type id
+ private @Nullable String fTraceTypeId;
+
// The trace path
private String fPath;
// ------------------------------------------------------------------------
@Override
- public void initTrace(final IResource resource, final String path, final Class<? extends ITmfEvent> type, String name) throws TmfTraceException {
+ public void initTrace(final IResource resource, final String path, final Class<? extends ITmfEvent> type, String name, String traceTypeId) throws TmfTraceException {
if (name == null) {
throw new IllegalArgumentException();
}
setName(name);
+ fTraceTypeId = traceTypeId;
initTrace(resource, path, type);
}
return fResource;
}
+ @Override
+ public @Nullable String getTraceTypeId() {
+ return fTraceTypeId;
+ }
+
@Override
public String getPath() {
return fPath;
/*******************************************************************************
- * Copyright (c) 2009, 2014 Ericsson and others.
+ * Copyright (c) 2009, 2015 Ericsson and others.
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v1.0 which
private static final String IMPORT_WIZARD_IMPORT_UNRECOGNIZED_ID = ".import_unrecognized_traces_id"; //$NON-NLS-1$
private static final String IMPORT_WIZARD_PRESERVE_FOLDERS_ID = ".import_preserve_folders_id"; //$NON-NLS-1$
private static final String IMPORT_WIZARD_IMPORT_FROM_DIRECTORY_ID = ".import_from_directory"; //$NON-NLS-1$
- private static final String SEPARATOR = ":"; //$NON-NLS-1$
// constant from WizardArchiveFileResourceImportPage1
private static final String[] FILE_IMPORT_MASK = { "*.jar;*.zip;*.tar;*.tar.gz;*.tgz", "*.*" }; //$NON-NLS-1$ //$NON-NLS-2$
* @return <code>true</code> if successful else <code>false</code>
*/
public boolean finish() {
- String traceTypeName = getImportTraceTypeId();
+ String traceTypeLabel = getImportTraceTypeId();
String traceId = null;
- if (!TRACE_TYPE_AUTO_DETECT.equals(traceTypeName)) {
- String tokens[] = traceTypeName.split(SEPARATOR, 2);
- if (tokens.length < 2) {
- return false;
- }
- traceId = TmfTraceType.getTraceTypeId(tokens[0], tokens[1]);
+ if (!TRACE_TYPE_AUTO_DETECT.equals(traceTypeLabel)) {
+ traceId = TmfTraceType.getTraceTypeId(traceTypeLabel);
}
// Save dialog settings
}
try {
- trace.initTrace(traceElement.getResource(), traceElement.getResource().getLocation().toOSString(), traceEvent.getClass(), traceElement.getElementPath());
+ trace.initTrace(traceElement.getResource(), traceElement.getResource().getLocation().toOSString(), traceEvent.getClass(), traceElement.getElementPath(), traceElement.getTraceType());
} catch (final TmfTraceException e) {
TraceUtils.displayErrorMsg(NLS.bind(Messages.TmfOpenTraceHelper_OpenElement, traceElement.getTypeName()),
Messages.TmfOpenTraceHelper_InitError + ENDL + ENDL + e);
if (getTraceType() != null) {
TraceTypeHelper helper = TmfTraceType.getTraceType(getTraceType());
if (helper != null) {
- return helper.getCategoryName() + " : " + helper.getName(); //$NON-NLS-1$
+ return helper.getLabel();
}
}
return ""; //$NON-NLS-1$
/*******************************************************************************
- * Copyright (c) 2010, 2014 Ericsson
+ * Copyright (c) 2010, 2015 Ericsson
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v1.0 which
*
* Contributors:
* Yuriy Vashchuk - Initial API and implementation
+ * Patrick Tasse - Update filter nodes
*******************************************************************************/
package org.eclipse.tracecompass.tmf.ui.views.filter;
import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterCompareNode.Type;
import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterContainsNode;
import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterEqualsNode;
-import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterEventTypeNode;
import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterMatchesFieldNode;
import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterNode;
import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterOrNode;
+import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterTraceTypeNode;
/**
* This is the Label Provider for our Filter Tree
TmfFilterNode node = (TmfFilterNode) element;
label = node.getNodeName() + " " + node.getFilterName(); //$NON-NLS-1$
- } else if (element instanceof TmfFilterEventTypeNode) {
+ } else if (element instanceof TmfFilterTraceTypeNode) {
- TmfFilterEventTypeNode node = (TmfFilterEventTypeNode) element;
+ TmfFilterTraceTypeNode node = (TmfFilterTraceTypeNode) element;
label = "WITH " + node.getNodeName() + (node.getName() != null ? " " + node.getName() : ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
} else if (element instanceof TmfFilterAndNode) {
/*******************************************************************************
- * Copyright (c) 2010, 2014 Ericsson
+ * Copyright (c) 2010, 2015 Ericsson
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v1.0 which
import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterCompareNode.Type;
import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterContainsNode;
import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterEqualsNode;
-import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterEventTypeNode;
import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterMatchesFieldNode;
import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterNode;
import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterOrNode;
import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterRootNode;
+import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterTraceTypeNode;
import org.eclipse.tracecompass.tmf.core.filter.model.TmfFilterTreeNode;
import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition;
import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition.OutputColumn;
-import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtEvent;
import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtTraceDefinition;
-import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlEvent;
import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlTraceDefinition;
import org.eclipse.tracecompass.tmf.core.project.model.TmfTraceType;
+import org.eclipse.tracecompass.tmf.core.project.model.TraceTypeHelper;
class FilterViewer extends Composite {
ITmfFilterTreeNode newNode = null;
if (TmfFilterNode.NODE_NAME.equals(child)) {
newNode = new TmfFilterNode(node, ""); //$NON-NLS-1$
- } else if (TmfFilterEventTypeNode.NODE_NAME.equals(child)) {
- newNode = new TmfFilterEventTypeNode(node);
+ } else if (TmfFilterTraceTypeNode.NODE_NAME.equals(child)) {
+ newNode = new TmfFilterTraceTypeNode(node);
} else if (TmfFilterAndNode.NODE_NAME.equals(child)) {
newNode = new TmfFilterAndNode(node);
} else if (TmfFilterOrNode.NODE_NAME.equals(child)) {
if (node instanceof TmfFilterNode) {
new FilterNodeComposite(fComposite, (TmfFilterNode) node);
- } else if (node instanceof TmfFilterEventTypeNode) {
- new FilterEventTypeNodeComposite(fComposite, (TmfFilterEventTypeNode) node);
+ } else if (node instanceof TmfFilterTraceTypeNode) {
+ new FilterTraceTypeNodeComposite(fComposite, (TmfFilterTraceTypeNode) node);
} else if (node instanceof TmfFilterAndNode) {
new FilterAndNodeComposite(fComposite, (TmfFilterAndNode) node);
} else if (node instanceof TmfFilterOrNode) {
return eventsTypeMap;
}
- protected String[] getFieldsList(ITmfFilterTreeNode node) {
- ArrayList<String> fieldsList = new ArrayList<>();
- ITmfFilterTreeNode curNode = node;
- while (curNode != null) {
- if (curNode instanceof TmfFilterEventTypeNode) {
- TmfFilterEventTypeNode eventTypeNode = (TmfFilterEventTypeNode) curNode;
- for (IConfigurationElement ce : TmfTraceType.getTypeElements()) {
- if (ce.getAttribute(TmfTraceType.EVENT_TYPE_ATTR).equals(eventTypeNode.getEventType())) {
- try {
- ITmfEvent event = (ITmfEvent) ce.createExecutableExtension(TmfTraceType.EVENT_TYPE_ATTR);
- ITmfEventType eventType = event.getType();
- if (eventType != null) {
- for (String field : eventType.getRootField().getFieldNames()) {
- fieldsList.add(field);
- }
- }
- } catch (CoreException e) {
- }
- if (fieldsList.size() == 0) {
- fieldsList.add(ITmfEvent.EVENT_FIELD_TIMESTAMP);
- fieldsList.add(ITmfEvent.EVENT_FIELD_SOURCE);
- fieldsList.add(ITmfEvent.EVENT_FIELD_TYPE);
- fieldsList.add(ITmfEvent.EVENT_FIELD_REFERENCE);
- fieldsList.add(ITmfEvent.EVENT_FIELD_CONTENT);
- }
- return fieldsList.toArray(new String[0]);
- }
- }
- if (eventTypeNode.getEventType() != null && eventTypeNode.getEventType().startsWith(CustomTxtEvent.class.getCanonicalName())) {
- for (CustomTxtTraceDefinition def : CustomTxtTraceDefinition.loadAll()) {
- if (eventTypeNode.getEventType().equals(CustomTxtEvent.class.getCanonicalName() + ':' + def.categoryName + ':' + def.definitionName)) {
- for (OutputColumn output : def.outputs) {
- fieldsList.add(output.name);
- }
- return fieldsList.toArray(new String[0]);
- }
- }
- }
- if (eventTypeNode.getEventType() != null && eventTypeNode.getEventType().startsWith(CustomXmlEvent.class.getCanonicalName())) {
- for (CustomXmlTraceDefinition def : CustomXmlTraceDefinition.loadAll()) {
- if (eventTypeNode.getEventType().equals(CustomXmlEvent.class.getCanonicalName() + ':' + def.categoryName + ':' + def.definitionName)) {
- for (OutputColumn output : def.outputs) {
- fieldsList.add(output.name);
- }
- return fieldsList.toArray(new String[0]);
- }
- }
- }
- }
- curNode = curNode.getParent();
+ protected Map<String, TraceTypeHelper> getTraceTypeMap() {
+ Map<String, TraceTypeHelper> traceTypeMap = new TreeMap<>();
+ for (TraceTypeHelper helper : TmfTraceType.getTraceTypeHelpers()) {
+ String text = helper.getCategoryName() + SEP + helper.getName();
+ traceTypeMap.put(text, helper);
}
+ return traceTypeMap;
+ }
+ protected String[] getFieldsList() {
+ ArrayList<String> fieldsList = new ArrayList<>();
fieldsList.add(Messages.FilterViewer_CommonCategory);
fieldsList.add(ITmfEvent.EVENT_FIELD_TIMESTAMP);
fieldsList.add(ITmfEvent.EVENT_FIELD_SOURCE);
}
}
- private class FilterEventTypeNodeComposite extends FilterBaseNodeComposite {
- TmfFilterEventTypeNode fNode;
+ private class FilterTraceTypeNodeComposite extends FilterBaseNodeComposite {
+ TmfFilterTraceTypeNode fNode;
Combo fTypeCombo;
- Map<String, Object> fEventsTypeMap;
+ Map<String, TraceTypeHelper> fTraceTypeMap;
- FilterEventTypeNodeComposite(Composite parent, TmfFilterEventTypeNode node) {
+ FilterTraceTypeNodeComposite(Composite parent, TmfFilterTraceTypeNode node) {
super(parent);
fNode = node;
- fEventsTypeMap = getEventsTypeMap();
+ fTraceTypeMap = getTraceTypeMap();
Label label = new Label(this, SWT.NONE);
label.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
fTypeCombo = new Combo(this, SWT.DROP_DOWN | SWT.READ_ONLY);
fTypeCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
- fTypeCombo.setItems(fEventsTypeMap.keySet().toArray(new String[0]));
- if (fNode.getEventType() != null) {
+ fTypeCombo.setItems(fTraceTypeMap.keySet().toArray(new String[0]));
+ if (fNode.getTraceTypeId() != null) {
fTypeCombo.setText(fNode.getName());
}
fTypeCombo.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
- for (Entry<String, Object> eventTypeEntry : fEventsTypeMap.entrySet()) {
- if (eventTypeEntry.getKey().equals(fTypeCombo.getText())) {
- Object value = eventTypeEntry.getValue();
- if (value instanceof IConfigurationElement) {
- IConfigurationElement ce = (IConfigurationElement) value;
- fNode.setEventType(ce.getAttribute(TmfTraceType.EVENT_TYPE_ATTR));
- String categoryId = ce.getAttribute(TmfTraceType.CATEGORY_ATTR);
- if (categoryId != null) {
- fNode.setName(TmfTraceType.getCategoryName(categoryId) + SEP
- + ce.getAttribute(TmfTraceType.NAME_ATTR));
- } else {
- fNode.setName(ce.getAttribute(TmfTraceType.NAME_ATTR));
- }
- } else if (value instanceof CustomTxtTraceDefinition) {
- CustomTxtTraceDefinition def = (CustomTxtTraceDefinition) value;
- fNode.setEventType(CustomTxtEvent.class.getCanonicalName() + ':' + def.categoryName + ':' + def.definitionName);
- fNode.setName(def.categoryName + SEP + def.definitionName);
- } else if (value instanceof CustomXmlTraceDefinition) {
- CustomXmlTraceDefinition def = (CustomXmlTraceDefinition) value;
- fNode.setEventType(CustomXmlEvent.class.getCanonicalName() + ':' + def.categoryName + ':' + def.definitionName);
- fNode.setName(def.categoryName + SEP + def.definitionName);
- }
- fViewer.refresh(fNode);
- break;
- }
- }
+ TraceTypeHelper helper = fTraceTypeMap.get(fTypeCombo.getText());
+ fNode.setTraceTypeId(helper.getTraceTypeId());
+ fNode.setTraceClass(helper.getTraceClass());
+ fNode.setName(fTypeCombo.getText());
+ fViewer.refresh(fNode);
}
});
}
fFieldCombo = new Combo(this, SWT.DROP_DOWN);
fFieldCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
- fFieldCombo.setItems(getFieldsList(fNode));
+ fFieldCombo.setItems(getFieldsList());
fFieldCombo.setToolTipText(Messages.FilterViewer_Subfilter_ToolTip);
if (fNode.getField() != null) {
fFieldCombo.setText(fNode.getField());
fFieldCombo = new Combo(this, SWT.DROP_DOWN);
fFieldCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
- fFieldCombo.setItems(getFieldsList(fNode));
+ fFieldCombo.setItems(getFieldsList());
fFieldCombo.setToolTipText(Messages.FilterViewer_Subfilter_ToolTip);
if (fNode.getField() != null) {
fFieldCombo.setText(fNode.getField());
fFieldCombo = new Combo(this, SWT.DROP_DOWN);
fFieldCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
- fFieldCombo.setItems(getFieldsList(fNode));
+ fFieldCombo.setItems(getFieldsList());
fFieldCombo.setToolTipText(Messages.FilterViewer_Subfilter_ToolTip);
if (fNode.getField() != null) {
fFieldCombo.setText(fNode.getField());
fFieldCombo = new Combo(this, SWT.DROP_DOWN);
fFieldCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
- fFieldCombo.setItems(getFieldsList(fNode));
+ fFieldCombo.setItems(getFieldsList());
fFieldCombo.setToolTipText(Messages.FilterViewer_Subfilter_ToolTip);
if (fNode.getField() != null) {
fFieldCombo.setText(fNode.getField());