~ubuntu-branches/ubuntu/trusty/eclipse-linuxtools/trusty

« back to all changes in this revision

Viewing changes to lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfEvent.java

  • Committer: Package Import Robot
  • Author(s): tony mancill
  • Date: 2013-05-13 21:43:22 UTC
  • mfrom: (1.2.1) (2.1.2 experimental)
  • Revision ID: package-import@ubuntu.com-20130513214322-6frgd9du1n0w2uo7
Tags: 1.2.1-1
* Team upload.
* New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
import java.util.List;
18
18
import java.util.Map.Entry;
19
19
 
 
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;
28
30
/**
29
31
 * A wrapper class around CTF's Event Definition/Declaration that maps all
30
32
 * types of Declaration to native Java types.
31
 
 * 
 
33
 *
32
34
 * @version 1.0
33
35
 * @author Alexandre Montplaisir
34
36
 */
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$
43
45
 
 
46
    /** Prefix for Context information stored as CtfTmfEventfield */
 
47
    private static final String CONTEXT_FIELD_PREFIX = "context."; //$NON-NLS-1$
44
48
 
45
49
    // ------------------------------------------------------------------------
46
50
    // Attributes
64
68
     * the StreamInputReader).
65
69
     *
66
70
     * @param eventDef
67
 
 
68
 
     * @param fileName String
69
 
     * @param originTrace CtfTmfTrace
 
71
     *            CTF EventDefinition object corresponding to this trace event
 
72
     * @param fileName
 
73
     *            The path to the trace file
 
74
     * @param originTrace
 
75
     *            The trace from which this event originates
70
76
     */
71
77
    public CtfTmfEvent(EventDefinition eventDef, String fileName,
72
78
            CtfTmfTrace originTrace) {
100
106
     * mess, and put them into something ITmfEventField can cope with.
101
107
     *
102
108
     * @param eventDef
103
 
 
104
 
     * @return CtfTmfEventField[]
 
109
     *            CTF EventDefinition to read
 
110
     * @return CtfTmfEventField[] The array of fields that were read
105
111
     */
106
 
    public static CtfTmfEventField[] parseFields(EventDefinition eventDef) {
 
112
    private CtfTmfEventField[] parseFields(EventDefinition eventDef) {
107
113
        List<CtfTmfEventField> fields = new ArrayList<CtfTmfEventField>();
108
114
 
109
115
        StructDefinition structFields = eventDef.getFields();
110
116
        HashMap<String, Definition> definitions = structFields.getDefinitions();
111
 
        String curFieldName;
 
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);
121
127
        }
122
128
 
 
129
        /* Add context information as CtfTmfEventField */
 
130
        long ip = -1;
 
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();
 
144
                }
 
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);
 
150
            }
 
151
        }
 
152
        /* Add callsite */
 
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));
 
160
            } else {
 
161
                final CTFCallsite callsiteName = fTrace.getCTFTrace().getCallsite(
 
162
                        name, ip);
 
163
                if (callsiteName != null) {
 
164
                    fields.add(new CTFStringField(callsiteName.toString(),
 
165
                            callsite));
 
166
                }
 
167
            }
 
168
        }
 
169
 
123
170
        return fields.toArray(new CtfTmfEventField[fields.size()]);
124
171
    }
125
172
 
127
174
     * Copy constructor
128
175
     *
129
176
     * @param other
 
177
     *            CtfTmfEvent to copy
130
178
     */
131
179
    public CtfTmfEvent(CtfTmfEvent other) {
132
180
        this.fTrace = other.getTrace();