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());
}
}
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));
}
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)));
}
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();
}
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);
}
Aggregations