Mercurial > stress-tester
changeset 1190:03ca923231c5
PcapSessionEventSourceMetric.loop
author | Devel 2 |
---|---|
date | Thu, 18 Jun 2020 11:01:57 +0200 |
parents | 7f70d5ddbde9 |
children | 992a973b37a3 |
files | stress-tester/src/main/java/com/passus/st/source/PcapSessionEventSource.java stress-tester/src/main/java/com/passus/st/source/PcapSessionEventSourceMetric.java |
diffstat | 2 files changed, 25 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/source/PcapSessionEventSource.java Thu Jun 18 11:00:51 2020 +0200 +++ b/stress-tester/src/main/java/com/passus/st/source/PcapSessionEventSource.java Thu Jun 18 11:01:57 2020 +0200 @@ -35,12 +35,11 @@ import com.passus.st.reader.pcap.PcapDataBlock; import com.passus.st.reader.pcap.PcapDataBlockReader; import com.passus.st.reader.pcapng.PcapNgReader; -import com.passus.st.validation.FileValidator; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import java.io.File; import java.io.IOException; -import java.io.File; import java.util.*; import static com.passus.config.schema.ConfigurationSchemaBuilder.*; @@ -338,6 +337,13 @@ try { String sourceName = PcapSessionEventSource.this.getName(); int loopNum = 0; + + if (collectMetric) { + synchronized (metric) { + metric.loop(loopNum + 1); + } + } + while (working) { PcapDataBlock dataBlock; while ((dataBlock = reader.read()) != null) { @@ -372,6 +378,13 @@ } loopNum++; + + if (collectMetric) { + synchronized (metric) { + metric.loop(loopNum + 1); + } + } + dataBlockHandler.nextLoop(); if (loopDelay > 0) { sleepFor(loopDelay);
--- a/stress-tester/src/main/java/com/passus/st/source/PcapSessionEventSourceMetric.java Thu Jun 18 11:00:51 2020 +0200 +++ b/stress-tester/src/main/java/com/passus/st/source/PcapSessionEventSourceMetric.java Thu Jun 18 11:01:57 2020 +0200 @@ -2,16 +2,16 @@ import com.passus.commons.Assert; import com.passus.commons.metric.Metric; +import org.apache.commons.lang3.mutable.MutableInt; + import java.io.Serializable; import java.util.Collections; import java.util.LinkedHashMap; import java.util.Map; import java.util.Set; import java.util.concurrent.atomic.AtomicInteger; -import org.apache.commons.lang3.mutable.MutableInt; /** - * * @author Mirosław Hawrot */ public class PcapSessionEventSourceMetric implements Metric { @@ -27,9 +27,11 @@ private final AtomicInteger events = new AtomicInteger(); private final MutableInt eventsEnqueued = new MutableInt(); private final MutableInt eventsDequeued = new MutableInt(); + private final MutableInt loop = new MutableInt(); private final Map<String, Serializable> attrs = new LinkedHashMap<>(); + private boolean active; public PcapSessionEventSourceMetric() { @@ -46,6 +48,7 @@ attrs.put("events", events); attrs.put("eventsEnqueued", eventsEnqueued); attrs.put("eventsDequeued", eventsDequeued); + attrs.put("loop", loop); } @Override @@ -98,6 +101,10 @@ eventsDequeued.increment(); } + public void loop(int loop) { + this.loop.setValue(loop); + } + @Override public boolean hasAttribute(String name) { return attrs.containsKey(name); @@ -143,5 +150,6 @@ events.addAndGet(pcapMetric.events.get()); eventsEnqueued.add(pcapMetric.eventsEnqueued); eventsDequeued.add(pcapMetric.eventsDequeued); + loop.setValue(pcapMetric.loop); } }