diff --git a/src/explorviz/live_trace_processing/filter/reduction/AbstractReductionFilter.java b/src/explorviz/live_trace_processing/filter/reduction/AbstractReductionFilter.java new file mode 100644 index 0000000000000000000000000000000000000000..f12f7dc1487939a896677788864f8c9304809456 --- /dev/null +++ b/src/explorviz/live_trace_processing/filter/reduction/AbstractReductionFilter.java @@ -0,0 +1,45 @@ +package explorviz.live_trace_processing.filter.reduction; + +import explorviz.live_trace_processing.Constants; +import explorviz.live_trace_processing.filter.AbstractFilter; +import explorviz.live_trace_processing.filter.IPipeReceiver; +import explorviz.live_trace_processing.record.IRecord; +import explorviz.live_trace_processing.record.misc.TerminateRecord; +import explorviz.live_trace_processing.record.misc.TimedPeriodRecord; +import explorviz.live_trace_processing.record.trace.Trace; + +public abstract class AbstractReductionFilter extends AbstractFilter implements ITraceReduction { + + public AbstractReductionFilter(final IPipeReceiver receiver, final String counterString) { + super(receiver, Constants.TRACE_SUMMARIZATION_DISRUPTOR_SIZE, + Constants.TRACE_SUMMARIZATION_OUTPUT_BUFFER_SIZE, counterString); + } + + public Trace testReduction(final Trace trace) { + return reduceTrace(trace); + } + + @Override + protected void processRecord(final IRecord record) { + if (record instanceof Trace) { + final Trace trace = (Trace) record; + if (trace.isValid()) { + final Trace reducedTrace = reduceTrace(trace); + deliver(reducedTrace); + } else { + deliver(trace); + } + } else if (record instanceof TimedPeriodRecord) { + periodicFlush(record); + deliver(record); + } else if (record instanceof TerminateRecord) { + System.out.println("terminate..."); + deliver(record); + } else { + deliver(record); + } + } + + protected abstract Trace reduceTrace(Trace trace); + +} diff --git a/src/explorviz/live_trace_processing/filter/reduction/DummyFilter.java b/src/explorviz/live_trace_processing/filter/reduction/DummyFilter.java new file mode 100644 index 0000000000000000000000000000000000000000..bedbea314c895b89605b81bec3ce02a5473a730b --- /dev/null +++ b/src/explorviz/live_trace_processing/filter/reduction/DummyFilter.java @@ -0,0 +1,17 @@ +package explorviz.live_trace_processing.filter.reduction; + +import explorviz.live_trace_processing.filter.IPipeReceiver; +import explorviz.live_trace_processing.record.trace.Trace; + +public class DummyFilter extends AbstractReductionFilter { + + public DummyFilter(final IPipeReceiver receiver) { + super(receiver, "dummy"); + } + + @Override + protected Trace reduceTrace(final Trace trace) { + return trace; + } + +} diff --git a/src/explorviz/live_trace_processing/filter/reduction/evaluation/ad_hoc/FragmentationFilter.java b/src/explorviz/live_trace_processing/filter/reduction/evaluation/ad_hoc/FragmentationFilter.java new file mode 100644 index 0000000000000000000000000000000000000000..ec176a5cafc975496ec9c1e17dcb7c94578ab5ff --- /dev/null +++ b/src/explorviz/live_trace_processing/filter/reduction/evaluation/ad_hoc/FragmentationFilter.java @@ -0,0 +1,51 @@ +package explorviz.live_trace_processing.filter.reduction.evaluation.ad_hoc; + +import java.util.ArrayList; +import java.util.List; +import java.util.Stack; + +import explorviz.live_trace_processing.filter.IPipeReceiver; +import explorviz.live_trace_processing.filter.reduction.AbstractReductionFilter; +import explorviz.live_trace_processing.record.event.AbstractAfterEventRecord; +import explorviz.live_trace_processing.record.event.AbstractBeforeEventRecord; +import explorviz.live_trace_processing.record.event.AbstractEventRecord; +import explorviz.live_trace_processing.record.trace.Trace; + +public class FragmentationFilter extends AbstractReductionFilter { + + private final int objectId; + + /* + * The FragmentationFilter keeps all Records with the given objectId. + */ + public FragmentationFilter(final IPipeReceiver receiver, final int objectId) { + super(receiver, "FragmentationFilter"); + this.objectId = objectId; + } + + @Override + protected Trace reduceTrace(final Trace trace) { + final List<AbstractEventRecord> traceEvents = new ArrayList<AbstractEventRecord>(); + final Stack<Integer> stack = new Stack<Integer>(); + int count = 0; + for (final AbstractEventRecord event : trace.getTraceEvents()) { + if (event instanceof AbstractBeforeEventRecord) { + count++; + final int objectId = ((AbstractBeforeEventRecord) event).getObjectId(); + if (this.objectId == objectId) { + traceEvents.add(event); + stack.push(new Integer(count)); + } + } else if (event instanceof AbstractAfterEventRecord) { + if (!stack.isEmpty() && (stack.peek() == count)) { + traceEvents.add(event); + stack.pop(); + } + count--; + } + } + + return new Trace(traceEvents, true); + } + +} diff --git a/src/explorviz/live_trace_processing/filter/reduction/evaluation/ad_hoc/SamplingFilter.java b/src/explorviz/live_trace_processing/filter/reduction/evaluation/ad_hoc/SamplingFilter.java new file mode 100644 index 0000000000000000000000000000000000000000..549f1935cf803de8cb7de0c091c77aa0a20fa3c7 --- /dev/null +++ b/src/explorviz/live_trace_processing/filter/reduction/evaluation/ad_hoc/SamplingFilter.java @@ -0,0 +1,53 @@ +package explorviz.live_trace_processing.filter.reduction.evaluation.ad_hoc; + +import java.util.ArrayList; +import java.util.List; +import java.util.Stack; + +import explorviz.live_trace_processing.filter.IPipeReceiver; +import explorviz.live_trace_processing.filter.reduction.AbstractReductionFilter; +import explorviz.live_trace_processing.record.event.AbstractAfterEventRecord; +import explorviz.live_trace_processing.record.event.AbstractAfterFailedEventRecord; +import explorviz.live_trace_processing.record.event.AbstractBeforeEventRecord; +import explorviz.live_trace_processing.record.event.AbstractEventRecord; +import explorviz.live_trace_processing.record.trace.Trace; + +public class SamplingFilter extends AbstractReductionFilter { + + private final int samplingDistance; + + public SamplingFilter(final IPipeReceiver receiver, final int samplingDistance) { + super(receiver, "Sampling"); + this.samplingDistance = samplingDistance; + } + + @Override + protected Trace reduceTrace(final Trace trace) { + final List<AbstractEventRecord> newTraceEvents = new ArrayList<AbstractEventRecord>(); + int stackDepth = 0; + int counter = samplingDistance; + final Stack<Integer> stack = new Stack<Integer>(); + for (final AbstractEventRecord record : trace.getTraceEvents()) { + if (record instanceof AbstractBeforeEventRecord) { + stackDepth++; + if (counter == samplingDistance) { + newTraceEvents.add(record); + stack.push(new Integer(stackDepth)); + counter = 0; + } + counter++; + } else if ((record instanceof AbstractAfterEventRecord) + || (record instanceof AbstractAfterFailedEventRecord)) { + if (!stack.isEmpty() && (stackDepth == stack.peek())) { + stack.pop(); + newTraceEvents.add(record); + } + stackDepth--; + } else { + newTraceEvents.add(record); + } + } + return new Trace(newTraceEvents, true); + } + +} diff --git a/src/explorviz/live_trace_processing/filter/reduction/evaluation/language_based/RemoveNonPublicMethodsFilter.java b/src/explorviz/live_trace_processing/filter/reduction/evaluation/language_based/RemoveNonPublicMethodsFilter.java new file mode 100644 index 0000000000000000000000000000000000000000..4b754f36d4493b6f21156f3781a19ed0105c76d4 --- /dev/null +++ b/src/explorviz/live_trace_processing/filter/reduction/evaluation/language_based/RemoveNonPublicMethodsFilter.java @@ -0,0 +1,18 @@ +package explorviz.live_trace_processing.filter.reduction.evaluation.language_based; + +import explorviz.live_trace_processing.filter.IPipeReceiver; +import explorviz.live_trace_processing.filter.reduction.language_based.AbstractLanguageBasedFilter; +import explorviz.live_trace_processing.record.event.AbstractBeforeEventRecord; + +public class RemoveNonPublicMethodsFilter extends AbstractLanguageBasedFilter { + + public RemoveNonPublicMethodsFilter(final IPipeReceiver receiver) { + super(receiver, "NonPublic"); + } + + @Override + protected boolean isSoughtEvent(final AbstractBeforeEventRecord abstractBeforeEventRecord) { + return !abstractBeforeEventRecord.getOperationSignature().contains("public"); + } + +} diff --git a/src/explorviz/live_trace_processing/filter/reduction/evaluation/language_based/RemovePackageFilter.java b/src/explorviz/live_trace_processing/filter/reduction/evaluation/language_based/RemovePackageFilter.java new file mode 100644 index 0000000000000000000000000000000000000000..ce792003612e00931bc8f8b5262cb8f374d80d3a --- /dev/null +++ b/src/explorviz/live_trace_processing/filter/reduction/evaluation/language_based/RemovePackageFilter.java @@ -0,0 +1,21 @@ +package explorviz.live_trace_processing.filter.reduction.evaluation.language_based; + +import explorviz.live_trace_processing.filter.IPipeReceiver; +import explorviz.live_trace_processing.filter.reduction.language_based.AbstractLanguageBasedFilter; +import explorviz.live_trace_processing.record.event.AbstractBeforeEventRecord; + +public class RemovePackageFilter extends AbstractLanguageBasedFilter { + + String packageName; + + public RemovePackageFilter(final IPipeReceiver receiver, final String packageName) { + super(receiver, "packageFiltering"); + this.packageName = packageName; + } + + @Override + protected boolean isSoughtEvent(final AbstractBeforeEventRecord abstractBeforeEventRecord) { + return abstractBeforeEventRecord.getOperationSignature().contains(packageName); + } + +} diff --git a/src/explorviz/live_trace_processing/filter/reduction/evaluation/metrics_based/StackDepthFilter.java b/src/explorviz/live_trace_processing/filter/reduction/evaluation/metrics_based/StackDepthFilter.java new file mode 100644 index 0000000000000000000000000000000000000000..b94e11af7629be7166724cd94088559263ea681c --- /dev/null +++ b/src/explorviz/live_trace_processing/filter/reduction/evaluation/metrics_based/StackDepthFilter.java @@ -0,0 +1,49 @@ +package explorviz.live_trace_processing.filter.reduction.evaluation.metrics_based; + +import java.util.ArrayList; +import java.util.List; + +import explorviz.live_trace_processing.filter.IPipeReceiver; +import explorviz.live_trace_processing.filter.reduction.AbstractReductionFilter; +import explorviz.live_trace_processing.record.event.AbstractAfterEventRecord; +import explorviz.live_trace_processing.record.event.AbstractAfterFailedEventRecord; +import explorviz.live_trace_processing.record.event.AbstractBeforeEventRecord; +import explorviz.live_trace_processing.record.event.AbstractEventRecord; +import explorviz.live_trace_processing.record.event.AbstractRemoteEventRecord; +import explorviz.live_trace_processing.record.trace.Trace; + +public class StackDepthFilter extends AbstractReductionFilter { + + private final int maxStackDepth; + + public StackDepthFilter(final IPipeReceiver receiver, final int maxStackDepth) { + super(receiver, "StackDepthLimitation"); + this.maxStackDepth = maxStackDepth; + } + + @Override + protected Trace reduceTrace(final Trace trace) { + final List<AbstractEventRecord> newTraceEvents = new ArrayList<AbstractEventRecord>(); + int count = 0; + for (final AbstractEventRecord record : trace.getTraceEvents()) { + if (record instanceof AbstractBeforeEventRecord) { + if (count < maxStackDepth) { + newTraceEvents.add(record); + } + count++; + } else if ((record instanceof AbstractAfterEventRecord) + || (record instanceof AbstractAfterFailedEventRecord)) { + count--; + if (count < maxStackDepth) { + newTraceEvents.add(record); + } + } else if (record instanceof AbstractRemoteEventRecord) { + newTraceEvents.add(record); + } else { + newTraceEvents.add(record); + } + } + return new Trace(newTraceEvents, true); + } + +} diff --git a/src/explorviz/live_trace_processing/filter/reduction/evaluation/summarization/MonotoneSubsequenceFilter.java b/src/explorviz/live_trace_processing/filter/reduction/evaluation/summarization/MonotoneSubsequenceFilter.java new file mode 100644 index 0000000000000000000000000000000000000000..16497e8fa09d10507c4bf3c64a86753cfba25385 --- /dev/null +++ b/src/explorviz/live_trace_processing/filter/reduction/evaluation/summarization/MonotoneSubsequenceFilter.java @@ -0,0 +1,55 @@ +package explorviz.live_trace_processing.filter.reduction.evaluation.summarization; + +import java.util.ArrayList; +import java.util.List; +import java.util.Stack; + +import explorviz.live_trace_processing.filter.IPipeReceiver; +import explorviz.live_trace_processing.filter.reduction.AbstractReductionFilter; +import explorviz.live_trace_processing.record.event.AbstractAfterEventRecord; +import explorviz.live_trace_processing.record.event.AbstractBeforeEventRecord; +import explorviz.live_trace_processing.record.event.AbstractEventRecord; +import explorviz.live_trace_processing.record.trace.Trace; + +public class MonotoneSubsequenceFilter extends AbstractReductionFilter { + + public MonotoneSubsequenceFilter(final IPipeReceiver receiver) { + super(receiver, "MonotoneSubsequence"); + } + + @Override + protected Trace reduceTrace(final Trace trace) { + final List<AbstractEventRecord> newTraceEvents = new ArrayList<AbstractEventRecord>(); + int count = 0; + boolean keepNextBeforeEvent = true; + boolean lastEventWasAfterEvent = false; + final Stack<Integer> searchCorrespondingAfterEvent = new Stack<Integer>(); + for (final AbstractEventRecord event : trace.getTraceEvents()) { + if (event instanceof AbstractBeforeEventRecord) { + count++; + lastEventWasAfterEvent = false; + if (keepNextBeforeEvent) { + newTraceEvents.add(event); + searchCorrespondingAfterEvent.push(new Integer(count)); + keepNextBeforeEvent = false; + } + } else if (event instanceof AbstractAfterEventRecord) { + if (lastEventWasAfterEvent) { + keepNextBeforeEvent = true; + } else { + lastEventWasAfterEvent = true; + } + if (!searchCorrespondingAfterEvent.isEmpty() + && (count == searchCorrespondingAfterEvent.peek())) { + searchCorrespondingAfterEvent.pop(); + newTraceEvents.add(event); + } + count--; + } else { + newTraceEvents.add(event); + } + } + return new Trace(newTraceEvents, true); + } + +} diff --git a/src/explorviz/live_trace_processing/filter/reduction/language_based/AbstractLanguageBasedFilter.java b/src/explorviz/live_trace_processing/filter/reduction/language_based/AbstractLanguageBasedFilter.java new file mode 100644 index 0000000000000000000000000000000000000000..0adb80f92322bf8c683c9a28bc29c1e0abeba786 --- /dev/null +++ b/src/explorviz/live_trace_processing/filter/reduction/language_based/AbstractLanguageBasedFilter.java @@ -0,0 +1,51 @@ +package explorviz.live_trace_processing.filter.reduction.language_based; + +import java.util.ArrayList; +import java.util.List; +import java.util.Stack; + +import explorviz.live_trace_processing.filter.IPipeReceiver; +import explorviz.live_trace_processing.filter.reduction.AbstractReductionFilter; +import explorviz.live_trace_processing.record.event.AbstractAfterEventRecord; +import explorviz.live_trace_processing.record.event.AbstractBeforeEventRecord; +import explorviz.live_trace_processing.record.event.AbstractEventRecord; +import explorviz.live_trace_processing.record.trace.Trace; + +public abstract class AbstractLanguageBasedFilter extends AbstractReductionFilter { + + public AbstractLanguageBasedFilter(final IPipeReceiver receiver, final String counterString) { + super(receiver, counterString); + } + + @Override + protected Trace reduceTrace(final Trace trace) { + final List<AbstractEventRecord> traceEvents = new ArrayList<AbstractEventRecord>(); + final Stack<Integer> stack = new Stack<Integer>(); + int count = 0; + for (final AbstractEventRecord event : trace.getTraceEvents()) { + if (event instanceof AbstractBeforeEventRecord) { + count++; + final AbstractBeforeEventRecord abstractBeforeEventRecord = (AbstractBeforeEventRecord) event; + if (isSoughtEvent(abstractBeforeEventRecord)) { + stack.push(new Integer(count)); + } else { + traceEvents.add(event); + } + } else if (event instanceof AbstractAfterEventRecord) { + if (!stack.isEmpty() && (count == stack.peek())) { + stack.pop(); + } else { + traceEvents.add(event); + } + count--; + } + } + if (traceEvents.size() > 0) { + return new Trace(traceEvents, true); + } else { + return new Trace(traceEvents, false); + } + } + + protected abstract boolean isSoughtEvent(AbstractBeforeEventRecord abstractBeforeEventRecord); +} diff --git a/src/explorviz/live_trace_processing/filter/reduction/language_based/RemoveConstructorsFilter.java b/src/explorviz/live_trace_processing/filter/reduction/language_based/RemoveConstructorsFilter.java new file mode 100644 index 0000000000000000000000000000000000000000..18e7db140c117bab0511f7554b17fea992ac4f45 --- /dev/null +++ b/src/explorviz/live_trace_processing/filter/reduction/language_based/RemoveConstructorsFilter.java @@ -0,0 +1,40 @@ +package explorviz.live_trace_processing.filter.reduction.language_based; + +import java.util.ArrayList; +import java.util.List; + +import explorviz.live_trace_processing.filter.IPipeReceiver; +import explorviz.live_trace_processing.record.event.AbstractBeforeEventRecord; +import explorviz.live_trace_processing.record.event.AbstractEventRecord; +import explorviz.live_trace_processing.record.event.constructor.AfterConstructorEventRecord; +import explorviz.live_trace_processing.record.event.constructor.BeforeConstructorEventRecord; +import explorviz.live_trace_processing.record.trace.Trace; + +public class RemoveConstructorsFilter extends AbstractLanguageBasedFilter { + + public RemoveConstructorsFilter(final IPipeReceiver receiver) { + super(receiver, "ConstructorHiding"); + } + + @Override + protected Trace reduceTrace(final Trace trace) { + final List<AbstractEventRecord> traceEvents = new ArrayList<AbstractEventRecord>(); + for (final AbstractEventRecord event : trace.getTraceEvents()) { + if (event instanceof BeforeConstructorEventRecord) { + + } else if (event instanceof AfterConstructorEventRecord) { + + } else { + traceEvents.add(event); + } + } + return new Trace(traceEvents, true); + } + + @Override + protected boolean isSoughtEvent(final AbstractBeforeEventRecord abstractBeforeEventRecord) { + // not used + return false; + } + +} diff --git a/src/explorviz/live_trace_processing/filter/reduction/language_based/RemoveGettersAndSettersFilter.java b/src/explorviz/live_trace_processing/filter/reduction/language_based/RemoveGettersAndSettersFilter.java new file mode 100644 index 0000000000000000000000000000000000000000..66af394e916072a6fd9e5866d9169d4381085e59 --- /dev/null +++ b/src/explorviz/live_trace_processing/filter/reduction/language_based/RemoveGettersAndSettersFilter.java @@ -0,0 +1,30 @@ +package explorviz.live_trace_processing.filter.reduction.language_based; + +import explorviz.live_trace_processing.filter.IPipeReceiver; +import explorviz.live_trace_processing.record.event.AbstractBeforeEventRecord; + +public class RemoveGettersAndSettersFilter extends AbstractLanguageBasedFilter { + + public RemoveGettersAndSettersFilter(final IPipeReceiver receiver) { + super(receiver, "GettersAndSetters"); + } + + @Override + protected boolean isSoughtEvent(final AbstractBeforeEventRecord abstractBeforeEventRecord) { + return isGetterOrSetter(abstractBeforeEventRecord.getOperationSignature()); + } + + private boolean isGetterOrSetter(final String operationSignature) { + final String methodName = getMethodName(operationSignature); + return methodName.startsWith("get") || methodName.startsWith("set"); + } + + private String getMethodName(final String operationSignatureStr) { + final String[] a = operationSignatureStr.split("\\(")[0].split("\\s"); + final String b = a[a.length - 1]; + final int c = b.lastIndexOf('.'); + final String methodName = b.substring(c + 1); + return methodName; + } + +} diff --git a/src/explorviz/live_trace_processing/filter/reduction/summarization/AssociativityFilter.java b/src/explorviz/live_trace_processing/filter/reduction/summarization/AssociativityFilter.java new file mode 100644 index 0000000000000000000000000000000000000000..f1828d1c6cb4b07831962fa29ac5b3fa20d4765c --- /dev/null +++ b/src/explorviz/live_trace_processing/filter/reduction/summarization/AssociativityFilter.java @@ -0,0 +1,78 @@ +package explorviz.live_trace_processing.filter.reduction.summarization; + +import java.util.ArrayList; +import java.util.List; +import java.util.Stack; + +import explorviz.live_trace_processing.filter.IPipeReceiver; +import explorviz.live_trace_processing.filter.reduction.AbstractReductionFilter; +import explorviz.live_trace_processing.record.event.AbstractAfterEventRecord; +import explorviz.live_trace_processing.record.event.AbstractAfterFailedEventRecord; +import explorviz.live_trace_processing.record.event.AbstractBeforeEventRecord; +import explorviz.live_trace_processing.record.event.AbstractEventRecord; +import explorviz.live_trace_processing.record.trace.Trace; + +public class AssociativityFilter extends AbstractReductionFilter { + + public AssociativityFilter(final IPipeReceiver receiver) { + super(receiver, "AssoziationFilter"); + } + + @Override + protected Trace reduceTrace(final Trace trace) { + final List<AbstractEventRecord> newTraceEvents = new ArrayList<AbstractEventRecord>(); + String caller = null; + int count = 0; + final Stack<Integer> stack = new Stack<Integer>(); + final Stack<String> callerStack = new Stack<String>(); + for (final AbstractEventRecord record : trace.getTraceEvents()) { + if (record instanceof AbstractBeforeEventRecord) { + count++; + final AbstractBeforeEventRecord abstractBeforeEventRecord = (AbstractBeforeEventRecord) record; + final String signature = abstractBeforeEventRecord.getOperationSignature(); + final String callee = getClazzFullQName(signature); + if (!callee.equals(caller)) { + newTraceEvents.add(record); + } else { + stack.push(new Integer(count)); + } + caller = callee; + callerStack.push(caller); + } else if ((record instanceof AbstractAfterEventRecord) + || (record instanceof AbstractAfterFailedEventRecord)) { + callerStack.pop(); + if (!callerStack.isEmpty()) { + caller = callerStack.peek(); + } + if (!stack.isEmpty() && (count == stack.peek())) { + stack.pop(); + } else { + newTraceEvents.add(record); + } + count--; + } else { + newTraceEvents.add(record); + } + } + return new Trace(newTraceEvents, true); + } + + private String getClazzFullQName(final String operationSignatureStr) { + final int brace = operationSignatureStr.indexOf('('); + final String signatureWithoutArguments = operationSignatureStr.substring(0, brace); + final int lastWhiteSpace = signatureWithoutArguments.lastIndexOf(' '); + final int lastDot = signatureWithoutArguments.lastIndexOf('.'); + if (lastDot == -1) { + return ""; + } + final String fullQClazzName = signatureWithoutArguments.substring(lastWhiteSpace + 1, + lastDot); + + if (fullQClazzName.indexOf("$") > 0) { + return fullQClazzName.substring(0, fullQClazzName.indexOf("$")); + } else { + return fullQClazzName; + } + } + +} diff --git a/src/explorviz/live_trace_processing/filter/reduction/summarization/Edge.java b/src/explorviz/live_trace_processing/filter/reduction/summarization/Edge.java new file mode 100644 index 0000000000000000000000000000000000000000..7aab3b84e071f17ee7e17edd54e952de021a289a --- /dev/null +++ b/src/explorviz/live_trace_processing/filter/reduction/summarization/Edge.java @@ -0,0 +1,51 @@ +package explorviz.live_trace_processing.filter.reduction.summarization; + +import explorviz.live_trace_processing.record.event.AbstractAfterEventRecord; +import explorviz.live_trace_processing.record.event.AbstractBeforeEventRecord; + +public class Edge { + + private AbstractBeforeEventRecord caller; + private AbstractBeforeEventRecord callee; + private AbstractAfterEventRecord callee_end; + private boolean taken; + + public Edge(final AbstractBeforeEventRecord caller, final AbstractBeforeEventRecord callee) { + this.caller = caller; + this.callee = callee; + taken = false; + } + + public AbstractAfterEventRecord getCallee_end() { + return callee_end; + } + + public void setCallee_end(final AbstractAfterEventRecord callee_end) { + this.callee_end = callee_end; + } + + public boolean isTaken() { + return taken; + } + + public void setTaken(final boolean taken) { + this.taken = taken; + } + + public AbstractBeforeEventRecord getCaller() { + return caller; + } + + public void setCaller(final AbstractBeforeEventRecord caller) { + this.caller = caller; + } + + public AbstractBeforeEventRecord getCallee() { + return callee; + } + + public void setCallee(final AbstractBeforeEventRecord callee) { + this.callee = callee; + } + +} diff --git a/src/explorviz/live_trace_processing/filter/reduction/summarization/IterationFilter.java b/src/explorviz/live_trace_processing/filter/reduction/summarization/IterationFilter.java new file mode 100644 index 0000000000000000000000000000000000000000..ba091d37bb35e79e73e68e207e39153fb86f7768 --- /dev/null +++ b/src/explorviz/live_trace_processing/filter/reduction/summarization/IterationFilter.java @@ -0,0 +1,73 @@ +package explorviz.live_trace_processing.filter.reduction.summarization; + +import java.util.ArrayList; +import java.util.List; + +import explorviz.live_trace_processing.filter.IPipeReceiver; +import explorviz.live_trace_processing.filter.reduction.AbstractReductionFilter; +import explorviz.live_trace_processing.filter.reduction.ITraceReduction; +import explorviz.live_trace_processing.record.event.AbstractAfterEventRecord; +import explorviz.live_trace_processing.record.event.AbstractBeforeEventRecord; +import explorviz.live_trace_processing.record.event.AbstractEventRecord; +import explorviz.live_trace_processing.record.trace.Trace; + +public class IterationFilter extends AbstractReductionFilter implements ITraceReduction { + + public IterationFilter(final IPipeReceiver receiver) { + super(receiver, "IterationFilter"); + } + + @Override + protected Trace reduceTrace(final Trace trace) { + final List<AbstractEventRecord> newTraceEvents = new ArrayList<AbstractEventRecord>(); + final List<AbstractEventRecord> traceEvents = trace.getTraceEvents(); + int i = 0; + while (i < (traceEvents.size() - 3)) { + if (traceEvents.get(i) instanceof AbstractBeforeEventRecord) { + final AbstractBeforeEventRecord firstBeforeEvent = (AbstractBeforeEventRecord) traceEvents + .get(i); + if (traceEvents.get(i + 1) instanceof AbstractAfterEventRecord) { + final AbstractAfterEventRecord firstAfterEvent = (AbstractAfterEventRecord) traceEvents + .get(i + 1); + if (traceEvents.get(i + 2) instanceof AbstractBeforeEventRecord) { + final AbstractBeforeEventRecord secondBeforeEvent = (AbstractBeforeEventRecord) traceEvents + .get(i + 2); + if (firstBeforeEvent.compareTo(secondBeforeEvent) == 0) { + if (traceEvents.get(i + 3) instanceof AbstractAfterEventRecord) { + secondBeforeEvent.getRuntimeStatisticInformation().merge( + firstBeforeEvent.getRuntimeStatisticInformation()); + i += 2; + } else { + newTraceEvents.add(firstBeforeEvent); + newTraceEvents.add(firstAfterEvent); + newTraceEvents.add(secondBeforeEvent); + i += 3; + } + } else { + newTraceEvents.add(firstBeforeEvent); + newTraceEvents.add(firstAfterEvent); + i += 2; + } + } else { + newTraceEvents.add(firstBeforeEvent); + newTraceEvents.add(firstAfterEvent); + i += 2; + } + } else { + newTraceEvents.add(firstBeforeEvent); + i++; + } + } else { + newTraceEvents.add(traceEvents.get(i)); + i++; + } + } + while (i < traceEvents.size()) { + newTraceEvents.add(traceEvents.get(i)); + i++; + } + final Trace reducedTrace = new Trace(newTraceEvents, true); + return reducedTrace; + } + +} diff --git a/src/explorviz/live_trace_processing/filter/reduction/summarization/PatternSummarizationFilter.java b/src/explorviz/live_trace_processing/filter/reduction/summarization/PatternSummarizationFilter.java new file mode 100644 index 0000000000000000000000000000000000000000..0526a8db2b1d8e608b52a8905a3e1468bf638ce9 --- /dev/null +++ b/src/explorviz/live_trace_processing/filter/reduction/summarization/PatternSummarizationFilter.java @@ -0,0 +1,179 @@ +package explorviz.live_trace_processing.filter.reduction.summarization; + +import java.util.ArrayList; +import java.util.List; +import java.util.Stack; + +import explorviz.live_trace_processing.filter.IPipeReceiver; +import explorviz.live_trace_processing.filter.reduction.AbstractReductionFilter; +import explorviz.live_trace_processing.record.event.AbstractAfterEventRecord; +import explorviz.live_trace_processing.record.event.AbstractBeforeEventRecord; +import explorviz.live_trace_processing.record.event.AbstractEventRecord; +import explorviz.live_trace_processing.record.trace.Trace; + +public class PatternSummarizationFilter extends AbstractReductionFilter { + + public static final int DEFAULT_DISTANCE = 300; + public static final int DEFAULT_NESTINGLEVEL = 1; + private final int distance; + private final int nestingLevel; + + // private int maxDistance = 0; + // private boolean nextRound = false; + // private int maxNestingLevel = 0; + + public PatternSummarizationFilter(final IPipeReceiver receiver, final int distance, + final int nestingLevel) { + super(receiver, "PatternSummarization"); + if (distance < 1) { + this.distance = DEFAULT_DISTANCE; + } else { + this.distance = distance; + } + if (nestingLevel < 1) { + this.nestingLevel = DEFAULT_NESTINGLEVEL; + } else { + this.nestingLevel = nestingLevel; + } + } + + @Override + protected Trace reduceTrace(Trace trace) { + int t = 0; + while (t < nestingLevel) { + trace = summarizePattern(trace); + // if (!nextRound) { + // System.out.println("max distance: " + maxDistance); + // System.out.println("max nesting level: " + maxNestingLevel); + // return trace; + // } + // nextRound = false; + // maxNestingLevel++; + t++; + } + return trace; + } + + private Trace summarizePattern(final Trace trace) { + final List<AbstractEventRecord> newTraceEvents = new ArrayList<AbstractEventRecord>(); + final List<AbstractEventRecord> traceEvents = trace.getTraceEvents(); + int index = 0; + final int traceLength = traceEvents.size(); + int count = 0; + final Stack<Integer> stack = new Stack<Integer>(); + while (index < traceLength) { + final AbstractEventRecord event = traceEvents.get(index); + if (event instanceof AbstractBeforeEventRecord) { + count++; + final AbstractBeforeEventRecord beforeEvent = (AbstractBeforeEventRecord) event; + final int possibleRepititionStart = findPatternStart(beforeEvent, traceEvents, + index, traceLength); + if (possibleRepititionStart != -1) { + final int numberOfPatternRepititions = findPatternRepititions(traceEvents, + index, possibleRepititionStart, traceLength); + if (numberOfPatternRepititions != 0) { + // nextRound = true; + removeRepititions(index, numberOfPatternRepititions, + possibleRepititionStart, traceEvents, newTraceEvents); + count--; + index += (numberOfPatternRepititions + 1) + * (possibleRepititionStart - index); + } else { + newTraceEvents.add(event); + stack.push(new Integer(count)); + index++; + } + } else { + newTraceEvents.add(event); + stack.push(new Integer(count)); + index++; + } + } else if (event instanceof AbstractAfterEventRecord) { + if (!stack.isEmpty() && (stack.peek() == count)) { + stack.pop(); + newTraceEvents.add(event); + } + index++; + count--; + } else { + newTraceEvents.add(event); + index++; + } + } + + return new Trace(newTraceEvents, true); + } + + // summarize a found pattern + private void removeRepititions(final int start, final int numberOfPatternRepititions, + final int end, final List<AbstractEventRecord> traceEvents, + final List<AbstractEventRecord> newTraceEvents) { + final int d = end - start; + // if (d > maxDistance) { + // maxDistance = d; + // } + for (int i = start; i < end; i++) { + final AbstractEventRecord event = traceEvents.get(i); + if (event instanceof AbstractBeforeEventRecord) { + final AbstractBeforeEventRecord beforeEvent = (AbstractBeforeEventRecord) event; + for (int r = 1; r <= numberOfPatternRepititions; r++) { + final AbstractBeforeEventRecord nextEqualEvent = (AbstractBeforeEventRecord) traceEvents + .get(i + (r * d)); + beforeEvent.getRuntimeStatisticInformation().merge( + nextEqualEvent.getRuntimeStatisticInformation()); + + } + } + newTraceEvents.add(event); + } + + } + + // check if a pattern repetition is present, i.e., t[i+1]=t[j+1] ... + private int findPatternRepititions(final List<AbstractEventRecord> traceEvents, int i, int j, + final int traceLength) { + int numberOfRepititions = 0; + final int d = j - i; + int counter = 0; + while (j < traceLength) { + final AbstractEventRecord event1 = traceEvents.get(i); + final AbstractEventRecord event2 = traceEvents.get(j); + if (event1.compareTo(event2) != 0) { + return numberOfRepititions; + } + counter++; + if (counter == d) { + numberOfRepititions++; + counter = 0; + } + i++; + j++; + } + return numberOfRepititions; + } + + // search j with trace[i]==trace[j] and j-i<=d and equal caller(count==0) + // -1: no hit + private int findPatternStart(final AbstractBeforeEventRecord beforeEvent, + final List<AbstractEventRecord> traceEvents, int i, final int traceLength) { + int end = i + distance; + if (end >= traceLength) { + end = traceLength - 1; + } + int count = 0; + while (i < end) { + i++; + final AbstractEventRecord event = traceEvents.get(i); + if (event instanceof AbstractBeforeEventRecord) { + count++; + if ((count == 0) && (beforeEvent.compareTo(event) == 0)) { + return i; + } + } else if (event instanceof AbstractAfterEventRecord) { + count--; + } + } + return -1; + } + +} diff --git a/src/explorviz/live_trace_processing/filter/reduction/summarization/TreeSummarizationFilter.java b/src/explorviz/live_trace_processing/filter/reduction/summarization/TreeSummarizationFilter.java new file mode 100644 index 0000000000000000000000000000000000000000..2b018c00ed274fc75dedca8b38b7818fa500ac84 --- /dev/null +++ b/src/explorviz/live_trace_processing/filter/reduction/summarization/TreeSummarizationFilter.java @@ -0,0 +1,144 @@ +package explorviz.live_trace_processing.filter.reduction.summarization; + +import java.util.ArrayList; +import java.util.List; +import java.util.Stack; + +import explorviz.live_trace_processing.filter.IPipeReceiver; +import explorviz.live_trace_processing.filter.reduction.AbstractReductionFilter; +import explorviz.live_trace_processing.record.event.AbstractAfterEventRecord; +import explorviz.live_trace_processing.record.event.AbstractBeforeEventRecord; +import explorviz.live_trace_processing.record.event.AbstractEventRecord; +import explorviz.live_trace_processing.record.trace.Trace; + +public class TreeSummarizationFilter extends AbstractReductionFilter { + + public TreeSummarizationFilter(final IPipeReceiver receiver) { + super(receiver, "TreeSummarization"); + } + + @Override + protected Trace reduceTrace(final Trace trace) { + if (trace.getTraceEvents().size() < 4) { + return trace; + } + final List<Edge> edges = new ArrayList<Edge>(); + buildEdgesfromTrace(edges, trace.getTraceEvents()); + final Trace newTrace = buildTraceFromEdges(edges); + return newTrace; + } + + private void buildEdgesfromTrace(final List<Edge> edges, + final List<AbstractEventRecord> traceEvents) { + AbstractBeforeEventRecord caller; + AbstractBeforeEventRecord callee = null; + final Stack<AbstractBeforeEventRecord> callerStack = new Stack<AbstractBeforeEventRecord>(); + callerStack.push(callee); + final Stack<Integer> stack = new Stack<Integer>(); + final Stack<Edge> edgeStack = new Stack<Edge>(); + int count = 0; + for (final AbstractEventRecord event : traceEvents) { + if (event instanceof AbstractBeforeEventRecord) { + count++; + caller = callerStack.peek(); + callee = (AbstractBeforeEventRecord) event; + callerStack.push(callee); + if (!callerEqualsCallee(caller, callee) + && addToList(caller, callee, edges, edgeStack)) { + stack.push(new Integer(count)); + } + } else if (event instanceof AbstractAfterEventRecord) { + callerStack.pop(); + if (!stack.isEmpty() && (count == stack.peek())) { + stack.pop(); + final Edge edge = edgeStack.pop(); + final AbstractAfterEventRecord callee_end = (AbstractAfterEventRecord) event; + edge.setCallee_end(callee_end); + } + count--; + } else { + // TODO: handle remote calls + } + } + } + + private boolean addToList(final AbstractBeforeEventRecord caller, + final AbstractBeforeEventRecord callee, final List<Edge> edges, + final Stack<Edge> edgeStack) { + for (final Edge edge : edges) { + if (callerEqualsCallee(caller, edge.getCaller()) + && callerEqualsCallee(callee, edge.getCallee())) { + mergeInformation(edge, caller, callee); + return false; + } + } + final Edge edge = new Edge(caller, callee); + edges.add(edge); + edgeStack.add(edge); + return true; + } + + private void mergeInformation(final Edge edge, final AbstractBeforeEventRecord caller, + final AbstractBeforeEventRecord callee) { + edge.getCallee().getRuntimeStatisticInformation() + .merge(callee.getRuntimeStatisticInformation()); + } + + private Trace buildTraceFromEdges(final List<Edge> edges) { + final List<AbstractEventRecord> traceEvents = new ArrayList<AbstractEventRecord>(); + final Edge start = edges.get(0); + traceEvents.add(start.getCallee()); + start.setTaken(true); + recursiveCall(traceEvents, edges, start.getCallee()); + traceEvents.add(start.getCallee_end()); + return new Trace(traceEvents, true); + } + + private void recursiveCall(final List<AbstractEventRecord> traceEvents, final List<Edge> edges, + final AbstractBeforeEventRecord callee) { + for (final Edge edge : edges) { + if (!edge.isTaken() && (callerEqualsCallee(edge.getCaller(), callee))) { + traceEvents.add(edge.getCallee()); + edge.setTaken(true); + recursiveCall(traceEvents, edges, edge.getCallee()); + traceEvents.add(edge.getCallee_end()); + } + } + + } + + private boolean callerEqualsCallee(final AbstractBeforeEventRecord caller, + final AbstractBeforeEventRecord callee) { + if (caller == null) { + if (callee == null) { + return true; + } else { + return false; + } + } else if (callee == null) { + return false; + } + final String callerClazz = getClazzFullQName(caller.getOperationSignature()); + final String calleeClazz = getClazzFullQName(callee.getOperationSignature()); + return callerClazz.equals(calleeClazz); + } + + private String getClazzFullQName(final String operationSignatureStr) { + final int brace = operationSignatureStr.indexOf('('); + final String signatureWithoutArguments = operationSignatureStr.substring(0, brace); + final int lastWhiteSpace = signatureWithoutArguments.lastIndexOf(' '); + final int lastDot = signatureWithoutArguments.lastIndexOf('.'); + if (lastDot == -1) { + return ""; + } + final String fullQClazzName = signatureWithoutArguments.substring(lastWhiteSpace + 1, + lastDot); + + if (fullQClazzName.indexOf("$") > 0) { + return fullQClazzName.substring(0, fullQClazzName.indexOf("$")); + } else { + return fullQClazzName; + } + } + +} diff --git a/src/explorviz/live_trace_processing/main/FilterConfiguration.java b/src/explorviz/live_trace_processing/main/FilterConfiguration.java index 98a3cde56d7083b60c01d50865124d08dface3c6..dbed37a84890a1b490e38825ae2a1dec6a230957 100644 --- a/src/explorviz/live_trace_processing/main/FilterConfiguration.java +++ b/src/explorviz/live_trace_processing/main/FilterConfiguration.java @@ -8,7 +8,7 @@ import explorviz.live_trace_processing.filter.ITraceSink; import explorviz.live_trace_processing.filter.reconstruction.ITraceReconstruction; import explorviz.live_trace_processing.filter.reconstruction.TraceReconstructionFilter; import explorviz.live_trace_processing.filter.reduction.ITraceReduction; -import explorviz.live_trace_processing.filter.reduction.summarization.TracePatternSummarizationFilter; +import explorviz.live_trace_processing.filter.reduction.language_based.RemoveConstructorsFilter; import explorviz.live_trace_processing.reader.TCPReader; public class FilterConfiguration { @@ -17,8 +17,12 @@ public class FilterConfiguration { // final IRecordCounting recordCounting = new // RecordCountingFilter(sink); - final ITraceReduction traceReduction = new TracePatternSummarizationFilter( - TimeUnit.MILLISECONDS.toNanos(990), sink); + final ITraceReduction traceReduction = new RemoveConstructorsFilter(sink); + // final ITraceReduction traceReduction = new + // TreeSummarization(recordCounting); + // final ITraceReduction traceReduction = new + // TracePatternSummarizationFilter( + // TimeUnit.MILLISECONDS.toNanos(990), sink); final ITraceReconstruction traceReconstruction = new TraceReconstructionFilter( TimeUnit.SECONDS.toNanos(4), traceReduction); diff --git a/test/explorviz/live_trace_processing/filter/reduction/AssociativityFilterTest.java b/test/explorviz/live_trace_processing/filter/reduction/AssociativityFilterTest.java new file mode 100644 index 0000000000000000000000000000000000000000..f003980a576a6d2b84617be34c913259182ffd54 --- /dev/null +++ b/test/explorviz/live_trace_processing/filter/reduction/AssociativityFilterTest.java @@ -0,0 +1,110 @@ +package explorviz.live_trace_processing.filter.reduction; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import explorviz.live_trace_processing.filter.reduction.summarization.AssociativityFilter; +import explorviz.live_trace_processing.record.event.AbstractEventRecord; +import explorviz.live_trace_processing.record.event.normal.AfterOperationEventRecord; +import explorviz.live_trace_processing.record.event.normal.BeforeOperationEventRecord; +import explorviz.live_trace_processing.record.trace.HostApplicationMetaDataRecord; +import explorviz.live_trace_processing.record.trace.RuntimeStatisticInformation; +import explorviz.live_trace_processing.record.trace.Trace; + +public class AssociativityFilterTest { + + private Trace testTrace; + + @Before + public void init() { + final List<AbstractEventRecord> traceEvents = new ArrayList<AbstractEventRecord>(); + + final BeforeOperationEventRecord beforeEvent = new BeforeOperationEventRecord(1L, 1L, 0, 0, + "test.package.Clazz.method1()", new HostApplicationMetaDataRecord("host", + "application")); + beforeEvent.setRuntimeStatisticInformation(new RuntimeStatisticInformation(11L)); + traceEvents.add(beforeEvent); + + final BeforeOperationEventRecord beforeEvent1 = new BeforeOperationEventRecord(2L, 1L, 1, + 0, "test.package.Clazz.method2()", new HostApplicationMetaDataRecord("host", + "application")); + beforeEvent1.setRuntimeStatisticInformation(new RuntimeStatisticInformation(2L)); + traceEvents.add(beforeEvent1); + + final AfterOperationEventRecord afterEvent1 = new AfterOperationEventRecord(4L, 1L, 2, + new HostApplicationMetaDataRecord("host", "application")); + traceEvents.add(afterEvent1); + + final BeforeOperationEventRecord beforeEvent2 = new BeforeOperationEventRecord(5L, 1L, 3, + 0, "test.package.OtherClazz.method3()", new HostApplicationMetaDataRecord("host", + "application")); + beforeEvent2.setRuntimeStatisticInformation(new RuntimeStatisticInformation(1L)); + traceEvents.add(beforeEvent2); + + final AfterOperationEventRecord afterEvent2 = new AfterOperationEventRecord(6L, 1L, 4, + new HostApplicationMetaDataRecord("host", "application")); + traceEvents.add(afterEvent2); + + final BeforeOperationEventRecord beforeEvent3 = new BeforeOperationEventRecord(7L, 1L, 5, + 0, "test.package.Clazz.method2()", new HostApplicationMetaDataRecord("host", + "application")); + beforeEvent3.setRuntimeStatisticInformation(new RuntimeStatisticInformation(2L)); + traceEvents.add(beforeEvent3); + + final AfterOperationEventRecord afterEvent3 = new AfterOperationEventRecord(9L, 1L, 6, + new HostApplicationMetaDataRecord("host", "application")); + traceEvents.add(afterEvent3); + + final BeforeOperationEventRecord beforeEvent4 = new BeforeOperationEventRecord(10L, 1L, 7, + 0, "test.package.Clazz.method2()", new HostApplicationMetaDataRecord("host", + "application")); + beforeEvent4.setRuntimeStatisticInformation(new RuntimeStatisticInformation(1L)); + traceEvents.add(beforeEvent4); + + final AfterOperationEventRecord afterEvent4 = new AfterOperationEventRecord(11L, 1L, 8, + new HostApplicationMetaDataRecord("host", "application")); + traceEvents.add(afterEvent4); + + final AfterOperationEventRecord afterEvent = new AfterOperationEventRecord(12L, 1L, 9, + new HostApplicationMetaDataRecord("host", "application")); + traceEvents.add(afterEvent); + + testTrace = new Trace(traceEvents, true); + } + + @Test + public void testReduction() { + final List<AbstractEventRecord> traceEvents = new ArrayList<AbstractEventRecord>(); + + final BeforeOperationEventRecord beforeEvent = new BeforeOperationEventRecord(1L, 1L, 0, 0, + "test.package.Clazz.method1()", new HostApplicationMetaDataRecord("host", + "application")); + beforeEvent.setRuntimeStatisticInformation(new RuntimeStatisticInformation(11L)); + traceEvents.add(beforeEvent); + + final BeforeOperationEventRecord beforeEvent2 = new BeforeOperationEventRecord(5L, 1L, 3, + 0, "test.package.OtherClazz.method3()", new HostApplicationMetaDataRecord("host", + "application")); + beforeEvent2.setRuntimeStatisticInformation(new RuntimeStatisticInformation(1L)); + traceEvents.add(beforeEvent2); + + final AfterOperationEventRecord afterEvent2 = new AfterOperationEventRecord(6L, 1L, 4, + new HostApplicationMetaDataRecord("host", "application")); + traceEvents.add(afterEvent2); + + final AfterOperationEventRecord afterEvent = new AfterOperationEventRecord(12L, 1L, 9, + new HostApplicationMetaDataRecord("host", "application")); + traceEvents.add(afterEvent); + + final Trace compareTrace = new Trace(traceEvents, true); + final AssociativityFilter assoziationFilter = new AssociativityFilter(null); + final Trace reducedTrace = assoziationFilter.testReduction(testTrace); + Assert.assertTrue(compareTrace.compareTo(reducedTrace) == 0); + + } + +} diff --git a/test/explorviz/live_trace_processing/filter/reduction/IterationFilterTest.java b/test/explorviz/live_trace_processing/filter/reduction/IterationFilterTest.java new file mode 100644 index 0000000000000000000000000000000000000000..db8cf7427ce4c87ce7ea2c2c909581ca2cb1707a --- /dev/null +++ b/test/explorviz/live_trace_processing/filter/reduction/IterationFilterTest.java @@ -0,0 +1,105 @@ +package explorviz.live_trace_processing.filter.reduction; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import explorviz.live_trace_processing.filter.reduction.summarization.IterationFilter; +import explorviz.live_trace_processing.record.event.AbstractEventRecord; +import explorviz.live_trace_processing.record.event.normal.AfterOperationEventRecord; +import explorviz.live_trace_processing.record.event.normal.BeforeOperationEventRecord; +import explorviz.live_trace_processing.record.trace.HostApplicationMetaDataRecord; +import explorviz.live_trace_processing.record.trace.RuntimeStatisticInformation; +import explorviz.live_trace_processing.record.trace.Trace; + +public class IterationFilterTest { + + private Trace trace; + + @Before + public void init() { + final List<AbstractEventRecord> traceEvents = new ArrayList<AbstractEventRecord>(); + + final BeforeOperationEventRecord beforeEvent = new BeforeOperationEventRecord(1L, 1L, 0, 0, + "test.package.Clazz.method1()", new HostApplicationMetaDataRecord("host", + "application")); + beforeEvent.setRuntimeStatisticInformation(new RuntimeStatisticInformation(11L)); + traceEvents.add(beforeEvent); + + final BeforeOperationEventRecord beforeEvent1 = new BeforeOperationEventRecord(2L, 1L, 1, + 0, "test.package.Clazz.method2()", new HostApplicationMetaDataRecord("host", + "application")); + beforeEvent1.setRuntimeStatisticInformation(new RuntimeStatisticInformation(2L)); + traceEvents.add(beforeEvent1); + + final AfterOperationEventRecord afterEvent1 = new AfterOperationEventRecord(4L, 1L, 2, + new HostApplicationMetaDataRecord("host", "application")); + traceEvents.add(afterEvent1); + + final BeforeOperationEventRecord beforeEvent2 = new BeforeOperationEventRecord(5L, 1L, 3, + 0, "test.package.Clazz.method2()", new HostApplicationMetaDataRecord("host", + "application")); + beforeEvent2.setRuntimeStatisticInformation(new RuntimeStatisticInformation(1L)); + traceEvents.add(beforeEvent2); + + final AfterOperationEventRecord afterEvent2 = new AfterOperationEventRecord(6L, 1L, 4, + new HostApplicationMetaDataRecord("host", "application")); + traceEvents.add(afterEvent2); + + final BeforeOperationEventRecord beforeEvent3 = new BeforeOperationEventRecord(7L, 1L, 5, + 0, "test.package.Clazz.method2()", new HostApplicationMetaDataRecord("host", + "application")); + beforeEvent3.setRuntimeStatisticInformation(new RuntimeStatisticInformation(2L)); + traceEvents.add(beforeEvent3); + + final AfterOperationEventRecord afterEvent3 = new AfterOperationEventRecord(9L, 1L, 6, + new HostApplicationMetaDataRecord("host", "application")); + traceEvents.add(afterEvent3); + + final BeforeOperationEventRecord beforeEvent4 = new BeforeOperationEventRecord(10L, 1L, 7, + 0, "test.package.Clazz.method2()", new HostApplicationMetaDataRecord("host", + "application")); + beforeEvent4.setRuntimeStatisticInformation(new RuntimeStatisticInformation(1L)); + traceEvents.add(beforeEvent4); + + final AfterOperationEventRecord afterEvent4 = new AfterOperationEventRecord(11L, 1L, 8, + new HostApplicationMetaDataRecord("host", "application")); + traceEvents.add(afterEvent4); + + final AfterOperationEventRecord afterEvent = new AfterOperationEventRecord(12L, 1L, 9, + new HostApplicationMetaDataRecord("host", "application")); + traceEvents.add(afterEvent); + + trace = new Trace(traceEvents, true); + } + + @Test + public void testReduction() { + final List<AbstractEventRecord> traceEvents = new ArrayList<AbstractEventRecord>(); + final HostApplicationMetaDataRecord hostApplicationMetadata = new HostApplicationMetaDataRecord( + "host", "application"); + final BeforeOperationEventRecord beforeEvent = new BeforeOperationEventRecord(1L, 1L, 0, 0, + "test.package.Clazz.method1()", hostApplicationMetadata); + traceEvents.add(beforeEvent); + beforeEvent.setRuntimeStatisticInformation(new RuntimeStatisticInformation(11L)); + final BeforeOperationEventRecord beforeEvent1 = new BeforeOperationEventRecord(10L, 1L, 7, + 0, "test.package.Clazz.method2()", hostApplicationMetadata); + traceEvents.add(beforeEvent1); + beforeEvent1.setRuntimeStatisticInformation(new RuntimeStatisticInformation(4, 6, 10)); + final AfterOperationEventRecord afterEvent1 = new AfterOperationEventRecord(11L, 1L, 8, + hostApplicationMetadata); + traceEvents.add(afterEvent1); + final AfterOperationEventRecord afterEvent = new AfterOperationEventRecord(12L, 1L, 9, + hostApplicationMetadata); + traceEvents.add(afterEvent); + final Trace compareTrace = new Trace(traceEvents, true); + final IterationFilter iterationFilter = new IterationFilter(null); + final Trace reducedTrace = iterationFilter.testReduction(trace); + Assert.assertTrue(compareTrace.compareTo(reducedTrace) == 0); + + } + +} diff --git a/test/explorviz/live_trace_processing/filter/reduction/MonotoneSubsequenceTest.java b/test/explorviz/live_trace_processing/filter/reduction/MonotoneSubsequenceTest.java new file mode 100644 index 0000000000000000000000000000000000000000..e4d0cdf65711a9da82f9dd67c8a5d0a970dee4ec --- /dev/null +++ b/test/explorviz/live_trace_processing/filter/reduction/MonotoneSubsequenceTest.java @@ -0,0 +1,101 @@ +package explorviz.live_trace_processing.filter.reduction; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import explorviz.live_trace_processing.filter.reduction.evaluation.summarization.MonotoneSubsequenceFilter; +import explorviz.live_trace_processing.record.event.AbstractEventRecord; +import explorviz.live_trace_processing.record.event.normal.AfterOperationEventRecord; +import explorviz.live_trace_processing.record.event.normal.BeforeOperationEventRecord; +import explorviz.live_trace_processing.record.trace.HostApplicationMetaDataRecord; +import explorviz.live_trace_processing.record.trace.RuntimeStatisticInformation; +import explorviz.live_trace_processing.record.trace.Trace; + +public class MonotoneSubsequenceTest { + + private Trace trace; + + @Before + public void init() { + final List<AbstractEventRecord> traceEvents = new ArrayList<AbstractEventRecord>(); + + final BeforeOperationEventRecord beforeEvent = new BeforeOperationEventRecord(1L, 1L, 0, 0, + "test.package.Clazz.method1()", new HostApplicationMetaDataRecord("host", + "application")); + beforeEvent.setRuntimeStatisticInformation(new RuntimeStatisticInformation(11L)); + traceEvents.add(beforeEvent); + + final BeforeOperationEventRecord beforeEvent1 = new BeforeOperationEventRecord(2L, 1L, 1, + 0, "test.package.Clazz.method2()", new HostApplicationMetaDataRecord("host", + "application")); + beforeEvent1.setRuntimeStatisticInformation(new RuntimeStatisticInformation(2L)); + traceEvents.add(beforeEvent1); + + final AfterOperationEventRecord afterEvent1 = new AfterOperationEventRecord(4L, 1L, 2, + new HostApplicationMetaDataRecord("host", "application")); + traceEvents.add(afterEvent1); + + final BeforeOperationEventRecord beforeEvent2 = new BeforeOperationEventRecord(5L, 1L, 3, + 0, "test.package.Clazz.method2()", new HostApplicationMetaDataRecord("host", + "application")); + beforeEvent2.setRuntimeStatisticInformation(new RuntimeStatisticInformation(1L)); + traceEvents.add(beforeEvent2); + + final AfterOperationEventRecord afterEvent2 = new AfterOperationEventRecord(6L, 1L, 4, + new HostApplicationMetaDataRecord("host", "application")); + traceEvents.add(afterEvent2); + + final BeforeOperationEventRecord beforeEvent3 = new BeforeOperationEventRecord(7L, 1L, 5, + 0, "test.package.Clazz.method2()", new HostApplicationMetaDataRecord("host", + "application")); + beforeEvent3.setRuntimeStatisticInformation(new RuntimeStatisticInformation(2L)); + traceEvents.add(beforeEvent3); + + final AfterOperationEventRecord afterEvent3 = new AfterOperationEventRecord(9L, 1L, 6, + new HostApplicationMetaDataRecord("host", "application")); + traceEvents.add(afterEvent3); + + final BeforeOperationEventRecord beforeEvent4 = new BeforeOperationEventRecord(10L, 1L, 7, + 0, "test.package.Clazz.method2()", new HostApplicationMetaDataRecord("host", + "application")); + beforeEvent4.setRuntimeStatisticInformation(new RuntimeStatisticInformation(1L)); + traceEvents.add(beforeEvent4); + + final AfterOperationEventRecord afterEvent4 = new AfterOperationEventRecord(11L, 1L, 8, + new HostApplicationMetaDataRecord("host", "application")); + traceEvents.add(afterEvent4); + + final AfterOperationEventRecord afterEvent = new AfterOperationEventRecord(12L, 1L, 9, + new HostApplicationMetaDataRecord("host", "application")); + traceEvents.add(afterEvent); + + trace = new Trace(traceEvents, true); + } + + @Test + public void testReduction() { + final List<AbstractEventRecord> traceEvents = new ArrayList<AbstractEventRecord>(); + + final HostApplicationMetaDataRecord hostApplicationMetadata = new HostApplicationMetaDataRecord( + "host", "application"); + + final BeforeOperationEventRecord beforeEvent = new BeforeOperationEventRecord(1L, 1L, 0, 0, + "test.package.Clazz.method1()", hostApplicationMetadata); + traceEvents.add(beforeEvent); + beforeEvent.setRuntimeStatisticInformation(new RuntimeStatisticInformation(11L)); + + final AfterOperationEventRecord afterEvent = new AfterOperationEventRecord(12L, 1L, 9, + hostApplicationMetadata); + traceEvents.add(afterEvent); + + final Trace compareTrace = new Trace(traceEvents, true); + final MonotoneSubsequenceFilter subseqFilter = new MonotoneSubsequenceFilter(null); + final Trace reducedTrace = subseqFilter.testReduction(trace); + Assert.assertTrue(compareTrace.compareTo(reducedTrace) == 0); + + } +} diff --git a/test/explorviz/live_trace_processing/filter/reduction/PatternSummarizationTest.java b/test/explorviz/live_trace_processing/filter/reduction/PatternSummarizationTest.java new file mode 100644 index 0000000000000000000000000000000000000000..cb99837b86e4cae25d4cddcff864e9bcf240cfe2 --- /dev/null +++ b/test/explorviz/live_trace_processing/filter/reduction/PatternSummarizationTest.java @@ -0,0 +1,250 @@ +package explorviz.live_trace_processing.filter.reduction; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import explorviz.live_trace_processing.filter.reduction.summarization.PatternSummarizationFilter; +import explorviz.live_trace_processing.record.event.AbstractEventRecord; +import explorviz.live_trace_processing.record.event.normal.AfterOperationEventRecord; +import explorviz.live_trace_processing.record.event.normal.BeforeOperationEventRecord; +import explorviz.live_trace_processing.record.trace.HostApplicationMetaDataRecord; +import explorviz.live_trace_processing.record.trace.RuntimeStatisticInformation; +import explorviz.live_trace_processing.record.trace.Trace; + +public class PatternSummarizationTest { + + private Trace trace; + + @Before + public void init() { + final List<AbstractEventRecord> traceEvents = new ArrayList<AbstractEventRecord>(); + + final BeforeOperationEventRecord beforeEvent = new BeforeOperationEventRecord(1L, 1L, 0, 0, + "test.package.Clazz.A()", new HostApplicationMetaDataRecord("host", "application")); + beforeEvent.setRuntimeStatisticInformation(new RuntimeStatisticInformation(31L)); + traceEvents.add(beforeEvent); + + final BeforeOperationEventRecord beforeEvent1 = new BeforeOperationEventRecord(2L, 1L, 1, + 0, "test.package.Clazz.B()", new HostApplicationMetaDataRecord("host", + "application")); + beforeEvent1.setRuntimeStatisticInformation(new RuntimeStatisticInformation(2L)); + traceEvents.add(beforeEvent1); + + final AfterOperationEventRecord afterEvent1 = new AfterOperationEventRecord(4L, 1L, 2, + new HostApplicationMetaDataRecord("host", "application")); + traceEvents.add(afterEvent1); + + final BeforeOperationEventRecord beforeEvent2 = new BeforeOperationEventRecord(5L, 1L, 3, + 0, "test.package.Clazz.C()", new HostApplicationMetaDataRecord("host", + "application")); + beforeEvent2.setRuntimeStatisticInformation(new RuntimeStatisticInformation(1L)); + traceEvents.add(beforeEvent2); + + final AfterOperationEventRecord afterEvent2 = new AfterOperationEventRecord(6L, 1L, 4, + new HostApplicationMetaDataRecord("host", "application")); + traceEvents.add(afterEvent2); + + final BeforeOperationEventRecord beforeEvent3 = new BeforeOperationEventRecord(7L, 1L, 5, + 0, "test.package.Clazz.D()", new HostApplicationMetaDataRecord("host", + "application")); + beforeEvent3.setRuntimeStatisticInformation(new RuntimeStatisticInformation(9L)); + traceEvents.add(beforeEvent3); + + final BeforeOperationEventRecord beforeEvent4 = new BeforeOperationEventRecord(8L, 1L, 6, + 0, "test.package.Clazz.E()", new HostApplicationMetaDataRecord("host", + "application")); + beforeEvent4.setRuntimeStatisticInformation(new RuntimeStatisticInformation(1L)); + traceEvents.add(beforeEvent4); + + final AfterOperationEventRecord afterEvent4 = new AfterOperationEventRecord(9L, 1L, 7, + new HostApplicationMetaDataRecord("host", "application")); + traceEvents.add(afterEvent4); + + final BeforeOperationEventRecord beforeEvent5 = new BeforeOperationEventRecord(10L, 1L, 8, + 0, "test.package.Clazz.F()", new HostApplicationMetaDataRecord("host", + "application")); + beforeEvent5.setRuntimeStatisticInformation(new RuntimeStatisticInformation(1L)); + traceEvents.add(beforeEvent5); + + final AfterOperationEventRecord afterEvent5 = new AfterOperationEventRecord(11L, 1L, 9, + new HostApplicationMetaDataRecord("host", "application")); + traceEvents.add(afterEvent5); + + final BeforeOperationEventRecord beforeEvent6 = new BeforeOperationEventRecord(12L, 1L, 10, + 0, "test.package.Clazz.E()", new HostApplicationMetaDataRecord("host", + "application")); + beforeEvent6.setRuntimeStatisticInformation(new RuntimeStatisticInformation(1L)); + traceEvents.add(beforeEvent6); + + final AfterOperationEventRecord afterEvent6 = new AfterOperationEventRecord(13L, 1L, 11, + new HostApplicationMetaDataRecord("host", "application")); + traceEvents.add(afterEvent6); + + final BeforeOperationEventRecord beforeEvent7 = new BeforeOperationEventRecord(14L, 1L, 12, + 0, "test.package.Clazz.F()", new HostApplicationMetaDataRecord("host", + "application")); + beforeEvent7.setRuntimeStatisticInformation(new RuntimeStatisticInformation(1L)); + traceEvents.add(beforeEvent7); + + final AfterOperationEventRecord afterEvent7 = new AfterOperationEventRecord(15L, 1L, 13, + new HostApplicationMetaDataRecord("host", "application")); + traceEvents.add(afterEvent7); + + final AfterOperationEventRecord afterEvent3 = new AfterOperationEventRecord(16L, 1L, 14, + new HostApplicationMetaDataRecord("host", "application")); + traceEvents.add(afterEvent3); + + final BeforeOperationEventRecord beforeEvent8 = new BeforeOperationEventRecord(17L, 1L, 15, + 0, "test.package.Clazz.B()", new HostApplicationMetaDataRecord("host", + "application")); + beforeEvent8.setRuntimeStatisticInformation(new RuntimeStatisticInformation(2L)); + traceEvents.add(beforeEvent8); + + final AfterOperationEventRecord afterEvent8 = new AfterOperationEventRecord(19L, 1L, 16, + new HostApplicationMetaDataRecord("host", "application")); + traceEvents.add(afterEvent8); + + final BeforeOperationEventRecord beforeEvent9 = new BeforeOperationEventRecord(20L, 1L, 17, + 0, "test.package.Clazz.C()", new HostApplicationMetaDataRecord("host", + "application")); + beforeEvent9.setRuntimeStatisticInformation(new RuntimeStatisticInformation(1L)); + traceEvents.add(beforeEvent9); + + final AfterOperationEventRecord afterEvent9 = new AfterOperationEventRecord(21L, 1L, 18, + new HostApplicationMetaDataRecord("host", "application")); + traceEvents.add(afterEvent9); + + final BeforeOperationEventRecord beforeEvent10 = new BeforeOperationEventRecord(22L, 1L, + 19, 0, "test.package.Clazz.D()", new HostApplicationMetaDataRecord("host", + "application")); + beforeEvent10.setRuntimeStatisticInformation(new RuntimeStatisticInformation(9L)); + traceEvents.add(beforeEvent10); + + final BeforeOperationEventRecord beforeEvent11 = new BeforeOperationEventRecord(23L, 1L, + 20, 0, "test.package.Clazz.E()", new HostApplicationMetaDataRecord("host", + "application")); + beforeEvent11.setRuntimeStatisticInformation(new RuntimeStatisticInformation(1L)); + traceEvents.add(beforeEvent11); + + final AfterOperationEventRecord afterEvent11 = new AfterOperationEventRecord(24L, 1L, 21, + new HostApplicationMetaDataRecord("host", "application")); + traceEvents.add(afterEvent11); + + final BeforeOperationEventRecord beforeEvent12 = new BeforeOperationEventRecord(25L, 1L, + 22, 0, "test.package.Clazz.F()", new HostApplicationMetaDataRecord("host", + "application")); + beforeEvent12.setRuntimeStatisticInformation(new RuntimeStatisticInformation(1L)); + traceEvents.add(beforeEvent12); + + final AfterOperationEventRecord afterEvent12 = new AfterOperationEventRecord(26L, 1L, 23, + new HostApplicationMetaDataRecord("host", "application")); + traceEvents.add(afterEvent12); + + final BeforeOperationEventRecord beforeEvent13 = new BeforeOperationEventRecord(27L, 1L, + 24, 0, "test.package.Clazz.E()", new HostApplicationMetaDataRecord("host", + "application")); + beforeEvent13.setRuntimeStatisticInformation(new RuntimeStatisticInformation(1L)); + traceEvents.add(beforeEvent13); + + final AfterOperationEventRecord afterEvent13 = new AfterOperationEventRecord(28L, 1L, 25, + new HostApplicationMetaDataRecord("host", "application")); + traceEvents.add(afterEvent13); + + final BeforeOperationEventRecord beforeEvent14 = new BeforeOperationEventRecord(29L, 1L, + 26, 0, "test.package.Clazz.F()", new HostApplicationMetaDataRecord("host", + "application")); + beforeEvent14.setRuntimeStatisticInformation(new RuntimeStatisticInformation(1L)); + traceEvents.add(beforeEvent14); + + final AfterOperationEventRecord afterEvent14 = new AfterOperationEventRecord(30L, 1L, 27, + new HostApplicationMetaDataRecord("host", "application")); + traceEvents.add(afterEvent14); + + final AfterOperationEventRecord afterEvent10 = new AfterOperationEventRecord(31L, 1L, 28, + new HostApplicationMetaDataRecord("host", "application")); + traceEvents.add(afterEvent10); + + final AfterOperationEventRecord afterEvent = new AfterOperationEventRecord(32L, 1L, 29, + new HostApplicationMetaDataRecord("host", "application")); + traceEvents.add(afterEvent); + + trace = new Trace(traceEvents, true); + } + + @Test + public void testReduction() { + final List<AbstractEventRecord> traceEvents = new ArrayList<AbstractEventRecord>(); + + final BeforeOperationEventRecord beforeEvent = new BeforeOperationEventRecord(1L, 1L, 0, 0, + "test.package.Clazz.A()", new HostApplicationMetaDataRecord("host", "application")); + beforeEvent.setRuntimeStatisticInformation(new RuntimeStatisticInformation(31L)); + traceEvents.add(beforeEvent); + + final BeforeOperationEventRecord beforeEvent1 = new BeforeOperationEventRecord(2L, 1L, 1, + 0, "test.package.Clazz.B()", new HostApplicationMetaDataRecord("host", + "application")); + beforeEvent1.setRuntimeStatisticInformation(new RuntimeStatisticInformation(2, 4, 8)); + traceEvents.add(beforeEvent1); + + final AfterOperationEventRecord afterEvent1 = new AfterOperationEventRecord(4L, 1L, 2, + new HostApplicationMetaDataRecord("host", "application")); + traceEvents.add(afterEvent1); + + final BeforeOperationEventRecord beforeEvent2 = new BeforeOperationEventRecord(5L, 1L, 3, + 0, "test.package.Clazz.C()", new HostApplicationMetaDataRecord("host", + "application")); + beforeEvent2.setRuntimeStatisticInformation(new RuntimeStatisticInformation(2, 2, 2)); + traceEvents.add(beforeEvent2); + + final AfterOperationEventRecord afterEvent2 = new AfterOperationEventRecord(6L, 1L, 4, + new HostApplicationMetaDataRecord("host", "application")); + traceEvents.add(afterEvent2); + + final BeforeOperationEventRecord beforeEvent3 = new BeforeOperationEventRecord(7L, 1L, 5, + 0, "test.package.Clazz.D()", new HostApplicationMetaDataRecord("host", + "application")); + beforeEvent3.setRuntimeStatisticInformation(new RuntimeStatisticInformation(2, 18, 162)); + traceEvents.add(beforeEvent3); + + final BeforeOperationEventRecord beforeEvent4 = new BeforeOperationEventRecord(8L, 1L, 6, + 0, "test.package.Clazz.E()", new HostApplicationMetaDataRecord("host", + "application")); + beforeEvent4.setRuntimeStatisticInformation(new RuntimeStatisticInformation(4, 4, 4)); + traceEvents.add(beforeEvent4); + + final AfterOperationEventRecord afterEvent4 = new AfterOperationEventRecord(9L, 1L, 7, + new HostApplicationMetaDataRecord("host", "application")); + traceEvents.add(afterEvent4); + + final BeforeOperationEventRecord beforeEvent5 = new BeforeOperationEventRecord(10L, 1L, 8, + 0, "test.package.Clazz.F()", new HostApplicationMetaDataRecord("host", + "application")); + beforeEvent5.setRuntimeStatisticInformation(new RuntimeStatisticInformation(4, 4, 4)); + traceEvents.add(beforeEvent5); + + final AfterOperationEventRecord afterEvent5 = new AfterOperationEventRecord(11L, 1L, 9, + new HostApplicationMetaDataRecord("host", "application")); + traceEvents.add(afterEvent5); + + final AfterOperationEventRecord afterEvent3 = new AfterOperationEventRecord(16L, 1L, 14, + new HostApplicationMetaDataRecord("host", "application")); + traceEvents.add(afterEvent3); + + final AfterOperationEventRecord afterEvent = new AfterOperationEventRecord(32L, 1L, 29, + new HostApplicationMetaDataRecord("host", "application")); + traceEvents.add(afterEvent); + + final Trace compareTrace = new Trace(traceEvents, true); + final PatternSummarizationFilter patternSummarizationFilter = new PatternSummarizationFilter( + null, PatternSummarizationFilter.DEFAULT_DISTANCE, + PatternSummarizationFilter.DEFAULT_NESTINGLEVEL); + final Trace reducedTrace = patternSummarizationFilter.testReduction(trace); + Assert.assertTrue(compareTrace.compareTo(reducedTrace) == 0); + + } + +}