17
17
import java.util.List;
18
18
import java.util.Map.Entry;
20
import org.eclipse.linuxtools.ctf.core.event.CTFCallsite;
20
21
import org.eclipse.linuxtools.ctf.core.event.EventDefinition;
21
22
import org.eclipse.linuxtools.ctf.core.event.types.Definition;
23
import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition;
22
24
import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition;
23
25
import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
24
26
import org.eclipse.linuxtools.tmf.core.event.ITmfEventField;
41
43
private static final String NO_STREAM = "No stream"; //$NON-NLS-1$
42
44
private static final String EMPTY_CTF_EVENT_NAME = "Empty CTF event"; //$NON-NLS-1$
46
/** Prefix for Context information stored as CtfTmfEventfield */
47
private static final String CONTEXT_FIELD_PREFIX = "context."; //$NON-NLS-1$
45
49
// ------------------------------------------------------------------------
64
68
* the StreamInputReader).
68
* @param fileName String
69
* @param originTrace CtfTmfTrace
71
* CTF EventDefinition object corresponding to this trace event
73
* The path to the trace file
75
* The trace from which this event originates
71
77
public CtfTmfEvent(EventDefinition eventDef, String fileName,
72
78
CtfTmfTrace originTrace) {
100
106
* mess, and put them into something ITmfEventField can cope with.
102
108
* @param eventDef
104
* @return CtfTmfEventField[]
109
* CTF EventDefinition to read
110
* @return CtfTmfEventField[] The array of fields that were read
106
public static CtfTmfEventField[] parseFields(EventDefinition eventDef) {
112
private CtfTmfEventField[] parseFields(EventDefinition eventDef) {
107
113
List<CtfTmfEventField> fields = new ArrayList<CtfTmfEventField>();
109
115
StructDefinition structFields = eventDef.getFields();
110
116
HashMap<String, Definition> definitions = structFields.getDefinitions();
117
String curFieldName = null;
112
118
Definition curFieldDef;
113
119
CtfTmfEventField curField;
114
120
Iterator<Entry<String, Definition>> it = definitions.entrySet().iterator();
120
126
fields.add(curField);
129
/* Add context information as CtfTmfEventField */
131
StructDefinition structContext = eventDef.getContext();
132
if (structContext != null) {
133
definitions = structContext.getDefinitions();
134
String curContextName;
135
Definition curContextDef;
136
CtfTmfEventField curContext;
137
it = definitions.entrySet().iterator();
138
while(it.hasNext()) {
139
Entry<String, Definition> entry = it.next();
140
/* This is to get the instruction pointer if available */
141
if (entry.getKey().equals("_ip") && //$NON-NLS-1$
142
(entry.getValue() instanceof IntegerDefinition)) {
143
ip = ((IntegerDefinition) entry.getValue()).getValue();
145
/* Prefix field name to */
146
curContextName = CONTEXT_FIELD_PREFIX + entry.getKey();
147
curContextDef = entry.getValue();
148
curContext = CtfTmfEventField.parseField(curContextDef, curContextName);
149
fields.add(curContext);
153
final String name = eventDef.getDeclaration().getName();
154
List<CTFCallsite> eventList = fTrace.getCTFTrace().getCallsiteCandidates(name);
155
if (!eventList.isEmpty()) {
156
final String callsite = "callsite"; //$NON-NLS-1$
157
if (eventList.size() == 1 || ip == -1) {
158
CTFCallsite cs = eventList.get(0);
159
fields.add(new CTFStringField(cs.toString(), callsite));
161
final CTFCallsite callsiteName = fTrace.getCTFTrace().getCallsite(
163
if (callsiteName != null) {
164
fields.add(new CTFStringField(callsiteName.toString(),
123
170
return fields.toArray(new CtfTmfEventField[fields.size()]);