- /* Read the fields */
- this.fContent = new CtfTmfContent(ITmfEventField.ROOT_FIELD_ID,
- parseFields(eventDef));
- }
-
- /**
- * Extract the field information from the structDefinition haze-inducing
- * mess, and put them into something ITmfEventField can cope with.
- *
- * @param eventDef
- * CTF EventDefinition to read
- * @return CtfTmfEventField[] The array of fields that were read
- */
- private CtfTmfEventField[] parseFields(EventDefinition eventDef) {
- List<CtfTmfEventField> fields = new ArrayList<CtfTmfEventField>();
-
- StructDefinition structFields = eventDef.getFields();
- HashMap<String, Definition> definitions = structFields.getDefinitions();
- String curFieldName = null;
- Definition curFieldDef;
- CtfTmfEventField curField;
- Iterator<Entry<String, Definition>> it = definitions.entrySet().iterator();
- while(it.hasNext()) {
- Entry<String, Definition> entry = it.next();
- curFieldName = entry.getKey();
- curFieldDef = entry.getValue();
- curField = CtfTmfEventField.parseField(curFieldDef, curFieldName);
- fields.add(curField);
- }
-
- /* Add context information as CtfTmfEventField */
- long ip = -1;
- StructDefinition structContext = eventDef.getContext();
- if (structContext != null) {
- definitions = structContext.getDefinitions();
- String curContextName;
- Definition curContextDef;
- CtfTmfEventField curContext;
- it = definitions.entrySet().iterator();
- while(it.hasNext()) {
- Entry<String, Definition> entry = it.next();
- /* This is to get the instruction pointer if available */
- if (entry.getKey().equals("_ip") && //$NON-NLS-1$
- (entry.getValue() instanceof IntegerDefinition)) {
- ip = ((IntegerDefinition) entry.getValue()).getValue();
- }
- /* Prefix field name to */
- curContextName = CONTEXT_FIELD_PREFIX + entry.getKey();
- curContextDef = entry.getValue();
- curContext = CtfTmfEventField.parseField(curContextDef, curContextName);
- fields.add(curContext);
- }
- }
- /* Add callsite */
- final String name = eventDef.getDeclaration().getName();
- List<CTFCallsite> eventList = fTrace.getCTFTrace().getCallsiteCandidates(name);
- if (eventList != null) {
- final String callsite = "callsite"; //$NON-NLS-1$
- if (eventList.size() == 1 || ip == -1) {
- CTFCallsite cs = eventList.get(0);
- fields.add(new CTFStringField(cs.toString(), callsite));
- } else {
- fields.add(new CTFStringField(
- fTrace.getCTFTrace().getCallsite(name, ip).toString(),
- callsite));
- }
- }
-
- return fields.toArray(new CtfTmfEventField[fields.size()]);
- }
-
- /**
- * Copy constructor
- *
- * @param other
- * CtfTmfEvent to copy
- */
- public CtfTmfEvent(CtfTmfEvent other) {
- this.fTrace = other.getTrace();
- /* Primitives, those will be copied by value */
- this.timestamp = other.timestamp;
- this.sourceCPU = other.sourceCPU;
- this.typeId = other.typeId;
-
- /* Strings are immutable, it's safe to shallow-copy them */
- this.eventName = other.eventName;
- this.fileName = other.fileName;
-
- /* Copy the fields over */
- this.fContent = (CtfTmfContent) other.fContent.clone();