ctf: Add lost events to synthetic LTTng kernel trace generator
authorPatrick Tasse <patrick.tasse@gmail.com>
Mon, 30 Nov 2015 21:51:44 +0000 (16:51 -0500)
committerPatrick Tasse <patrick.tasse@gmail.com>
Tue, 8 Dec 2015 17:32:39 +0000 (12:32 -0500)
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 <patrick.tasse@gmail.com>
Reviewed-on: https://git.eclipse.org/r/61599
Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
ctf/org.eclipse.tracecompass.ctf.core.tests/shared/org/eclipse/tracecompass/ctf/core/tests/shared/LttngKernelTraceGenerator.java

index 705ecb3d0fce3bef9f74ca7e6195e6224bdbae0b..cffb08861c3970211c76e9bda7a181615a2de8c2 100644 (file)
@@ -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);
This page took 0.02615 seconds and 5 git commands to generate.