Commit | Line | Data |
---|---|---|
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 | ||
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; |
a3fc8213 AM |
21 | import org.eclipse.linuxtools.tmf.core.event.ITmfEventField; |
22 | import org.eclipse.linuxtools.tmf.core.event.ITmfEventType; | |
6cfa0200 | 23 | import org.eclipse.linuxtools.tmf.core.event.TmfEvent; |
306dc902 | 24 | import org.eclipse.linuxtools.tmf.core.event.TmfEventField; |
93bfd50a | 25 | import org.eclipse.linuxtools.tmf.core.event.TmfEventPropertySource; |
f47ed727 BH |
26 | import org.eclipse.linuxtools.tmf.core.event.lookup.ITmfModelLookup; |
27 | import org.eclipse.linuxtools.tmf.core.event.lookup.ITmfSourceLookup; | |
6cfa0200 | 28 | import org.eclipse.linuxtools.tmf.core.trace.ITmfContext; |
93bfd50a | 29 | import org.eclipse.ui.views.properties.IPropertySource; |
a3fc8213 AM |
30 | |
31 | /** | |
d09f973b FC |
32 | * A wrapper class around CTF's Event Definition/Declaration that maps all |
33 | * types 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 | */ |
f47ed727 | 39 | public final class CtfTmfEvent extends TmfEvent implements ITmfSourceLookup, ITmfModelLookup { |
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(); | |
a3fc8213 AM |
80 | } |
81 | ||
82 | /** | |
b8a6e46d | 83 | * Inner constructor to create "null" events. Don't use this directly in |
6cfa0200 AM |
84 | * normal usage, use {@link CtfTmfEventFactory#getNullEvent()} to get an |
85 | * instance of an empty event. | |
c26afeaf | 86 | * |
b8a6e46d AM |
87 | * This needs to be public however because it's used in extension points, |
88 | * and the framework will use this constructor to get the class type. | |
a3fc8213 | 89 | */ |
ce2388e0 | 90 | public CtfTmfEvent() { |
6cfa0200 AM |
91 | super(null, |
92 | ITmfContext.UNKNOWN_RANK, | |
93 | new CtfTmfTimestamp(-1), | |
94 | null, | |
95 | null, | |
214cc822 | 96 | new TmfEventField("", null, new CtfTmfEventField[0]), //$NON-NLS-1$ |
6cfa0200 | 97 | NO_STREAM); |
a3fc8213 AM |
98 | this.sourceCPU = -1; |
99 | this.typeId = -1; | |
a3fc8213 | 100 | this.eventName = EMPTY_CTF_EVENT_NAME; |
8e964be1 | 101 | this.fDeclaration = null; |
a3fc8213 AM |
102 | } |
103 | ||
104 | // ------------------------------------------------------------------------ | |
105 | // Getters/Setters/Predicates | |
106 | // ------------------------------------------------------------------------ | |
107 | ||
a3fc8213 AM |
108 | /** |
109 | * Gets the cpu core the event was recorded on. | |
110 | * | |
58f3bc52 AM |
111 | * @return The cpu id for a given source. In lttng it's from CPUINFO |
112 | */ | |
a3fc8213 AM |
113 | public int getCPU() { |
114 | return this.sourceCPU; | |
115 | } | |
116 | ||
117 | /** | |
58f3bc52 | 118 | * Return this event's ID, according to the trace's metadata. |
a3fc8213 | 119 | * |
58f3bc52 AM |
120 | * Watch out, this ID is not constant from one trace to another for the same |
121 | * event types! Use "getEventName()" for a constant reference. | |
122 | * | |
123 | * @return The event ID | |
124 | */ | |
a3fc8213 AM |
125 | public long getID() { |
126 | return this.typeId; | |
127 | } | |
128 | ||
129 | /** | |
130 | * Gets the name of a current event. | |
131 | * | |
58f3bc52 AM |
132 | * @return The event name |
133 | */ | |
a3fc8213 AM |
134 | public String getEventName() { |
135 | return eventName; | |
136 | } | |
137 | ||
a3fc8213 AM |
138 | @Override |
139 | public CtfTmfTrace getTrace() { | |
6cfa0200 AM |
140 | /* Should be of the right type, since we take a CtfTmfTrace at the constructor */ |
141 | return (CtfTmfTrace) super.getTrace(); | |
a3fc8213 AM |
142 | } |
143 | ||
144 | @Override | |
145 | public ITmfEventType getType() { | |
c26afeaf | 146 | CtfTmfEventType ctfTmfEventType = CtfTmfEventType.get(eventName); |
6cfa0200 AM |
147 | if (ctfTmfEventType == null) { |
148 | /* Should only return null the first time */ | |
149 | ctfTmfEventType = new CtfTmfEventType(this.getEventName(), this.getContent()); | |
c26afeaf MD |
150 | } |
151 | return ctfTmfEventType; | |
a3fc8213 AM |
152 | } |
153 | ||
8e964be1 MK |
154 | /** |
155 | * List the custom CTF attributes for events of this type. | |
156 | * | |
157 | * @return The list of custom attribute names. Should not be null, but could | |
158 | * be empty. | |
159 | * @since 2.0 | |
160 | */ | |
161 | public Set<String> listCustomAttributes() { | |
162 | if (fDeclaration == null) { | |
163 | return new HashSet<String>(); | |
164 | } | |
165 | return fDeclaration.getCustomAttributes(); | |
166 | } | |
167 | ||
168 | /** | |
169 | * Get the value of a custom CTF attributes for this event's type. | |
170 | * | |
171 | * @param name | |
172 | * Name of the the custom attribute | |
173 | * @return Value of this attribute, or null if there is no attribute with | |
174 | * that name | |
175 | * @since 2.0 | |
176 | */ | |
177 | public String getCustomAttribute(String name) { | |
178 | if (fDeclaration == null) { | |
179 | return null; | |
180 | } | |
181 | return fDeclaration.getCustomAttribute(name); | |
182 | } | |
183 | ||
60fb38b8 | 184 | /** |
f47ed727 | 185 | * Get the call site for this event. |
60fb38b8 | 186 | * |
f47ed727 | 187 | * @return the call site information, or null if there is none |
60fb38b8 PT |
188 | * @since 2.0 |
189 | */ | |
f47ed727 | 190 | @Override |
60fb38b8 PT |
191 | public CtfTmfCallsite getCallsite() { |
192 | CTFCallsite callsite = null; | |
193 | if (getTrace() == null) { | |
194 | return null; | |
195 | } | |
196 | if (getContent() != null) { | |
197 | ITmfEventField ipField = getContent().getField(CtfConstants.CONTEXT_FIELD_PREFIX + CtfConstants.IP_KEY); | |
198 | if (ipField != null && ipField.getValue() instanceof Long) { | |
199 | long ip = (Long) ipField.getValue(); | |
200 | callsite = getTrace().getCTFTrace().getCallsite(eventName, ip); | |
201 | } | |
202 | } | |
203 | if (callsite == null) { | |
204 | callsite = getTrace().getCTFTrace().getCallsite(eventName); | |
205 | } | |
206 | if (callsite != null) { | |
207 | return new CtfTmfCallsite(callsite); | |
208 | } | |
209 | return null; | |
210 | } | |
211 | ||
f47ed727 BH |
212 | /** |
213 | * @since 2.0 | |
214 | */ | |
215 | @Override | |
216 | public String getModelUri() { | |
217 | return getCustomAttribute(CtfConstants.MODEL_URI_KEY); | |
218 | } | |
219 | ||
531987c8 PT |
220 | /** |
221 | * @since 2.0 | |
222 | */ | |
93bfd50a PT |
223 | @Override |
224 | public Object getAdapter(Class adapter) { | |
225 | if (adapter == IPropertySource.class) { | |
226 | return new TmfEventPropertySource(this); | |
227 | } | |
228 | return null; | |
229 | } | |
a3fc8213 | 230 | } |