From: Patrick Tasse Date: Mon, 30 Nov 2015 21:51:44 +0000 (-0500) Subject: ctf: Add lost events to synthetic LTTng kernel trace generator X-Git-Url: http://git.efficios.com/?a=commitdiff_plain;h=9709972d88d1a5c0ac8be628764922bf83b6450d;p=deliverable%2Ftracecompass.git ctf: Add lost events to synthetic LTTng kernel trace generator The trace generator now creates packets with lost events pseudo-randomly approximately once out of 10 times the number of channels. The trace generator also now sets the content size of the last packet of each channel so that the total number of events (including lost events) is exactly the number of requested trace events. Change-Id: Ie804e5650d5a4186225b5dfcc75526b0fe9c2704 Signed-off-by: Patrick Tasse Reviewed-on: https://git.eclipse.org/r/61599 Reviewed-by: Matthew Khouzam --- diff --git a/ctf/org.eclipse.tracecompass.ctf.core.tests/shared/org/eclipse/tracecompass/ctf/core/tests/shared/LttngKernelTraceGenerator.java b/ctf/org.eclipse.tracecompass.ctf.core.tests/shared/org/eclipse/tracecompass/ctf/core/tests/shared/LttngKernelTraceGenerator.java index 705ecb3d0f..cffb08861c 100644 --- a/ctf/org.eclipse.tracecompass.ctf.core.tests/shared/org/eclipse/tracecompass/ctf/core/tests/shared/LttngKernelTraceGenerator.java +++ b/ctf/org.eclipse.tracecompass.ctf.core.tests/shared/org/eclipse/tracecompass/ctf/core/tests/shared/LttngKernelTraceGenerator.java @@ -276,8 +276,10 @@ public class LttngKernelTraceGenerator { } // determine the number of events per channel long evPerChan = fNbEvents / fNbChans; + final int evPerPacket = PacketWriter.CONTENT_SIZE / EventWriter.SIZE; long delta = (int) (fDuration / evPerChan); long offsetTime = 0; + Random rndLost = new Random(1337); for (int chan = 0; chan < fNbChans; chan++) { int currentSpace = 0; ByteBuffer bb = ByteBuffer.allocate(65536); @@ -291,7 +293,12 @@ public class LttngKernelTraceGenerator { } int prevPrio = 0; int prevPos = -1; + int discarded = 0; + int discardedTotal = 0; for (int eventNb = 0; eventNb < evPerChan; eventNb++) { + if (EventWriter.SIZE > currentSpace) { + eventNb += discarded; + } long ts = eventNb * delta + delta / (fNbChans + 1) * chan; int pos = rnd.nextInt((int) (fProcesses.size() * 1.5)); @@ -319,8 +326,12 @@ public class LttngKernelTraceGenerator { PacketWriter pw = new PacketWriter(bb); long tsBegin = ts; offsetTime = ts; - long tsEnd = (eventNb + (PacketWriter.SIZE / EventWriter.SIZE)) * delta + 1; - pw.writeNewHeader(tsBegin, tsEnd, chan); + int eventCount = Math.min(evPerPacket, (int) evPerChan - eventNb); + discarded = rndLost.nextInt(10 * fNbChans) == 0 ? rndLost.nextInt(evPerPacket) : 0; + discarded = Math.min(discarded, (int) evPerChan - eventNb - eventCount); + discardedTotal += discarded; + long tsEnd = (eventNb + eventCount + discarded) * delta; + pw.writeNewHeader(tsBegin, tsEnd, chan, eventCount, discardedTotal); currentSpace = PacketWriter.CONTENT_SIZE; } EventWriter ew = new EventWriter(bb); @@ -424,7 +435,7 @@ public class LttngKernelTraceGenerator { data = bb; } - public void writeNewHeader(long tsBegin, long tsEnd, int cpu) { + public void writeNewHeader(long tsBegin, long tsEnd, int cpu, int eventCount, int discarded) { final int magicLE = 0xC1FC1FC1; byte uuid[] = { 0x11, 0x11, 0x11, 0x11, @@ -448,13 +459,13 @@ public class LttngKernelTraceGenerator { data.putLong(tsEnd); // content_size 8 - data.putLong((CONTENT_SIZE / EventWriter.SIZE * EventWriter.SIZE + HEADER_SIZE) * 8); + data.putLong((eventCount * EventWriter.SIZE + HEADER_SIZE)* 8); // packet_size 8 data.putLong((SIZE) * 8); // events_discarded 4 - data.putInt(0); + data.putInt(discarded); // cpu_id 4 data.putInt(cpu);