1 /*******************************************************************************
2 * Copyright (c) 2011-2013 Ericsson
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
10 * Alexandre Montplaisir - Initial API and implementation
11 * Bernd Hufmann - Updated for source and model lookup interfaces
12 *******************************************************************************/
14 package org
.eclipse
.linuxtools
.tmf
.core
.ctfadaptor
;
16 import java
.util
.HashSet
;
19 import org
.eclipse
.linuxtools
.ctf
.core
.event
.CTFCallsite
;
20 import org
.eclipse
.linuxtools
.ctf
.core
.event
.IEventDeclaration
;
21 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfCustomAttributes
;
22 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEventField
;
23 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEventType
;
24 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfEvent
;
25 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfEventField
;
26 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfEventPropertySource
;
27 import org
.eclipse
.linuxtools
.tmf
.core
.event
.lookup
.ITmfModelLookup
;
28 import org
.eclipse
.linuxtools
.tmf
.core
.event
.lookup
.ITmfSourceLookup
;
29 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfContext
;
30 import org
.eclipse
.ui
.views
.properties
.IPropertySource
;
33 * A wrapper class around CTF's Event Definition/Declaration that maps all
34 * types of Declaration to native Java types.
37 * @author Alexandre Montplaisir
40 public final class CtfTmfEvent
extends TmfEvent
41 implements ITmfSourceLookup
, ITmfModelLookup
, ITmfCustomAttributes
{
43 // ------------------------------------------------------------------------
45 // ------------------------------------------------------------------------
47 static final String NO_STREAM
= "No stream"; //$NON-NLS-1$
48 private static final String EMPTY_CTF_EVENT_NAME
= "Empty CTF event"; //$NON-NLS-1$
50 // ------------------------------------------------------------------------
52 // ------------------------------------------------------------------------
54 private final int sourceCPU
;
55 private final long typeId
;
56 private final String eventName
;
57 private final IEventDeclaration fDeclaration
;
59 // ------------------------------------------------------------------------
61 // ------------------------------------------------------------------------
64 * Constructor used by {@link CtfTmfEventFactory#createEvent}
66 CtfTmfEvent(CtfTmfTrace trace
, long rank
, CtfTmfTimestamp timestamp
,
67 ITmfEventField content
, String fileName
, int cpu
,
68 IEventDeclaration declaration
) {
72 String
.valueOf(cpu
), // Source
73 null, // Event type. We don't use TmfEvent's field here, we re-implement getType()
78 fDeclaration
= declaration
;
80 typeId
= declaration
.getId();
81 eventName
= declaration
.getName();
85 * Inner constructor to create "null" events. Don't use this directly in
86 * normal usage, use {@link CtfTmfEventFactory#getNullEvent()} to get an
87 * instance of an empty event.
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.
92 public CtfTmfEvent() {
94 ITmfContext
.UNKNOWN_RANK
,
95 new CtfTmfTimestamp(-1),
98 new TmfEventField("", null, new CtfTmfEventField
[0]), //$NON-NLS-1$
102 this.eventName
= EMPTY_CTF_EVENT_NAME
;
103 this.fDeclaration
= null;
106 // ------------------------------------------------------------------------
107 // Getters/Setters/Predicates
108 // ------------------------------------------------------------------------
111 * Gets the cpu core the event was recorded on.
113 * @return The cpu id for a given source. In lttng it's from CPUINFO
115 public int getCPU() {
116 return this.sourceCPU
;
120 * Return this event's ID, according to the trace's metadata.
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.
125 * @return The event ID
127 public long getID() {
132 * Gets the name of a current event.
134 * @return The event name
136 public String
getEventName() {
141 public CtfTmfTrace
getTrace() {
142 /* Should be of the right type, since we take a CtfTmfTrace at the constructor */
143 return (CtfTmfTrace
) super.getTrace();
147 public ITmfEventType
getType() {
148 CtfTmfEventType ctfTmfEventType
= CtfTmfEventType
.get(eventName
);
149 if (ctfTmfEventType
== null) {
150 /* Should only return null the first time */
151 ctfTmfEventType
= new CtfTmfEventType(this.getEventName(), this.getContent());
153 return ctfTmfEventType
;
160 public Set
<String
> listCustomAttributes() {
161 if (fDeclaration
== null) {
162 return new HashSet
<String
>();
164 return fDeclaration
.getCustomAttributes();
171 public String
getCustomAttribute(String name
) {
172 if (fDeclaration
== null) {
175 return fDeclaration
.getCustomAttribute(name
);
179 * Get the call site for this event.
181 * @return the call site information, or null if there is none
185 public CtfTmfCallsite
getCallsite() {
186 CTFCallsite callsite
= null;
187 if (getTrace() == null) {
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
);
197 if (callsite
== null) {
198 callsite
= getTrace().getCTFTrace().getCallsite(eventName
);
200 if (callsite
!= null) {
201 return new CtfTmfCallsite(callsite
);
210 public String
getModelUri() {
211 return getCustomAttribute(CtfConstants
.MODEL_URI_KEY
);
218 public Object
getAdapter(Class adapter
) {
219 if (adapter
== IPropertySource
.class) {
220 return new TmfEventPropertySource(this);