import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Date;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
+import org.eclipse.tracecompass.tmf.core.event.aspect.ITmfEventAspect;
+import org.eclipse.tracecompass.tmf.core.event.aspect.TmfBaseAspects;
import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtEvent;
import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtTrace;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
+import com.google.common.collect.Lists;
+
/**
* Test the events parsed by a custom txt trace
*
private static final int NB_EVENTS = 10;
private CustomTxtTraceDefinition fDefinition;
+ private ITmfEventAspect<?> fTimestampAspect;
@Override
public ITmfTrace getTrace() throws IOException, TmfTraceException {
final File file = new File(TRACE_PATH);
try (BufferedWriter writer = new BufferedWriter(new FileWriter(file));) {
for (int i = 0; i < NB_EVENTS; ++i) {
- String eventStr = i + " hello world\n";
+ SimpleDateFormat f = new SimpleDateFormat(TIMESTAMP_FORMAT);
+ String eventStr = f.format(new Date(i)) + " hello world\n";
writer.write(eventStr);
int extra = i % 3;
for (int j = 0; j < extra; j++) {
}
}
}
- return new CustomTxtTrace(null, fDefinition, file.getPath(), BLOCK_SIZE);
+ ITmfTrace trace = new CustomTxtTrace(null, fDefinition, file.getPath(), BLOCK_SIZE);
+ ArrayList<@NonNull ITmfEventAspect<?>> aspects = Lists.newArrayList(trace.getEventAspects());
+ fTimestampAspect = aspects.stream().filter(aspect -> aspect.getName().equals("Timestamp")).findFirst().get();
+ return trace;
}
@Override
String name = fDefinition.definitionName;
assertEquals("Event name", name, event.getName());
assertEquals("Event name and type", event.getType().getName(), event.getName());
+ assertEquals("Timestamp", Long.toString(event.getTimestamp().toNanos()), fTimestampAspect.resolve(event));
}
@Override
private static final String ODD_EVENT = "OddName";
private static final String EVEN_EVENT = "EvenName";
private CustomTxtTraceDefinition fDefinition;
+ private ITmfEventAspect<?> fTimestampAspect;
@Override
public ITmfTrace getTrace() throws IOException, TmfTraceException {
}
}
}
- return new CustomTxtTrace(null, fDefinition, file.getPath(), BLOCK_SIZE);
+ ITmfTrace trace = new CustomTxtTrace(null, fDefinition, file.getPath(), BLOCK_SIZE);
+ ArrayList<@NonNull ITmfEventAspect<?>> aspects = Lists.newArrayList(trace.getEventAspects());
+ fTimestampAspect = aspects.stream().filter(aspect -> aspect.getName().equals("Timestamp")).findFirst().get();
+ return trace;
}
@Override
assertEquals("Event name", ODD_EVENT, event.getName());
}
assertEquals("Event name and type", event.getType().getName(), event.getName());
+ assertEquals("Timestamp", TmfBaseAspects.getTimestampAspect().resolve(event), fTimestampAspect.resolve(event));
}
@Override
import java.io.FileWriter;
import java.io.IOException;
import java.text.SimpleDateFormat;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
+import org.eclipse.tracecompass.tmf.core.event.aspect.ITmfEventAspect;
+import org.eclipse.tracecompass.tmf.core.event.aspect.TmfBaseAspects;
import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlEvent;
import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlTrace;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
+import com.google.common.collect.Lists;
+
/**
* Test the events parsed by a custom XML trace
*
private static final int NB_EVENTS = 10;
private CustomXmlTraceDefinition fDefinition;
+ private ITmfEventAspect<?> fTimestampAspect;
@Override
public ITmfTrace getTrace() throws IOException, TmfTraceException {
}
writer.write("</trace>");
}
- return new CustomXmlTrace(null, fDefinition, file.getPath(), BLOCK_SIZE);
+ ITmfTrace trace = new CustomXmlTrace(null, fDefinition, file.getPath(), BLOCK_SIZE);
+ ArrayList<@NonNull ITmfEventAspect<?>> aspects = Lists.newArrayList(trace.getEventAspects());
+ fTimestampAspect = aspects.stream().filter(aspect -> aspect.getName().equals("Timestamp")).findFirst().get();
+ return trace;
}
@Override
String name = fDefinition.definitionName;
assertEquals("Event name", name, event.getName());
assertEquals("Event name and type", event.getType().getName(), event.getName());
+ assertEquals("Timestamp", Long.toString(event.getTimestamp().toNanos()), fTimestampAspect.resolve(event));
}
@Override
private static final String ATTRIBUTE_EVENT = "AttributeName";
private static final String ELEMENT_EVENT = "ElementName";
private CustomXmlTraceDefinition fDefinition;
+ private ITmfEventAspect<?> fTimestampAspect;
@Override
public ITmfTrace getTrace() throws IOException, TmfTraceException {
}
writer.write("</trace>");
}
- return new CustomXmlTrace(null, fDefinition, file.getPath(), BLOCK_SIZE);
+ ITmfTrace trace = new CustomXmlTrace(null, fDefinition, file.getPath(), BLOCK_SIZE);
+ ArrayList<@NonNull ITmfEventAspect<?>> aspects = Lists.newArrayList(trace.getEventAspects());
+ fTimestampAspect = aspects.stream().filter(aspect -> aspect.getName().equals("Timestamp")).findFirst().get();
+ return trace;
}
@Override
assertEquals("Event name", ELEMENT_EVENT, event.getName());
}
assertEquals("Event name and type", event.getType().getName(), event.getName());
+ assertEquals("Timestamp", TmfBaseAspects.getTimestampAspect().resolve(event), fTimestampAspect.resolve(event));
}
@Override
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<CustomTxtTraceDefinitionList>
<Definition name="testtxt">
-<TimeStampOutputFormat>dd/MM/yyyy HH:mm:ss:SSS</TimeStampOutputFormat>
+<TimeStampOutputFormat>Tn</TimeStampOutputFormat>
<InputLine>
<Cardinality max="2147483647" min="0"/>
<RegEx>(\S*\s\S*) (.*\S)</RegEx>
<InputData action="2" tag="MESSAGE"/>
</InputLine>
</InputLine>
-<OutputColumn name="Time Stamp" tag="TIMESTAMP"/>
+<OutputColumn name="Timestamp" tag="TIMESTAMP"/>
<OutputColumn name="Message" tag="MESSAGE"/>
</Definition>
<Definition name="testtxtevname">
-<TimeStampOutputFormat>dd/MM/yyyy HH:mm:ss:SSS</TimeStampOutputFormat>
<InputLine>
<Cardinality max="2147483647" min="0"/>
<RegEx>(\d*) (.*\S)?</RegEx>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<CustomXMLTraceDefinitionList>
<Definition name="myxml">
-<TimeStampOutputFormat>HH:mm:ss:SSS</TimeStampOutputFormat>
+<TimeStampOutputFormat>Tn</TimeStampOutputFormat>
<InputElement name="trace">
<InputElement logentry="true" name="element">
<InputData action="0" name="Message" tag="MESSAGE"/>
<OutputColumn name="Message" tag="MESSAGE"/>
</Definition>
<Definition name="xmlevname">
-<TimeStampOutputFormat>HH:mm:ss:SSS</TimeStampOutputFormat>
<InputElement name="trace">
<InputElement eventtype="DefaultName" logentry="true" name="element">
<InputData action="0" name="Ignore" tag="IGNORE"/>