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