1 /*******************************************************************************
2 * Copyright (c) 2011, 2014 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
.ctf
.core
;
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
.ctf
.core
.trace
.CTFTrace
;
22 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfCustomAttributes
;
23 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEventField
;
24 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEventType
;
25 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfEvent
;
26 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfEventField
;
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
;
32 * A wrapper class around CTF's Event Definition/Declaration that maps all types
33 * of Declaration to native Java types.
36 * @author Alexandre Montplaisir
39 public class CtfTmfEvent
extends TmfEvent
40 implements ITmfSourceLookup
, ITmfModelLookup
, ITmfCustomAttributes
{
42 // ------------------------------------------------------------------------
44 // ------------------------------------------------------------------------
46 static final String NO_STREAM
= "No stream"; //$NON-NLS-1$
47 private static final String EMPTY_CTF_EVENT_NAME
= "Empty CTF event"; //$NON-NLS-1$
49 // ------------------------------------------------------------------------
51 // ------------------------------------------------------------------------
53 private final int fSourceCPU
;
54 private final long fTypeId
;
55 private final String fEventName
;
56 private final IEventDeclaration fDeclaration
;
58 // ------------------------------------------------------------------------
60 // ------------------------------------------------------------------------
63 * Constructor used by {@link CtfTmfEventFactory#createEvent}
65 CtfTmfEvent(CtfTmfTrace trace
, long rank
, CtfTmfTimestamp timestamp
,
66 ITmfEventField content
, String fileName
, int cpu
,
67 IEventDeclaration declaration
) {
71 String
.valueOf(cpu
), // Source
72 null, // Event type. We don't use TmfEvent's field here, we re-implement getType()
77 fDeclaration
= declaration
;
79 fTypeId
= declaration
.getId();
80 fEventName
= 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 fEventName
= EMPTY_CTF_EVENT_NAME
;
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() {
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 public CtfTmfTrace
getTrace() {
134 * Should be of the right type, since we take a CtfTmfTrace at the
137 return (CtfTmfTrace
) super.getTrace();
141 public ITmfEventType
getType() {
142 CtfTmfEventType ctfTmfEventType
= CtfTmfEventType
.get(getTrace(), fEventName
);
143 if (ctfTmfEventType
== null) {
144 /* Should only return null the first time */
145 ctfTmfEventType
= new CtfTmfEventType(fEventName
, getTrace(), getContent());
147 return ctfTmfEventType
;
154 public Set
<String
> listCustomAttributes() {
155 if (fDeclaration
== null) {
156 return new HashSet
<>();
158 return fDeclaration
.getCustomAttributes();
165 public String
getCustomAttribute(String name
) {
166 if (fDeclaration
== null) {
169 return fDeclaration
.getCustomAttribute(name
);
173 * Get the call site for this event.
175 * @return the call site information, or null if there is none
179 public CtfTmfCallsite
getCallsite() {
180 CTFCallsite callsite
= null;
181 CtfTmfTrace trace
= getTrace();
185 CTFTrace ctfTrace
= trace
.getCTFTrace();
186 /* Should not happen, but it is a good check */
187 if (ctfTrace
== 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
= ctfTrace
.getCallsite(fEventName
, ip
);
197 if (callsite
== null) {
198 callsite
= ctfTrace
.getCallsite(fEventName
);
200 if (callsite
!= null) {
201 return new CtfTmfCallsite(callsite
);
210 public String
getModelUri() {
211 return getCustomAttribute(CtfConstants
.MODEL_URI_KEY
);