Commit | Line | Data |
---|---|---|
a3fc8213 | 1 | /******************************************************************************* |
60ae41e1 | 2 | * Copyright (c) 2011, 2014 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 | ||
14 | package org.eclipse.linuxtools.tmf.core.ctfadaptor; | |
15 | ||
8e964be1 | 16 | import java.util.HashSet; |
8e964be1 | 17 | import java.util.Set; |
a3fc8213 | 18 | |
60fb38b8 | 19 | import org.eclipse.linuxtools.ctf.core.event.CTFCallsite; |
8e964be1 | 20 | import org.eclipse.linuxtools.ctf.core.event.IEventDeclaration; |
f332660b | 21 | import org.eclipse.linuxtools.ctf.core.trace.CTFTrace; |
860b76d4 | 22 | import org.eclipse.linuxtools.tmf.core.event.ITmfCustomAttributes; |
a3fc8213 AM |
23 | import org.eclipse.linuxtools.tmf.core.event.ITmfEventField; |
24 | import org.eclipse.linuxtools.tmf.core.event.ITmfEventType; | |
6cfa0200 | 25 | import org.eclipse.linuxtools.tmf.core.event.TmfEvent; |
306dc902 | 26 | import org.eclipse.linuxtools.tmf.core.event.TmfEventField; |
f47ed727 BH |
27 | import org.eclipse.linuxtools.tmf.core.event.lookup.ITmfModelLookup; |
28 | import org.eclipse.linuxtools.tmf.core.event.lookup.ITmfSourceLookup; | |
6cfa0200 | 29 | import org.eclipse.linuxtools.tmf.core.trace.ITmfContext; |
a3fc8213 AM |
30 | |
31 | /** | |
f332660b MK |
32 | * A wrapper class around CTF's Event Definition/Declaration that maps all types |
33 | * of Declaration to native Java types. | |
6256d8ad | 34 | * |
d09f973b FC |
35 | * @version 1.0 |
36 | * @author Alexandre Montplaisir | |
93bfd50a | 37 | * @since 2.0 |
a3fc8213 | 38 | */ |
c26d0fe0 | 39 | public class CtfTmfEvent extends TmfEvent |
860b76d4 | 40 | implements ITmfSourceLookup, ITmfModelLookup, ITmfCustomAttributes { |
a3fc8213 AM |
41 | |
42 | // ------------------------------------------------------------------------ | |
43 | // Constants | |
44 | // ------------------------------------------------------------------------ | |
45 | ||
6cfa0200 | 46 | static final String NO_STREAM = "No stream"; //$NON-NLS-1$ |
a3fc8213 | 47 | private static final String EMPTY_CTF_EVENT_NAME = "Empty CTF event"; //$NON-NLS-1$ |
aa572e22 | 48 | |
a3fc8213 AM |
49 | // ------------------------------------------------------------------------ |
50 | // Attributes | |
51 | // ------------------------------------------------------------------------ | |
52 | ||
a3fc8213 AM |
53 | private final int sourceCPU; |
54 | private final long typeId; | |
55 | private final String eventName; | |
8e964be1 | 56 | private final IEventDeclaration fDeclaration; |
a3fc8213 AM |
57 | |
58 | // ------------------------------------------------------------------------ | |
59 | // Constructors | |
60 | // ------------------------------------------------------------------------ | |
61 | ||
62 | /** | |
6cfa0200 | 63 | * Constructor used by {@link CtfTmfEventFactory#createEvent} |
a3fc8213 | 64 | */ |
6cfa0200 AM |
65 | CtfTmfEvent(CtfTmfTrace trace, long rank, CtfTmfTimestamp timestamp, |
66 | ITmfEventField content, String fileName, int cpu, | |
67 | IEventDeclaration declaration) { | |
68 | super(trace, | |
69 | rank, | |
70 | timestamp, | |
71 | String.valueOf(cpu), // Source | |
72 | null, // Event type. We don't use TmfEvent's field here, we re-implement getType() | |
73 | content, | |
74 | fileName // Reference | |
75 | ); | |
76 | ||
77 | fDeclaration = declaration; | |
78 | sourceCPU = cpu; | |
79 | typeId = declaration.getId(); | |
80 | eventName = declaration.getName(); | |
e73a4ba5 | 81 | |
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 | ||
a3fc8213 AM |
131 | @Override |
132 | public CtfTmfTrace getTrace() { | |
f332660b MK |
133 | /* |
134 | * Should be of the right type, since we take a CtfTmfTrace at the | |
135 | * constructor | |
136 | */ | |
6cfa0200 | 137 | return (CtfTmfTrace) super.getTrace(); |
a3fc8213 AM |
138 | } |
139 | ||
140 | @Override | |
141 | public ITmfEventType getType() { | |
c26afeaf | 142 | CtfTmfEventType ctfTmfEventType = CtfTmfEventType.get(eventName); |
6cfa0200 AM |
143 | if (ctfTmfEventType == null) { |
144 | /* Should only return null the first time */ | |
33803b9b | 145 | ctfTmfEventType = new CtfTmfEventType(eventName, this.getContent()); |
c26afeaf MD |
146 | } |
147 | return ctfTmfEventType; | |
a3fc8213 AM |
148 | } |
149 | ||
8e964be1 | 150 | /** |
8e964be1 MK |
151 | * @since 2.0 |
152 | */ | |
860b76d4 | 153 | @Override |
8e964be1 MK |
154 | public Set<String> listCustomAttributes() { |
155 | if (fDeclaration == null) { | |
a4524c1b | 156 | return new HashSet<>(); |
8e964be1 MK |
157 | } |
158 | return fDeclaration.getCustomAttributes(); | |
159 | } | |
160 | ||
161 | /** | |
8e964be1 MK |
162 | * @since 2.0 |
163 | */ | |
860b76d4 | 164 | @Override |
8e964be1 MK |
165 | public String getCustomAttribute(String name) { |
166 | if (fDeclaration == null) { | |
167 | return null; | |
168 | } | |
169 | return fDeclaration.getCustomAttribute(name); | |
170 | } | |
171 | ||
60fb38b8 | 172 | /** |
f47ed727 | 173 | * Get the call site for this event. |
60fb38b8 | 174 | * |
f47ed727 | 175 | * @return the call site information, or null if there is none |
60fb38b8 PT |
176 | * @since 2.0 |
177 | */ | |
f47ed727 | 178 | @Override |
60fb38b8 PT |
179 | public CtfTmfCallsite getCallsite() { |
180 | CTFCallsite callsite = null; | |
f332660b MK |
181 | CtfTmfTrace trace = getTrace(); |
182 | if (trace == null) { | |
183 | return null; | |
184 | } | |
185 | CTFTrace ctfTrace = trace.getCTFTrace(); | |
186 | /* Should not happen, but it is a good check */ | |
187 | if (ctfTrace == null) { | |
60fb38b8 PT |
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(); | |
f332660b | 194 | callsite = ctfTrace.getCallsite(eventName, ip); |
60fb38b8 PT |
195 | } |
196 | } | |
197 | if (callsite == null) { | |
f332660b | 198 | callsite = ctfTrace.getCallsite(eventName); |
60fb38b8 PT |
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 | ||
a3fc8213 | 214 | } |