tmf: Bug 477508: Fix wrong event count and ranks in TmfXmlTraceStub
authorPatrick Tasse <patrick.tasse@gmail.com>
Tue, 24 Nov 2015 23:27:50 +0000 (18:27 -0500)
committerPatrick Tasse <patrick.tasse@gmail.com>
Thu, 26 Nov 2015 20:07:44 +0000 (15:07 -0500)
The stub implementation of getNext() was increasing the context rank
twice per event. This would cause a wrong event count in the trace.

The processing of the 'set_aspects' dummy event was also causing the
context rank to be incremented twice. The XML Schema Definition is
changed to extract 'set_aspects' into its own element. The trace stub
now first parses the trace with a custom XML trace definition that only
processes the single 'set_aspects' event, then reinitializes the trace
with a custom XML trace definition that processes 'event' events.

Change-Id: Id1cf2251e364f892ab37511f0a5d99f2bcc2b5c6
Signed-off-by: Patrick Tasse <patrick.tasse@gmail.com>
Reviewed-on: https://git.eclipse.org/r/61205
Reviewed-by: Hudson CI
analysis/org.eclipse.tracecompass.analysis.os.linux.core.tests/testfiles/cpu_analysis.xml
analysis/org.eclipse.tracecompass.analysis.os.linux.core.tests/testfiles/lttng_kernel_analysis.xml
lttng/org.eclipse.tracecompass.lttng2.kernel.core.tests/testfiles/graph/sched_only.xml
lttng/org.eclipse.tracecompass.lttng2.kernel.core.tests/testfiles/vm/OneQemuKvm/guest.xml
lttng/org.eclipse.tracecompass.lttng2.kernel.core.tests/testfiles/vm/OneQemuKvm/host.xml
tmf/org.eclipse.tracecompass.tmf.core.tests/stubs/org/eclipse/tracecompass/tmf/tests/stubs/trace/xml/TmfXmlDevelopmentTrace.xml
tmf/org.eclipse.tracecompass.tmf.core.tests/stubs/org/eclipse/tracecompass/tmf/tests/stubs/trace/xml/TmfXmlDevelopmentTrace.xsd
tmf/org.eclipse.tracecompass.tmf.core.tests/stubs/org/eclipse/tracecompass/tmf/tests/stubs/trace/xml/TmfXmlTraceStub.java
tmf/org.eclipse.tracecompass.tmf.core.tests/testfiles/stub_xml_traces/valid/test.xml
tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/ui/swtbot/tests/wizards/TestImportExportPackageWizard.java

index 01faef4aa8101f358a2ddc0159d2a9e5a79813a6..6f6c1f1d3aad3f8f64188af459175e33f0d3a542 100644 (file)
@@ -1,7 +1,7 @@
 <trace>
-<event timestamp="0" name="set_aspects">
+<set_aspects>
 <field name="cpu" value="1" type="int" />
-</event>
+</set_aspects>
 <event timestamp="1" name="sched_switch">
 <field name="cpu" value="0" type="int" />
 <field name="prev_comm" value="proc1" type="string" />
index 40f7efcfdbbd4f6f6f552f7bfa513221646f60a7..4e0469a9dc6a1e23cca50ad0fb3560ae36b82983 100644 (file)
@@ -3,9 +3,9 @@
 * sched_switches and a process forking
 *************************************************************************** -->
 <trace>
-<event timestamp="0" name="set_aspects">
+<set_aspects>
 <field name="cpu" value="1" type="int" />
-</event>
+</set_aspects>
 <event timestamp="1" name="lttng_statedump_process_state">
 <field name="cpu" value="0" type="int" />
 <field name="tid" value="10" type="long" />
index 8ddf57775993e76d030acee5d6ba3a0911bcaaec..a827f5b3ceafeee1e8f7c39de73df63f41b34372 100644 (file)
@@ -1,7 +1,7 @@
 <trace>
-<event timestamp="0" name="set_aspects">
+<set_aspects>
 <field name="cpu" value="1" type="int" />
-</event>
+</set_aspects>
 <event timestamp="10" name="sched_switch">
 <field name="cpu" value="0" type="int" />
 <field name="prev_comm" value="proc1" type="string" />
index fc973d3a5a0f8a8445fb2c41c2690f26e3075117..60d106373899475b167b74331d96fc6833be3646 100644 (file)
@@ -1,7 +1,7 @@
 <trace>
-<event timestamp="0" name="set_aspects">
+<set_aspects>
 <field name="cpu" value="1" type="int" />
-</event>
+</set_aspects>
 <event timestamp="10" name="sched_switch">
 <field name="cpu" value="0" type="int" />
 <field name="prev_comm" value="any" type="string" />
index c26e8367f7452e67174ed40fbe35cdcad084bed1..dc0e1fa9d82afb36a9caff0e58f9827005e482a4 100644 (file)
@@ -1,7 +1,7 @@
 <trace>
-<event timestamp="0" name="set_aspects">
+<set_aspects>
 <field name="cpu" value="1" type="int" />
-</event>
+</set_aspects>
 <event timestamp="1" name="sched_switch">
 <field name="cpu" value="0" type="int" />
 <field name="prev_comm" value="any" type="string" />
index 3a94a57720c89dd16f0aea792ce8f4a9c267a23a..1cd1aa7e0762d5c179e6e2fb8847c0b769c373ff 100644 (file)
@@ -1,6 +1,28 @@
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
 <CustomXMLTraceDefinitionList>
-<Definition name="handmade">
+<Definition name="set_aspects">
+<InputElement name="trace">
+<InputElement logentry="true" name="set_aspects">
+<InputData action="0" format="" name="Ignore"/>
+<InputElement name="field">
+<InputData action="0" format="" name="Ignore"/>
+<Attribute name="name">
+<InputData action="2" format="" name="fields"/>
+</Attribute>
+<Attribute name="type">
+<InputData action="2" format="" name="type"/>
+</Attribute>
+<Attribute name="value">
+<InputData action="2" format="" name="values"/>
+</Attribute>
+</InputElement>
+</InputElement>
+</InputElement>
+<OutputColumn name="fields"/>
+<OutputColumn name="values"/>
+<OutputColumn name="type"/>
+</Definition>
+<Definition name="events">
 <TimeStampOutputFormat>T</TimeStampOutputFormat>
 <InputElement name="trace">
 <InputElement logentry="true" name="event">
index b77f0f9a1d12f5719a8dace8db4aadbbcfe17a5f..b2f20bf796a07eba9f0d861594b60d4d6086b053 100644 (file)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
 <!-- ***************************************************************************
- * Copyright (c) 2014 École Polytechnique de Montréal
+ * Copyright (c) 2014, 2015 École Polytechnique de Montréal and others
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
@@ -9,6 +9,7 @@
  *
  * Contributors:
  *   Geneviève Bastien - Initial API and implementation
+ *   Patrick Tasse - Extract set_aspects in its own element
  *************************************************************************** -->
 <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
        attributeFormDefault="unqualified" elementFormDefault="qualified">
        <xs:element name="trace">
                <xs:complexType>
                        <xs:sequence>
+                               <xs:element maxOccurs="1" minOccurs="0" name="set_aspects" type="set_aspects" />
                                <xs:element maxOccurs="unbounded" minOccurs="0" name="event" type="event" />
                        </xs:sequence>
                </xs:complexType>
        </xs:element>
 
+       <xs:complexType name="set_aspects">
+               <xs:sequence>
+                       <xs:element maxOccurs="unbounded" minOccurs="0" name="field" type="field" />
+               </xs:sequence>
+       </xs:complexType>
+
        <xs:complexType name="event">
                <xs:sequence>
                        <xs:element maxOccurs="unbounded" minOccurs="0" name="field" type="field" />
index 64c48ac99dec115b0d4b3611baf49eecd156e513..7b91eeafacd2b11895ee35d0104b64ab709c6768 100644 (file)
@@ -56,6 +56,8 @@ import org.eclipse.tracecompass.tmf.core.timestamp.TmfNanoTimestamp;
 import org.eclipse.tracecompass.tmf.core.trace.ITmfContext;
 import org.eclipse.tracecompass.tmf.core.trace.TmfContext;
 import org.eclipse.tracecompass.tmf.core.trace.TmfTrace;
+import org.eclipse.tracecompass.tmf.core.trace.indexer.ITmfTraceIndexer;
+import org.eclipse.tracecompass.tmf.core.trace.indexer.checkpoint.TmfCheckpointIndexer;
 import org.eclipse.tracecompass.tmf.core.trace.location.ITmfLocation;
 import org.xml.sax.SAXException;
 
@@ -90,14 +92,14 @@ public class TmfXmlTraceStub extends TmfTrace {
     private static final String VALUES_SEPARATOR = " \\| "; //$NON-NLS-1$
     private static final String TYPE_INTEGER = "int"; //$NON-NLS-1$
     private static final String TYPE_LONG = "long"; //$NON-NLS-1$
-    private static final String ASPECT_SPECIAL_EVENT = "set_aspects";
     private static final String ASPECT_CPU = "cpu";
 
     private static final Long SECONDS_TO_NS = 1000000000L;
 
-    private final CustomXmlTrace fTrace;
+    private final CustomXmlTraceDefinition fDefinition;
+    private CustomXmlTrace fTrace;
 
-    private Collection<ITmfEventAspect> fAspects;
+    private Collection<ITmfEventAspect> fAspects = TmfTrace.BASE_ASPECTS;
 
     /**
      * Constructor. Constructs the custom XML trace with the appropriate
@@ -108,15 +110,19 @@ public class TmfXmlTraceStub extends TmfTrace {
         /* Load custom XML definition */
         try (InputStream in = TmfXmlTraceStub.class.getResourceAsStream(DEVELOPMENT_TRACE_PARSER_PATH);) {
             CustomXmlTraceDefinition[] definitions = CustomXmlTraceDefinition.loadAll(in);
-            if (definitions.length == 0) {
+            if (definitions.length < 2) {
                 throw new IllegalStateException("The custom trace definition does not exist"); //$NON-NLS-1$
             }
-            fTrace = new CustomXmlTrace(definitions[0]);
-            /* Deregister the custom XML trace */
-            TmfSignalManager.deregister(fTrace);
-
-            Collection<ITmfEventAspect> aspects = TmfTrace.BASE_ASPECTS;
-            fAspects = aspects;
+            /* The first definition parses the 'set_aspects' event */
+            fTrace = new CustomXmlTrace(definitions[0]) {
+                @Override
+                protected ITmfTraceIndexer createIndexer(int interval) {
+                    /* Use the in-memory checkpoint indexer */
+                    return new TmfCheckpointIndexer(this, interval);
+                }
+            };
+            /* The second definition parses 'event' trace events */
+            fDefinition = checkNotNull(definitions[1]);
         } catch (IOException e) {
             throw new IllegalStateException("Cannot open the trace parser for development traces"); //$NON-NLS-1$
         }
@@ -126,8 +132,21 @@ public class TmfXmlTraceStub extends TmfTrace {
     @Override
     public void initTrace(@Nullable IResource resource, @Nullable String path, @Nullable Class<? extends ITmfEvent> type) throws TmfTraceException {
         super.initTrace(resource, path, type);
-        fTrace.initTrace(resource, path, type);
         ITmfContext ctx;
+
+        /* Initialize and read the trace with the 'set_aspects' definition */
+        TmfSignalManager.deregister(fTrace);
+        fTrace.initTrace(resource, path, type);
+        ctx = seekEvent(0L);
+        /* If a set_aspects event exists, getNext() will process it */
+        getNext(ctx);
+        ctx.dispose();
+        fTrace.dispose();
+
+        /* Initialize a new trace with the trace events definition */
+        fTrace = new CustomXmlTrace(fDefinition);
+        TmfSignalManager.deregister(fTrace);
+        fTrace.initTrace(resource, path, type);
         /* Set the start and (current) end times for this trace */
         ctx = seekEvent(0L);
         if (ctx == null) {
@@ -139,6 +158,7 @@ public class TmfXmlTraceStub extends TmfTrace {
             this.setStartTime(curTime);
             this.setEndTime(curTime);
         }
+        ctx.dispose();
     }
 
     @Override
@@ -277,15 +297,15 @@ public class TmfXmlTraceStub extends TmfTrace {
             fieldsArray[i] = new TmfEventField(checkNotNull(fields[i]), val, null);
         }
 
-        /* Generate the aspects for this trace if it is the aspects special event */
-        String eventName = getStringValue(content, EVENT_NAME_FIELD);
-        if (eventName.equals(ASPECT_SPECIAL_EVENT)) {
+        /* Generate the aspects for this trace if it is the 'set_aspects' definition */
+        if (fTrace.getDefinition() != fDefinition) {
             generateAspects(fieldsArray);
-            return getNext(context);
+            return null;
         }
 
         /* Create a new event with new fields and name */
         ITmfEventType customEventType = event.getType();
+        String eventName = getStringValue(content, EVENT_NAME_FIELD);
         TmfEventType eventType = new TmfEventType(eventName, customEventType.getRootField());
         ITmfEventField eventFields = new CustomEventContent(content.getName(), content.getValue(), fieldsArray);
         /*
@@ -297,8 +317,6 @@ public class TmfXmlTraceStub extends TmfTrace {
         ITmfTimestamp timestamp = new TmfNanoTimestamp(event.getTimestamp().getValue() / SECONDS_TO_NS);
         TmfEvent newEvent = new TmfEvent(this, ITmfContext.UNKNOWN_RANK, timestamp, eventType, eventFields);
         updateAttributes(savedContext, event);
-        context.increaseRank();
-
         return newEvent;
     }
 
index e7874e642bda1b244bd76bd36d34c58fac082a21..04589d876cc9cd047e802d2b2ba2d618b63e971a 100644 (file)
@@ -1,8 +1,8 @@
 <trace>
-<event timestamp="0" name="set_aspects">
+<set_aspects>
 <field name="cpu" value="1" type="int" />
 <field name="test" value="abc" type="string" />
-</event>
+</set_aspects>
 <event timestamp="1" name="A">
 <field name="cpu" value="1" type="int" />
 <field name="test" value="abc" type="string" />
index b0c8f1ac48e0ccfe43f81a54ab1cc4b75f0a96e6..421023a969fb15baa9a08e728b90332dc58be6c9 100644 (file)
@@ -66,10 +66,6 @@ public class TestImportExportPackageWizard {
     private static final String PROJECT_NAME = "Test";
     private static final String XMLSTUB_ID = "org.eclipse.linuxtools.tmf.core.tests.xmlstub";
 
-    /*
-     * FIXME: bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=477508, we
-     * shouldn't need so many events.
-     */
     private static final String TRACE_CONTENT = "<trace>" +
             "<event timestamp=\"100\" name=\"event\"><field name=\"field\" value=\"1\" type=\"int\" /></event>" +
             "<event timestamp=\"200\" name=\"event1\"><field name=\"field\" value=\"2\" type=\"int\" /></event>" +
This page took 0.032705 seconds and 5 git commands to generate.