Search in sources :

Example 1 with CtfTmfTrace

use of org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace in project tracecompass by tracecompass.

the class ExperimentBenchmark method init.

/**
 * Initialization
 *
 * @param maxTraces
 *            maximum number of traces to open
 */
private void init(int maxTraces) {
    try {
        File parentDir = new File(TRACES_ROOT_PATH);
        File[] traceFiles = parentDir.listFiles();
        ITmfTrace[] traces = new CtfTmfTrace[Math.min(maxTraces, traceFiles.length)];
        for (int i = 0; i < traces.length; i++) {
            traces[i] = new CtfTmfTrace();
        }
        int j = 0;
        for (int i = 0; i < (traces.length) && (j < traces.length); i++) {
            String absolutePath = traceFiles[j].getAbsolutePath();
            if (traces[i].validate(null, absolutePath).isOK()) {
                traces[i].initTrace(null, absolutePath, ITmfEvent.class);
            } else {
                i--;
            }
            j++;
        }
        fExperiment = new TmfExperimentStub("MegaExperiment", traces, BLOCK_SIZE);
        if (traces[traces.length - 1].getPath() == null) {
            throw new TmfTraceException("Insufficient valid traces in directory");
        }
    } catch (TmfTraceException e) {
        System.out.println(e.getMessage());
    }
}
Also used : ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) TmfTraceException(org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException) TmfExperimentStub(org.eclipse.tracecompass.tmf.tests.stubs.trace.TmfExperimentStub) File(java.io.File) CtfTmfTrace(org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace)

Example 2 with CtfTmfTrace

use of org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace in project tracecompass by tracecompass.

the class CtfTmfCpuAspectTest method setUp.

/**
 * Create 3 event definitions and a trace, the event definitions should
 * stress the CPU aspect.
 *
 * @throws CTFException
 *             Won't happen, if the buffer isn't big enough throw an
 *             exception
 */
@Before
public void setUp() throws CTFException {
    fTrace = new CtfTmfTrace();
    int capacity = 2048;
    ByteBuffer bb = ByteBuffer.allocateDirect(capacity);
    StructDeclaration sDec = new StructDeclaration(1l);
    IntegerDeclaration intDec = IntegerDeclaration.INT_8_DECL;
    sDec.addField("cpu_id", intDec);
    sDec.addField("CpuId", intDec);
    /* Set cpu_id = 2 */
    bb.put((byte) 2);
    /* Set CpuId = 3 */
    bb.put((byte) 3);
    StructDefinition def = sDec.createDefinition(null, ROOT, new BitBuffer(bb));
    EventDeclaration dec = new EventDeclaration();
    dec.setName("hi");
    /*
         * CPU in the stream == undefined cpu, has a cpu_id field set to 2,
         * resolve to 2
         */
    fEvents.add(new EventDefinition(dec, IEventDefinition.UNKNOWN_CPU, 0, null, null, null, null, def, null));
    /*
         * CPU in the stream == 3, has a cpu_id field set to 2, stream take
         * priority, resolve to 3
         */
    fEvents.add(new EventDefinition(dec, 3, 0, null, null, null, null, def, null));
    /*
         * CPU in the stream == undefined cpu, has a context with cpu_id,
         * unsupported, resolves to null
         */
    fEvents.add(new EventDefinition(dec, IEventDefinition.UNKNOWN_CPU, 0, null, null, null, def, null, null));
    /* CPU in the stream == undefined cpu, has a no fields */
    fEvents.add(new EventDefinition(dec, IEventDefinition.UNKNOWN_CPU, 0, null, null, null, null, null, null));
    /* CPU in the stream == 6, has a no fields */
    fEvents.add(new EventDefinition(dec, 6, 0, null, null, null, null, null, null));
}
Also used : EventDeclaration(org.eclipse.tracecompass.internal.ctf.core.event.EventDeclaration) StructDefinition(org.eclipse.tracecompass.ctf.core.event.types.StructDefinition) IntegerDeclaration(org.eclipse.tracecompass.ctf.core.event.types.IntegerDeclaration) StructDeclaration(org.eclipse.tracecompass.ctf.core.event.types.StructDeclaration) EventDefinition(org.eclipse.tracecompass.internal.ctf.core.event.EventDefinition) IEventDefinition(org.eclipse.tracecompass.ctf.core.event.IEventDefinition) ByteBuffer(java.nio.ByteBuffer) CtfTmfTrace(org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace) BitBuffer(org.eclipse.tracecompass.ctf.core.event.io.BitBuffer) Before(org.junit.Before)

Example 3 with CtfTmfTrace

use of org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace in project tracecompass by tracecompass.

the class CtfTmfCpuAspectTest method test.

/**
 * Test the cpu aspect
 */
@Test
public void test() {
    CtfCpuAspect fixture = new CtfCpuAspect();
    CtfTmfTrace trace = fTrace;
    assertNotNull(trace);
    CtfTmfEventFactory fabrica = CtfTmfEventFactory.instance();
    /*
         * Evaluate field, no stream
         */
    CtfTmfEvent e = fabrica.createEvent(trace, fEvents.get(0), "");
    assertEquals(Integer.valueOf(2), fixture.resolve(e));
    /*
         * Evaluate stream and field
         */
    e = fabrica.createEvent(trace, fEvents.get(1), "");
    assertEquals(Integer.valueOf(3), fixture.resolve(e));
    /*
         * Evaluate context
         */
    e = fabrica.createEvent(trace, fEvents.get(2), "");
    assertNull(fixture.resolve(e));
    /*
         * Evaluate an empty event
         */
    e = fabrica.createEvent(trace, fEvents.get(3), "");
    assertNull(fixture.resolve(e));
    /*
         * Evaluate stream and no field, default LTTng behaviour
         */
    e = fabrica.createEvent(trace, fEvents.get(4), "");
    assertEquals(Integer.valueOf(6), fixture.resolve(e));
    /*
         * Evaluate non-ctf event
         */
    assertNull(fixture.resolve(new TmfEvent(trace, 0, TmfTimestamp.BIG_BANG, null, null)));
}
Also used : CtfTmfEvent(org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEvent) TmfEvent(org.eclipse.tracecompass.tmf.core.event.TmfEvent) CtfTmfEvent(org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEvent) CtfCpuAspect(org.eclipse.tracecompass.tmf.ctf.core.event.aspect.CtfCpuAspect) CtfTmfEventFactory(org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEventFactory) CtfTmfTrace(org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace) Test(org.junit.Test)

Example 4 with CtfTmfTrace

use of org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace in project tracecompass by tracecompass.

the class CtfTmfLostEventsTest method testLostEventWithTransform.

/**
 * Test getting a lost event from a trace that has a timestamp transform.
 */
@Test
public void testLostEventWithTransform() {
    CtfTmfTrace trace = CtfTmfTestTraceUtils.getTrace(testTrace);
    long offset = 1234567890L;
    trace.setTimestampTransform(TimestampTransformFactory.createWithOffset(offset));
    trace.indexTrace(true);
    final long rank = 190;
    final ITmfTimestamp start = TmfTimestamp.fromNanos(1376592664828900165L + offset);
    final ITmfTimestamp end = TmfTimestamp.fromNanos(1376592664828900165L + 502911L + offset);
    final long nbLost = 859;
    ITmfContext context = trace.seekEvent(rank);
    final CtfTmfEvent ev = trace.getNext(context);
    context.dispose();
    assertTrue(ev instanceof ITmfLostEvent);
    ITmfLostEvent event = (ITmfLostEvent) ev;
    assertEquals(start, event.getTimestamp());
    assertEquals(start, event.getTimeRange().getStartTime());
    assertEquals(end, event.getTimeRange().getEndTime());
    assertEquals(nbLost, event.getNbLostEvents());
    trace.setTimestampTransform(null);
    trace.dispose();
}
Also used : ITmfContext(org.eclipse.tracecompass.tmf.core.trace.ITmfContext) CtfTmfEvent(org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEvent) ITmfTimestamp(org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp) ITmfLostEvent(org.eclipse.tracecompass.tmf.core.event.ITmfLostEvent) CtfTmfTrace(org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace) Test(org.junit.Test)

Example 5 with CtfTmfTrace

use of org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace in project tracecompass by tracecompass.

the class StatisticsAnalysisBenchmark method runTest.

private static void runTest(CtfTestTrace testTrace, String testName, Map<String, Long> testCases) {
    Performance perf = Performance.getDefault();
    PerformanceMeter pm = perf.createPerformanceMeter(TEST_ID + '#' + testName);
    perf.tagAsSummary(pm, "Statistics Analysis: " + testName, Dimension.CPU_TIME);
    if (testTrace == CtfTestTrace.DJANGO_CLIENT || testTrace == CtfTestTrace.DJANGO_HTTPD) {
        /* Do not show all traces in the global summary */
        perf.tagAsGlobalSummary(pm, "Statistics Analysis: " + testName, Dimension.CPU_TIME);
    }
    for (int i = 0; i < LOOP_COUNT; i++) {
        LttngKernelTrace trace = null;
        TmfStatisticsModule module = null;
        try {
            trace = new LttngKernelTrace();
            module = new TmfStatisticsModule();
            module.setId("test");
            // TODO Allow the utility method to return a LttngKernelTrace directly
            CtfTmfTrace ctfTmfTrace = CtfTmfTestTraceUtils.getTrace(testTrace);
            trace.initTrace(null, ctfTmfTrace.getPath(), CtfTmfEvent.class);
            module.setTrace(trace);
            pm.start();
            TmfTestHelper.executeAnalysis(module);
            pm.stop();
            ITmfStatistics stats = module.getStatistics();
            if (stats == null) {
                throw new IllegalStateException();
            }
            Map<String, Long> map = stats.getEventTypesTotal();
            /*
                 * Test each of the entries
                 */
            try {
                for (Entry<String, Long> entry : testCases.entrySet()) {
                    Long value = map.get(entry.getKey());
                    assertNotNull(value);
                    assertTrue(value.equals(entry.getValue()));
                }
            } catch (NullPointerException e) {
                fail(e.getMessage());
            }
            /*
                 * Delete the supplementary files, so that the next iteration
                 * rebuilds the state system.
                 */
            File suppDir = new File(TmfTraceManager.getSupplementaryFileDir(trace));
            for (File file : suppDir.listFiles()) {
                file.delete();
            }
        } catch (TmfAnalysisException | TmfTraceException e) {
            fail(e.getMessage());
        } finally {
            if (module != null) {
                module.dispose();
            }
            if (trace != null) {
                trace.dispose();
            }
        }
    }
    pm.commit();
    CtfTmfTestTraceUtils.dispose(testTrace);
}
Also used : LttngKernelTrace(org.eclipse.tracecompass.lttng2.kernel.core.trace.LttngKernelTrace) TmfStatisticsModule(org.eclipse.tracecompass.tmf.core.statistics.TmfStatisticsModule) ITmfStatistics(org.eclipse.tracecompass.tmf.core.statistics.ITmfStatistics) TmfAnalysisException(org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException) TmfTraceException(org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException) PerformanceMeter(org.eclipse.test.performance.PerformanceMeter) Performance(org.eclipse.test.performance.Performance) File(java.io.File) CtfTmfTrace(org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace)

Aggregations

CtfTmfTrace (org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace)42 Test (org.junit.Test)28 File (java.io.File)10 ITmfTrace (org.eclipse.tracecompass.tmf.core.trace.ITmfTrace)10 TmfExperiment (org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment)7 CtfTmfEvent (org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEvent)6 TmfTraceException (org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException)5 ITmfTimestamp (org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp)5 TmfAnalysisException (org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException)4 Performance (org.eclipse.test.performance.Performance)3 PerformanceMeter (org.eclipse.test.performance.PerformanceMeter)3 CtfIterator (org.eclipse.tracecompass.internal.tmf.ctf.core.trace.iterator.CtfIterator)3 BeforeClass (org.junit.BeforeClass)3 Path (java.nio.file.Path)2 IStatus (org.eclipse.core.runtime.IStatus)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 SWTWorkbenchBot (org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot)2 KernelAnalysisModule (org.eclipse.tracecompass.analysis.os.linux.core.kernel.KernelAnalysisModule)2 ITmfStateSystem (org.eclipse.tracecompass.statesystem.core.ITmfStateSystem)2 CtfTestTrace (org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace)2