X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=org.eclipse.linuxtools.tmf.core%2Fsrc%2Forg%2Feclipse%2Flinuxtools%2Ftmf%2Fcore%2Fctfadaptor%2FCtfTmfEvent.java;h=8cab950ec05c60a4eb65b5453e6dd9cdad63f538;hb=e693075df9ab61d18493abaf9db9726efc254c17;hp=d2a3db3a06f9291865d1c6ea05ae0029117cbc25;hpb=d921f72d242cb533e31a80e712d2f87ec7e5c5a3;p=deliverable%2Ftracecompass.git diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfEvent.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfEvent.java index d2a3db3a06..8cab950ec0 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfEvent.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfEvent.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011 Ericsson + * Copyright (c) 2011, 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 @@ -8,235 +8,112 @@ * * Contributors: * Alexandre Montplaisir - Initial API and implementation + * Bernd Hufmann - Updated for source and model lookup interfaces *******************************************************************************/ package org.eclipse.linuxtools.tmf.core.ctfadaptor; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map.Entry; +import java.util.HashSet; +import java.util.Set; -import org.eclipse.core.runtime.IAdaptable; import org.eclipse.linuxtools.ctf.core.event.CTFCallsite; -import org.eclipse.linuxtools.ctf.core.event.EventDefinition; -import org.eclipse.linuxtools.ctf.core.event.types.Definition; -import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition; -import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition; -import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; +import org.eclipse.linuxtools.ctf.core.event.IEventDeclaration; +import org.eclipse.linuxtools.ctf.core.trace.CTFTrace; +import org.eclipse.linuxtools.tmf.core.event.ITmfCustomAttributes; import org.eclipse.linuxtools.tmf.core.event.ITmfEventField; import org.eclipse.linuxtools.tmf.core.event.ITmfEventType; -import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp; +import org.eclipse.linuxtools.tmf.core.event.TmfEvent; import org.eclipse.linuxtools.tmf.core.event.TmfEventField; -import org.eclipse.linuxtools.tmf.core.event.TmfEventPropertySource; -import org.eclipse.ui.views.properties.IPropertySource; +import org.eclipse.linuxtools.tmf.core.event.lookup.ITmfModelLookup; +import org.eclipse.linuxtools.tmf.core.event.lookup.ITmfSourceLookup; +import org.eclipse.linuxtools.tmf.core.trace.ITmfContext; /** - * A wrapper class around CTF's Event Definition/Declaration that maps all - * types of Declaration to native Java types. + * A wrapper class around CTF's Event Definition/Declaration that maps all types + * of Declaration to native Java types. * * @version 1.0 * @author Alexandre Montplaisir * @since 2.0 */ -public final class CtfTmfEvent implements ITmfEvent, IAdaptable, Cloneable { +public class CtfTmfEvent extends TmfEvent + implements ITmfSourceLookup, ITmfModelLookup, ITmfCustomAttributes { // ------------------------------------------------------------------------ // Constants // ------------------------------------------------------------------------ - private static final String NO_STREAM = "No stream"; //$NON-NLS-1$ + static final String NO_STREAM = "No stream"; //$NON-NLS-1$ private static final String EMPTY_CTF_EVENT_NAME = "Empty CTF event"; //$NON-NLS-1$ - /** Prefix for Context information stored as CtfTmfEventfield */ - private static final String CONTEXT_FIELD_PREFIX = "context."; //$NON-NLS-1$ - // ------------------------------------------------------------------------ // Attributes // ------------------------------------------------------------------------ - private final CtfTmfTrace fTrace; - private final ITmfTimestamp fTimestamp; - private final int sourceCPU; - private final long typeId; - private final String eventName; - private final String fileName; - - private final TmfEventField fContent; + private final int fSourceCPU; + private final long fTypeId; + private final String fEventName; + private final IEventDeclaration fDeclaration; // ------------------------------------------------------------------------ // Constructors // ------------------------------------------------------------------------ /** - * Usual CTFEvent constructor, where we read an event from the trace (via - * the StreamInputReader). - * - * @param eventDef - * CTF EventDefinition object corresponding to this trace event - * @param fileName - * The path to the trace file - * @param originTrace - * The trace from which this event originates - */ - public CtfTmfEvent(EventDefinition eventDef, String fileName, - CtfTmfTrace originTrace) { - this.fTrace = originTrace; - - if (eventDef == null) { - this.fTimestamp = new CtfTmfTimestamp(-1); - this.sourceCPU = -1; - this.typeId = -1; - this.fileName = NO_STREAM; - this.eventName = EMPTY_CTF_EVENT_NAME; - this.fContent = null; - return; - } - - /* Read the base event info */ - long ts = this.getTrace().getCTFTrace().timestampCyclesToNanos(eventDef.getTimestamp()); - this.fTimestamp = new CtfTmfTimestamp(ts); - this.sourceCPU = eventDef.getCPU(); - this.typeId = eventDef.getDeclaration().getId(); - this.eventName = eventDef.getDeclaration().getName(); - this.fileName = fileName; - - /* Read the fields */ - this.fContent = new TmfEventField(ITmfEventField.ROOT_FIELD_ID, parseFields(eventDef)); - } - - /** - * Extract the field information from the structDefinition haze-inducing - * mess, and put them into something ITmfEventField can cope with. + * Constructor used by {@link CtfTmfEventFactory#createEvent} */ - private CtfTmfEventField[] parseFields(EventDefinition eventDef) { - List fields = new ArrayList(); - - StructDefinition structFields = eventDef.getFields(); - HashMap definitions = structFields.getDefinitions(); - String curFieldName = null; - Definition curFieldDef; - CtfTmfEventField curField; - Iterator> it = definitions.entrySet().iterator(); - while(it.hasNext()) { - Entry entry = it.next(); - curFieldName = entry.getKey(); - curFieldDef = entry.getValue(); - curField = CtfTmfEventField.parseField(curFieldDef, curFieldName); - fields.add(curField); - } + CtfTmfEvent(CtfTmfTrace trace, long rank, CtfTmfTimestamp timestamp, + ITmfEventField content, String fileName, int cpu, + IEventDeclaration declaration) { + super(trace, + rank, + timestamp, + String.valueOf(cpu), // Source + null, // Event type. We don't use TmfEvent's field here, we re-implement getType() + content, + fileName // Reference + ); - /* Add context information as CtfTmfEventField */ - long ip = -1; - StructDefinition structContext = eventDef.getContext(); - if (structContext != null) { - definitions = structContext.getDefinitions(); - String curContextName; - Definition curContextDef; - CtfTmfEventField curContext; - it = definitions.entrySet().iterator(); - while(it.hasNext()) { - Entry entry = it.next(); - /* This is to get the instruction pointer if available */ - if (entry.getKey().equals("_ip") && //$NON-NLS-1$ - (entry.getValue() instanceof IntegerDefinition)) { - ip = ((IntegerDefinition) entry.getValue()).getValue(); - } - /* Prefix field name to */ - curContextName = CONTEXT_FIELD_PREFIX + entry.getKey(); - curContextDef = entry.getValue(); - curContext = CtfTmfEventField.parseField(curContextDef, curContextName); - fields.add(curContext); - } - } - /* Add callsite */ - final String name = eventDef.getDeclaration().getName(); - List eventList = fTrace.getCTFTrace().getCallsiteCandidates(name); - if (!eventList.isEmpty()) { - final String callsite = "callsite"; //$NON-NLS-1$ - if (eventList.size() == 1 || ip == -1) { - CTFCallsite cs = eventList.get(0); - fields.add(new CTFStringField(cs.toString(), callsite)); - } else { - fields.add(new CTFStringField( - fTrace.getCTFTrace().getCallsite(name, ip).toString(), - callsite)); - } - } + fDeclaration = declaration; + fSourceCPU = cpu; + fTypeId = declaration.getId(); + fEventName = declaration.getName(); - return fields.toArray(new CtfTmfEventField[fields.size()]); - } - - /** - * Copy constructor - * - * @param other - * CtfTmfEvent to copy - */ - public CtfTmfEvent(CtfTmfEvent other) { - /* There is only one reference to the trace, so we can shallow-copy it */ - this.fTrace = other.getTrace(); - - /* - * Copy the timestamp - * FIXME This can be switched to a shallow-copy once timestamps are - * made immutable. - */ - this.fTimestamp = new CtfTmfTimestamp(other.fTimestamp.getValue()); - - /* Primitives, those will be copied by value */ - this.sourceCPU = other.sourceCPU; - this.typeId = other.typeId; - - /* Strings are immutable, it's safe to shallow-copy them */ - this.eventName = other.eventName; - this.fileName = other.fileName; - - /* Copy the fields over */ - this.fContent = other.fContent.clone(); } /** * Inner constructor to create "null" events. Don't use this directly in - * normal usage, use CtfTmfEvent.getNullEvent() to get an instance of an - * empty event. + * normal usage, use {@link CtfTmfEventFactory#getNullEvent()} to get an + * instance of an empty event. * * This needs to be public however because it's used in extension points, * and the framework will use this constructor to get the class type. */ public CtfTmfEvent() { - this.fTrace = null; - this.fTimestamp = new CtfTmfTimestamp(-1); - this.sourceCPU = -1; - this.typeId = -1; - this.fileName = NO_STREAM; - this.eventName = EMPTY_CTF_EVENT_NAME; - this.fContent = new TmfEventField("", new CtfTmfEventField[0]); //$NON-NLS-1$ + super(null, + ITmfContext.UNKNOWN_RANK, + new CtfTmfTimestamp(-1), + null, + null, + new TmfEventField("", null, new CtfTmfEventField[0]), //$NON-NLS-1$ + NO_STREAM); + fSourceCPU = -1; + fTypeId = -1; + fEventName = EMPTY_CTF_EVENT_NAME; + fDeclaration = null; } // ------------------------------------------------------------------------ // Getters/Setters/Predicates // ------------------------------------------------------------------------ - private static CtfTmfEvent nullEvent = new CtfTmfEvent(); - - /** - * Get a null event - * - * @return An empty event. - */ - public static CtfTmfEvent getNullEvent() { - return nullEvent; - } - /** * Gets the cpu core the event was recorded on. * * @return The cpu id for a given source. In lttng it's from CPUINFO */ public int getCPU() { - return this.sourceCPU; + return fSourceCPU; } /** @@ -248,84 +125,90 @@ public final class CtfTmfEvent implements ITmfEvent, IAdaptable, Cloneable { * @return The event ID */ public long getID() { - return this.typeId; - } - - /** - * Gets the name of a current event. - * - * @return The event name - */ - public String getEventName() { - return eventName; - } - - /** - * Gets the channel name of a field. - * - * @return The channel name. - */ - public String getChannelName() { - return this.fileName; + return fTypeId; } @Override public CtfTmfTrace getTrace() { - return fTrace; - } - - @Override - public long getRank() { - // TODO Auto-generated method stub - return 0; - } - - @Override - public ITmfTimestamp getTimestamp() { - return fTimestamp; - } - - @Override - public String getSource() { - // TODO Returns CPU for now - return Integer.toString(getCPU()); + /* + * Should be of the right type, since we take a CtfTmfTrace at the + * constructor + */ + return (CtfTmfTrace) super.getTrace(); } @Override public ITmfEventType getType() { - CtfTmfEventType ctfTmfEventType = CtfTmfEventType.get(eventName); - if( ctfTmfEventType == null ){ - ctfTmfEventType = new CtfTmfEventType( this.getEventName(), this.getContent()); + CtfTmfEventType ctfTmfEventType = CtfTmfEventType.get(getTrace(), fEventName); + if (ctfTmfEventType == null) { + /* Should only return null the first time */ + ctfTmfEventType = new CtfTmfEventType(fEventName, getTrace(), getContent()); } return ctfTmfEventType; } + /** + * @since 2.0 + */ @Override - public ITmfEventField getContent() { - return fContent; + public Set listCustomAttributes() { + if (fDeclaration == null) { + return new HashSet<>(); + } + return fDeclaration.getCustomAttributes(); } + /** + * @since 2.0 + */ @Override - public String getReference() { - return getChannelName(); + public String getCustomAttribute(String name) { + if (fDeclaration == null) { + return null; + } + return fDeclaration.getCustomAttribute(name); } + /** + * Get the call site for this event. + * + * @return the call site information, or null if there is none + * @since 2.0 + */ @Override - public CtfTmfEvent clone() { - return new CtfTmfEvent(this); + public CtfTmfCallsite getCallsite() { + CTFCallsite callsite = null; + CtfTmfTrace trace = getTrace(); + if (trace == null) { + return null; + } + CTFTrace ctfTrace = trace.getCTFTrace(); + /* Should not happen, but it is a good check */ + if (ctfTrace == null) { + return null; + } + if (getContent() != null) { + ITmfEventField ipField = getContent().getField(CtfConstants.CONTEXT_FIELD_PREFIX + CtfConstants.IP_KEY); + if (ipField != null && ipField.getValue() instanceof Long) { + long ip = (Long) ipField.getValue(); + callsite = ctfTrace.getCallsite(fEventName, ip); + } + } + if (callsite == null) { + callsite = ctfTrace.getCallsite(fEventName); + } + if (callsite != null) { + return new CtfTmfCallsite(callsite); + } + return null; } - /* (non-Javadoc) - * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class) - */ /** * @since 2.0 */ @Override - public Object getAdapter(Class adapter) { - if (adapter == IPropertySource.class) { - return new TmfEventPropertySource(this); - } - return null; + public String getModelUri() { + return getCustomAttribute(CtfConstants.MODEL_URI_KEY); } + }