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
.lookup
.ITmfModelLookup
;
27 import org
.eclipse
.linuxtools
.tmf
.core
.event
.lookup
.ITmfSourceLookup
;
28 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfContext
;
31 * A wrapper class around CTF's Event Definition/Declaration that maps all
32 * types of Declaration to native Java types.
35 * @author Alexandre Montplaisir
38 public class CtfTmfEvent
extends TmfEvent
39 implements ITmfSourceLookup
, ITmfModelLookup
, ITmfCustomAttributes
{
41 // ------------------------------------------------------------------------
43 // ------------------------------------------------------------------------
45 static final String NO_STREAM
= "No stream"; //$NON-NLS-1$
46 private static final String EMPTY_CTF_EVENT_NAME
= "Empty CTF event"; //$NON-NLS-1$
48 // ------------------------------------------------------------------------
50 // ------------------------------------------------------------------------
52 private final int sourceCPU
;
53 private final long typeId
;
54 private final String eventName
;
55 private final IEventDeclaration fDeclaration
;
57 // ------------------------------------------------------------------------
59 // ------------------------------------------------------------------------
62 * Constructor used by {@link CtfTmfEventFactory#createEvent}
64 CtfTmfEvent(CtfTmfTrace trace
, long rank
, CtfTmfTimestamp timestamp
,
65 ITmfEventField content
, String fileName
, int cpu
,
66 IEventDeclaration declaration
) {
70 String
.valueOf(cpu
), // Source
71 null, // Event type. We don't use TmfEvent's field here, we re-implement getType()
76 fDeclaration
= declaration
;
78 typeId
= declaration
.getId();
79 eventName
= declaration
.getName();
84 * Inner constructor to create "null" events. Don't use this directly in
85 * normal usage, use {@link CtfTmfEventFactory#getNullEvent()} to get an
86 * instance of an empty event.
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.
91 public CtfTmfEvent() {
93 ITmfContext
.UNKNOWN_RANK
,
94 new CtfTmfTimestamp(-1),
97 new TmfEventField("", null, new CtfTmfEventField
[0]), //$NON-NLS-1$
101 this.eventName
= EMPTY_CTF_EVENT_NAME
;
102 this.fDeclaration
= null;
105 // ------------------------------------------------------------------------
106 // Getters/Setters/Predicates
107 // ------------------------------------------------------------------------
110 * Gets the cpu core the event was recorded on.
112 * @return The cpu id for a given source. In lttng it's from CPUINFO
114 public int getCPU() {
115 return this.sourceCPU
;
119 * Return this event's ID, according to the trace's metadata.
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.
124 * @return The event ID
126 public long getID() {
131 * Gets the name of a current event.
133 * @return The event name
135 public String
getEventName() {
140 public CtfTmfTrace
getTrace() {
141 /* Should be of the right type, since we take a CtfTmfTrace at the constructor */
142 return (CtfTmfTrace
) super.getTrace();
146 public ITmfEventType
getType() {
147 CtfTmfEventType ctfTmfEventType
= CtfTmfEventType
.get(eventName
);
148 if (ctfTmfEventType
== null) {
149 /* Should only return null the first time */
150 ctfTmfEventType
= new CtfTmfEventType(this.getEventName(), this.getContent());
152 return ctfTmfEventType
;
159 public Set
<String
> listCustomAttributes() {
160 if (fDeclaration
== null) {
161 return new HashSet
<>();
163 return fDeclaration
.getCustomAttributes();
170 public String
getCustomAttribute(String name
) {
171 if (fDeclaration
== null) {
174 return fDeclaration
.getCustomAttribute(name
);
178 * Get the call site for this event.
180 * @return the call site information, or null if there is none
184 public CtfTmfCallsite
getCallsite() {
185 CTFCallsite callsite
= null;
186 if (getTrace() == null) {
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
);
196 if (callsite
== null) {
197 callsite
= getTrace().getCTFTrace().getCallsite(eventName
);
199 if (callsite
!= null) {
200 return new CtfTmfCallsite(callsite
);
209 public String
getModelUri() {
210 return getCustomAttribute(CtfConstants
.MODEL_URI_KEY
);