Metadata is now autoclosable so the trace doesn't have to be.
Change-Id: I376c21f0888d57c55f41e83a15762c786a982b06
Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/36367
Tested-by: Hudson CI
Reviewed-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
for (int loop = 0; loop < LOOP_COUNT; loop++) {
pm.start();
- try (CTFTrace trace = testTrace.getTrace();
- CTFTraceReader traceReader = new CTFTraceReader(trace);) {
+ try {
+ CTFTrace trace = testTrace.getTrace();
+ try (CTFTraceReader traceReader = new CTFTraceReader(trace);) {
- while (traceReader.hasMoreEvents()) {
- EventDefinition ed = traceReader.getCurrentEventDef();
- /* Do something with the event */
- ed.getCPU();
- traceReader.advance();
+ while (traceReader.hasMoreEvents()) {
+ EventDefinition ed = traceReader.getCurrentEventDef();
+ /* Do something with the event */
+ ed.getCPU();
+ traceReader.advance();
+ }
}
-
} catch (CTFReaderException e) {
/* Should not happen if assumeTrue() passed above */
fail("Test failed at iteration " + loop + ':' + e.getMessage());
/**
* Tests for performance regressions of the ctf reader. It only tests the ctf
- * reader, not tmf.
- * <br>
+ * reader, not tmf. <br>
* This test runs in 3 passes.
* <ul>
* <li>first it opens a trace</li>
* <li>then it reads the trace completely</li>
- * <li>then it randomly (seeded) seeks NB_SEEKS locations in the trace and reads one
- * event at each position.</li>
+ * <li>then it randomly (seeded) seeks NB_SEEKS locations in the trace and reads
+ * one event at each position.</li>
* </ul>
*
* @author Matthew Khouzam
/**
* Run the benchmark scenario for the trace "kernel"
+ *
+ * @throws CTFReaderException
+ * Should not happen
*/
@Test
- public void testKernelTrace() {
+ public void testKernelTrace() throws CTFReaderException {
readAndSeekTrace(CtfTestTrace.KERNEL, "trace-kernel", true);
}
- private static void readAndSeekTrace(CtfTestTrace testTrace, String testName, boolean inGlobalSummary) {
+ private static void readAndSeekTrace(CtfTestTrace testTrace, String testName, boolean inGlobalSummary) throws CTFReaderException {
assumeTrue(testTrace.exists());
Performance perf = Performance.getDefault();
}
for (int loop = 0; loop < LOOP_COUNT; loop++) {
- try (CTFTrace trace = testTrace.getTrace();
- CTFTraceReader traceReader = new CTFTraceReader(trace);) {
+ CTFTrace trace = testTrace.getTrace();
+ try (CTFTraceReader traceReader = new CTFTraceReader(trace);) {
/* Read the whole trace to find out the start and end times */
EventDefinition firstEvent = traceReader.getCurrentEventDef();
*/
@Test
public void testTrace() {
- try (/* Instantiate the trace (which implies parsing the metadata) */
- CTFTrace trace = new CTFTrace(fTracePath);
- /* Read the trace until the end */
- CTFTraceReader reader = new CTFTraceReader(trace);) {
-
- reader.getCurrentEventDef();
- while (reader.advance()) {
- assertNotNull(reader.getCurrentEventDef());
- }
+ try {
+ /* Instantiate the trace (which implies parsing the metadata) */
+ CTFTrace trace = new CTFTrace(fTracePath);
+ /* Read the trace until the end */
+ try (CTFTraceReader reader = new CTFTraceReader(trace);) {
+
+ reader.getCurrentEventDef();
+ while (reader.advance()) {
+ assertNotNull(reader.getCurrentEventDef());
+ }
- checkIfWeShoudlSucceed();
+ checkIfWeShoudlSucceed();
+ }
} catch (CTFReaderException e) {
checkIfWeShouldFail(e);
} catch (OutOfMemoryError e) {
/*******************************************************************************
- * Copyright (c) 2013 Ericsson
+ * Copyright (c) 2013, 2014 Ericsson
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
*/
@Test
public void testStream() throws CTFReaderException {
- try (CTFTrace trace = testTrace.getTrace()) {
- CTFStream result = new CTFStream(trace);
- assertNotNull(result);
- }
+ CTFTrace trace = testTrace.getTrace();
+ CTFStream result = new CTFStream(trace);
+ assertNotNull(result);
}
/**
*/
@Test
public void testGetTrace() {
- try (CTFTrace result = fixture.getTrace();) {
- assertNotNull(result);
- }
+ CTFTrace result = fixture.getTrace();
+ assertNotNull(result);
}
/**
/*******************************************************************************
- * Copyright (c) 2013 Ericsson
+ * Copyright (c) 2013, 2014 Ericsson
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
*/
@Test
public void testOpen_existing() throws CTFReaderException {
- try (CTFTrace trace = testTrace.getTrace();
- CTFTraceReader result = new CTFTraceReader(trace);) {
+ CTFTrace trace = testTrace.getTrace();
+ try (CTFTraceReader result = new CTFTraceReader(trace);) {
assertNotNull(result);
}
}
*/
@Test(expected = org.eclipse.tracecompass.ctf.core.trace.CTFReaderException.class)
public void testOpen_nonexisting() throws CTFReaderException {
- try (CTFTrace trace = new CTFTrace("badfile.bad");
- CTFTraceReader result = new CTFTraceReader(trace);) {
+ CTFTrace trace = new CTFTrace("badfile.bad");
+ try (CTFTraceReader result = new CTFTraceReader(trace);) {
assertNotNull(result);
}
}
*/
@Test(expected = org.eclipse.tracecompass.ctf.core.trace.CTFReaderException.class)
public void testOpen_invalid() throws CTFReaderException {
- try (CTFTrace trace = new CTFTrace("");
- CTFTraceReader result = new CTFTraceReader(trace);) {
+ CTFTrace trace = new CTFTrace("");
+ try (CTFTraceReader result = new CTFTraceReader(trace);) {
assertNotNull(result);
}
}
/**
* Run the boolean advance() method test. Test advancing normally.
- * @throws CTFReaderException error
+ *
+ * @throws CTFReaderException
+ * error
*/
@Test
public void testAdvance_normal() throws CTFReaderException {
/**
* Run the boolean advance() method test. Test advancing when we're at the
* end, so we expect that there is no more events.
- * @throws CTFReaderException error
+ *
+ * @throws CTFReaderException
+ * error
*/
@Test
public void testAdvance_end() throws CTFReaderException {
/**
* Run the CTFTraceReader copy constructor test.
- * @throws CTFReaderException error
+ *
+ * @throws CTFReaderException
+ * error
*/
@Test
public void testCopyFrom() throws CTFReaderException {
/**
* Run the getCurrentEventDef() method test. Get the last event's
* definition.
- * @throws CTFReaderException error
+ *
+ * @throws CTFReaderException
+ * error
*/
@Test
public void testGetCurrentEventDef_last() throws CTFReaderException {
/**
* Run the void goToLastEvent() method test.
- * @throws CTFReaderException error
+ *
+ * @throws CTFReaderException
+ * error
*/
@Test
public void testGoToLastEvent() throws CTFReaderException {
/**
* Run the void printStats() method test with no 'width' parameter.
- * @throws CTFReaderException error
+ *
+ * @throws CTFReaderException
+ * error
*/
@Test
public void testPrintStats_noparam() throws CTFReaderException {
/**
* Run the void printStats(int) method test with width = 0.
- * @throws CTFReaderException error
+ *
+ * @throws CTFReaderException
+ * error
*/
@Test
public void testPrintStats_width0() throws CTFReaderException {
/**
* Run the void printStats(int) method test with width = 1.
- * @throws CTFReaderException error
+ *
+ * @throws CTFReaderException
+ * error
*/
@Test
public void testPrintStats_width1() throws CTFReaderException {
/**
* Run the void printStats(int) method test with width = 2.
- * @throws CTFReaderException error
+ *
+ * @throws CTFReaderException
+ * error
*/
@Test
public void testPrintStats_width2() throws CTFReaderException {
/**
* Run the void printStats(int) method test with width = 10.
- * @throws CTFReaderException error
+ *
+ * @throws CTFReaderException
+ * error
*/
@Test
public void testPrintStats_width10() throws CTFReaderException {
/**
* Run the void printStats(int) method test with width = 100.
- * @throws CTFReaderException error
+ *
+ * @throws CTFReaderException
+ * error
*/
@Test
public void testPrintStats_100() throws CTFReaderException {
/**
* Run the boolean seek(long) method test.
- * @throws CTFReaderException error
+ *
+ * @throws CTFReaderException
+ * error
*/
@Test
public void testSeek() throws CTFReaderException {
assertTrue(result);
}
-
-
/**
* @return
*/
*/
@Test
public void testOpen_existing() {
- try (CTFTrace result = testTrace.getTraceFromFile();) {
+ try {
+ CTFTrace result = testTrace.getTraceFromFile();
assertNotNull(result.getUUID());
} catch (CTFReaderException e) {
fail();
@Test(expected = org.eclipse.tracecompass.ctf.core.trace.CTFReaderException.class)
public void testOpen_invalid() throws CTFReaderException {
File path = new File("");
- try (CTFTrace result = new CTFTrace(path);) {
- assertNotNull(result);
- }
+ CTFTrace result = new CTFTrace(path);
+ assertNotNull(result);
}
/**
*/
@Test
public void testPacketHeaderIsSet_invalid() {
- try (CTFTrace fixture2 = testTrace.getTraceFromFile();){
+ try {
+ CTFTrace fixture2 = testTrace.getTraceFromFile();
fixture2.setMinor(1L);
fixture2.setUUID(UUID.randomUUID());
- fixture2.setPacketHeader((StructDeclaration) null); /* it's null here! */
+ /*
+ * it's null here!
+ */
+ fixture2.setPacketHeader((StructDeclaration) null);
fixture2.setMajor(1L);
fixture2.setByteOrder(ByteOrder.BIG_ENDIAN);
/**
* Test for getCallsite(eventName, ip)
- * @throws CTFReaderException not expected
+ *
+ * @throws CTFReaderException
+ * not expected
*/
@Test
public void callsitePosition() throws CTFReaderException {
long ip1 = 2;
long ip2 = 5;
long ip3 = 7;
- try (CTFTrace callsiteTest = testTrace.getTraceFromFile()) {
- callsiteTest.addCallsite("testEvent", null, ip1, null, 23);
- callsiteTest.addCallsite("testEvent", null, ip2, null, 50);
- callsiteTest.addCallsite("testEvent", null, ip3, null, 15);
-
- assertEquals(2, (callsiteTest.getCallsite("testEvent", 1)).getIp());
- assertEquals(2, (callsiteTest.getCallsite("testEvent", 2)).getIp());
- assertEquals(5, (callsiteTest.getCallsite("testEvent", 3)).getIp());
- assertEquals(5, (callsiteTest.getCallsite("testEvent", 5)).getIp());
- assertEquals(7, (callsiteTest.getCallsite("testEvent", 6)).getIp());
- assertEquals(7, (callsiteTest.getCallsite("testEvent", 7)).getIp());
- assertEquals(7, (callsiteTest.getCallsite("testEvent", 8)).getIp());
- }
+ CTFTrace callsiteTest = testTrace.getTraceFromFile();
+ callsiteTest.addCallsite("testEvent", null, ip1, null, 23);
+ callsiteTest.addCallsite("testEvent", null, ip2, null, 50);
+ callsiteTest.addCallsite("testEvent", null, ip3, null, 15);
+
+ assertEquals(2, (callsiteTest.getCallsite("testEvent", 1)).getIp());
+ assertEquals(2, (callsiteTest.getCallsite("testEvent", 2)).getIp());
+ assertEquals(5, (callsiteTest.getCallsite("testEvent", 3)).getIp());
+ assertEquals(5, (callsiteTest.getCallsite("testEvent", 5)).getIp());
+ assertEquals(7, (callsiteTest.getCallsite("testEvent", 6)).getIp());
+ assertEquals(7, (callsiteTest.getCallsite("testEvent", 7)).getIp());
+ assertEquals(7, (callsiteTest.getCallsite("testEvent", 8)).getIp());
}
-
}
import org.eclipse.tracecompass.ctf.core.trace.CTFTrace;
import org.eclipse.tracecompass.internal.ctf.core.event.EventDeclaration;
import org.eclipse.tracecompass.internal.ctf.core.event.metadata.IOStructGen;
-import org.junit.After;
import org.junit.Test;
/**
}
- /**
- * Close trace
- */
- @After
- public void tearDown(){
- trace.close();
- }
-
/**
* Simple test (only the minimum)
*
@Test
public void testStreamTextMD() throws CTFReaderException {
- try (CTFTrace trace = testSingleFragment();) {
- fixture.parseTextFragment(mdSecond);
- final List<IEventDeclaration> eventDeclarations = new ArrayList<>(trace.getEventDeclarations(0L));
- assertEquals(2, eventDeclarations.size());
- assertEquals("bozo_the_clown", eventDeclarations.get(1).getName());
- }
+ CTFTrace trace = testSingleFragment();
+ fixture.parseTextFragment(mdSecond);
+ final List<IEventDeclaration> eventDeclarations = new ArrayList<>(trace.getEventDeclarations(0L));
+ assertEquals(2, eventDeclarations.size());
+ assertEquals("bozo_the_clown", eventDeclarations.get(1).getName());
}
/**
/*******************************************************************************
- * Copyright (c) 2013 Ericsson
+ * Copyright (c) 2013, 2014 Ericsson
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
*/
@Test
public void testGetId() {
- assertEquals(1,fixture.id());
+ assertEquals(1, fixture.id());
}
/**
*/
@Test
public void testEventDefinition() throws CTFReaderException {
- try (CTFTrace trace = testTrace.getTrace();) {
- EventDefinition ed = null;
- try (CTFTraceReader tr = new CTFTraceReader(trace);) {
- tr.advance();
- ed = tr.getCurrentEventDef();
- }
-
- assertNotNull(ed);
- assertNotNull(ed.getScopePath());
- assertNotNull(ed.getDeclaration());
- assertNotNull(ed.getFields());
- assertNull(ed.getContext());
- assertNotNull(ed.getPacketContext());
- assertNotNull(ed.getCPU());
- assertNotNull(ed.getStreamInputReader());
- assertNull(ed.lookupDefinition("context"));
- assertNotNull(ed.lookupDefinition("fields"));
- assertNull(ed.lookupDefinition("other"));
- assertNotNull(ed.toString());
+ CTFTrace trace = testTrace.getTrace();
+ EventDefinition ed = null;
+ try (CTFTraceReader tr = new CTFTraceReader(trace);) {
+ tr.advance();
+ ed = tr.getCurrentEventDef();
}
+
+ assertNotNull(ed);
+ assertNotNull(ed.getScopePath());
+ assertNotNull(ed.getDeclaration());
+ assertNotNull(ed.getFields());
+ assertNull(ed.getContext());
+ assertNotNull(ed.getPacketContext());
+ assertNotNull(ed.getCPU());
+ assertNotNull(ed.getStreamInputReader());
+ assertNull(ed.lookupDefinition("context"));
+ assertNotNull(ed.lookupDefinition("fields"));
+ assertNull(ed.lookupDefinition("other"));
+ assertNotNull(ed.toString());
}
EventDeclaration e1;
EventDeclaration e2;
-
@Test
- public void testEquals1(){
+ public void testEquals1() {
e1 = new EventDeclaration();
assertFalse(e1.equals(null));
}
@Test
- public void testEquals2(){
+ public void testEquals2() {
e1 = EventDeclaration.getLostEventDeclaration();
assertFalse(e1.equals(new Long(23L)));
}
@Test
- public void testEquals3(){
+ public void testEquals3() {
e1 = EventDeclaration.getLostEventDeclaration();
- assertEquals(e1,e1);
+ assertEquals(e1, e1);
}
@Test
- public void testEquals4(){
+ public void testEquals4() {
e1 = EventDeclaration.getLostEventDeclaration();
e2 = EventDeclaration.getLostEventDeclaration();
- assertEquals(e1,e2);
+ assertEquals(e1, e2);
}
@Test
- public void testEquals5(){
+ public void testEquals5() {
e1 = EventDeclaration.getLostEventDeclaration();
e2 = new EventDeclaration();
assertFalse(e1.equals(e2));
* @author Matthew Khouzam
* @version $Revision: 1.0 $
*/
-public class CTFTrace implements IDefinitionScope, AutoCloseable {
+public class CTFTrace implements IDefinitionScope {
@Override
public String toString() {
}
}
- /**
- * Dispose the trace
- *
- * FIXME Not needed anymore, class doesn't need to be AutoCloseable.
- *
- * @since 3.0
- */
- @Override
- public void close() {
- }
-
// ------------------------------------------------------------------------
// Getters/Setters/Predicates
// ------------------------------------------------------------------------
* Make sure the trace is openable as a CTF trace. We do this here
* instead of calling super.validate() to keep the reference to "temp".
*/
- try (CTFTrace temp = new CTFTrace(path);) {
+ try {
+ CTFTrace temp = new CTFTrace(path);
/* Make sure the domain is "kernel" in the trace's env vars */
String dom = temp.getEnvironment().get("domain"); //$NON-NLS-1$
if (dom != null && dom.startsWith("\"kernel")) { //$NON-NLS-1$
* CTF trace in the "ust" domain.
*/
@Override
- public IStatus validate(final IProject project, final String path) {
- try (CTFTrace temp = new CTFTrace(path);) {
+ public IStatus validate(final IProject project, final String path) {
+ try {
+ CTFTrace temp = new CTFTrace(path);
/* Make sure the domain is "ust" in the trace's env vars */
String dom = temp.getEnvironment().get("domain"); //$NON-NLS-1$
if (dom != null && dom.equals("\"ust\"")) { //$NON-NLS-1$
public synchronized void dispose() {
fIteratorManager.dispose();
if (fTrace != null) {
- fTrace.close();
fTrace = null;
}
super.dispose();
@Override
public IStatus validate(final IProject project, final String path) {
IStatus status = new TraceValidationStatus(CONFIDENCE, Activator.PLUGIN_ID);
- try (final CTFTrace temp = new CTFTrace(path);) {
+ try {
+ final CTFTrace temp = new CTFTrace(path);
if (!temp.majorIsSet()) {
status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.CtfTmfTrace_MajorNotSet);
} else {
sessionName = getResource().getPersistentProperty(CtfConstants.LIVE_SESSION_NAME);
} catch (CoreException e) {
Activator.getDefault().logError(e.getMessage(), e);
- // Something happened to the resource, assume we won't get any more data from it
+ // Something happened to the resource, assume we won't get any more
+ // data from it
return true;
}
return host == null || port == null || sessionName == null;