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