ctf: Read and display custom event attributes
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / ctfadaptor / CtfTmfEvent.java
CommitLineData
a3fc8213 1/*******************************************************************************
8e964be1 2 * Copyright (c) 2011-2013 Ericsson
a3fc8213
AM
3 *
4 * All rights reserved. This program and the accompanying materials are made
5 * available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
58f3bc52
AM
9 * Contributors:
10 * Alexandre Montplaisir - Initial API and implementation
f47ed727 11 * Bernd Hufmann - Updated for source and model lookup interfaces
a3fc8213
AM
12 *******************************************************************************/
13
14package org.eclipse.linuxtools.tmf.core.ctfadaptor;
15
8e964be1 16import java.util.HashSet;
8e964be1 17import java.util.Set;
a3fc8213 18
60fb38b8 19import org.eclipse.linuxtools.ctf.core.event.CTFCallsite;
8e964be1 20import org.eclipse.linuxtools.ctf.core.event.IEventDeclaration;
860b76d4 21import org.eclipse.linuxtools.tmf.core.event.ITmfCustomAttributes;
a3fc8213
AM
22import org.eclipse.linuxtools.tmf.core.event.ITmfEventField;
23import org.eclipse.linuxtools.tmf.core.event.ITmfEventType;
6cfa0200 24import org.eclipse.linuxtools.tmf.core.event.TmfEvent;
306dc902 25import org.eclipse.linuxtools.tmf.core.event.TmfEventField;
93bfd50a 26import org.eclipse.linuxtools.tmf.core.event.TmfEventPropertySource;
f47ed727
BH
27import org.eclipse.linuxtools.tmf.core.event.lookup.ITmfModelLookup;
28import org.eclipse.linuxtools.tmf.core.event.lookup.ITmfSourceLookup;
6cfa0200 29import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
93bfd50a 30import org.eclipse.ui.views.properties.IPropertySource;
a3fc8213
AM
31
32/**
d09f973b
FC
33 * A wrapper class around CTF's Event Definition/Declaration that maps all
34 * types of Declaration to native Java types.
6256d8ad 35 *
d09f973b
FC
36 * @version 1.0
37 * @author Alexandre Montplaisir
93bfd50a 38 * @since 2.0
a3fc8213 39 */
860b76d4
SD
40public final class CtfTmfEvent extends TmfEvent
41 implements ITmfSourceLookup, ITmfModelLookup, ITmfCustomAttributes {
a3fc8213
AM
42
43 // ------------------------------------------------------------------------
44 // Constants
45 // ------------------------------------------------------------------------
46
6cfa0200 47 static final String NO_STREAM = "No stream"; //$NON-NLS-1$
a3fc8213 48 private static final String EMPTY_CTF_EVENT_NAME = "Empty CTF event"; //$NON-NLS-1$
aa572e22 49
a3fc8213
AM
50 // ------------------------------------------------------------------------
51 // Attributes
52 // ------------------------------------------------------------------------
53
a3fc8213
AM
54 private final int sourceCPU;
55 private final long typeId;
56 private final String eventName;
8e964be1 57 private final IEventDeclaration fDeclaration;
a3fc8213
AM
58
59 // ------------------------------------------------------------------------
60 // Constructors
61 // ------------------------------------------------------------------------
62
63 /**
6cfa0200 64 * Constructor used by {@link CtfTmfEventFactory#createEvent}
a3fc8213 65 */
6cfa0200
AM
66 CtfTmfEvent(CtfTmfTrace trace, long rank, CtfTmfTimestamp timestamp,
67 ITmfEventField content, String fileName, int cpu,
68 IEventDeclaration declaration) {
69 super(trace,
70 rank,
71 timestamp,
72 String.valueOf(cpu), // Source
73 null, // Event type. We don't use TmfEvent's field here, we re-implement getType()
74 content,
75 fileName // Reference
76 );
77
78 fDeclaration = declaration;
79 sourceCPU = cpu;
80 typeId = declaration.getId();
81 eventName = declaration.getName();
a3fc8213
AM
82 }
83
84 /**
b8a6e46d 85 * Inner constructor to create "null" events. Don't use this directly in
6cfa0200
AM
86 * normal usage, use {@link CtfTmfEventFactory#getNullEvent()} to get an
87 * instance of an empty event.
c26afeaf 88 *
b8a6e46d
AM
89 * This needs to be public however because it's used in extension points,
90 * and the framework will use this constructor to get the class type.
a3fc8213 91 */
ce2388e0 92 public CtfTmfEvent() {
6cfa0200
AM
93 super(null,
94 ITmfContext.UNKNOWN_RANK,
95 new CtfTmfTimestamp(-1),
96 null,
97 null,
214cc822 98 new TmfEventField("", null, new CtfTmfEventField[0]), //$NON-NLS-1$
6cfa0200 99 NO_STREAM);
a3fc8213
AM
100 this.sourceCPU = -1;
101 this.typeId = -1;
a3fc8213 102 this.eventName = EMPTY_CTF_EVENT_NAME;
8e964be1 103 this.fDeclaration = null;
a3fc8213
AM
104 }
105
106 // ------------------------------------------------------------------------
107 // Getters/Setters/Predicates
108 // ------------------------------------------------------------------------
109
a3fc8213
AM
110 /**
111 * Gets the cpu core the event was recorded on.
112 *
58f3bc52
AM
113 * @return The cpu id for a given source. In lttng it's from CPUINFO
114 */
a3fc8213
AM
115 public int getCPU() {
116 return this.sourceCPU;
117 }
118
119 /**
58f3bc52 120 * Return this event's ID, according to the trace's metadata.
a3fc8213 121 *
58f3bc52
AM
122 * Watch out, this ID is not constant from one trace to another for the same
123 * event types! Use "getEventName()" for a constant reference.
124 *
125 * @return The event ID
126 */
a3fc8213
AM
127 public long getID() {
128 return this.typeId;
129 }
130
131 /**
132 * Gets the name of a current event.
133 *
58f3bc52
AM
134 * @return The event name
135 */
a3fc8213
AM
136 public String getEventName() {
137 return eventName;
138 }
139
a3fc8213
AM
140 @Override
141 public CtfTmfTrace getTrace() {
6cfa0200
AM
142 /* Should be of the right type, since we take a CtfTmfTrace at the constructor */
143 return (CtfTmfTrace) super.getTrace();
a3fc8213
AM
144 }
145
146 @Override
147 public ITmfEventType getType() {
c26afeaf 148 CtfTmfEventType ctfTmfEventType = CtfTmfEventType.get(eventName);
6cfa0200
AM
149 if (ctfTmfEventType == null) {
150 /* Should only return null the first time */
151 ctfTmfEventType = new CtfTmfEventType(this.getEventName(), this.getContent());
c26afeaf
MD
152 }
153 return ctfTmfEventType;
a3fc8213
AM
154 }
155
8e964be1 156 /**
8e964be1
MK
157 * @since 2.0
158 */
860b76d4 159 @Override
8e964be1
MK
160 public Set<String> listCustomAttributes() {
161 if (fDeclaration == null) {
162 return new HashSet<String>();
163 }
164 return fDeclaration.getCustomAttributes();
165 }
166
167 /**
8e964be1
MK
168 * @since 2.0
169 */
860b76d4 170 @Override
8e964be1
MK
171 public String getCustomAttribute(String name) {
172 if (fDeclaration == null) {
173 return null;
174 }
175 return fDeclaration.getCustomAttribute(name);
176 }
177
60fb38b8 178 /**
f47ed727 179 * Get the call site for this event.
60fb38b8 180 *
f47ed727 181 * @return the call site information, or null if there is none
60fb38b8
PT
182 * @since 2.0
183 */
f47ed727 184 @Override
60fb38b8
PT
185 public CtfTmfCallsite getCallsite() {
186 CTFCallsite callsite = null;
187 if (getTrace() == null) {
188 return null;
189 }
190 if (getContent() != null) {
191 ITmfEventField ipField = getContent().getField(CtfConstants.CONTEXT_FIELD_PREFIX + CtfConstants.IP_KEY);
192 if (ipField != null && ipField.getValue() instanceof Long) {
193 long ip = (Long) ipField.getValue();
194 callsite = getTrace().getCTFTrace().getCallsite(eventName, ip);
195 }
196 }
197 if (callsite == null) {
198 callsite = getTrace().getCTFTrace().getCallsite(eventName);
199 }
200 if (callsite != null) {
201 return new CtfTmfCallsite(callsite);
202 }
203 return null;
204 }
205
f47ed727
BH
206 /**
207 * @since 2.0
208 */
209 @Override
210 public String getModelUri() {
211 return getCustomAttribute(CtfConstants.MODEL_URI_KEY);
212 }
213
531987c8
PT
214 /**
215 * @since 2.0
216 */
93bfd50a
PT
217 @Override
218 public Object getAdapter(Class adapter) {
219 if (adapter == IPropertySource.class) {
220 return new TmfEventPropertySource(this);
221 }
222 return null;
223 }
a3fc8213 224}
This page took 0.048182 seconds and 5 git commands to generate.