Skip to content
Snippets Groups Projects
Commit 436d8020 authored by Bjoern Weissenfels's avatar Bjoern Weissenfels
Browse files

add reduction techniques

parent 56641d2a
No related branches found
No related tags found
No related merge requests found
Showing
with 1278 additions and 3 deletions
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);
}
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;
}
}
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);
}
}
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);
}
}
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");
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
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;
}
}
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;
}
}
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;
}
}
}
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;
}
}
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;
}
}
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;
}
}
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;
}
}
}
...@@ -8,7 +8,7 @@ import explorviz.live_trace_processing.filter.ITraceSink; ...@@ -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.ITraceReconstruction;
import explorviz.live_trace_processing.filter.reconstruction.TraceReconstructionFilter; import explorviz.live_trace_processing.filter.reconstruction.TraceReconstructionFilter;
import explorviz.live_trace_processing.filter.reduction.ITraceReduction; 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; import explorviz.live_trace_processing.reader.TCPReader;
public class FilterConfiguration { public class FilterConfiguration {
...@@ -17,8 +17,12 @@ public class FilterConfiguration { ...@@ -17,8 +17,12 @@ public class FilterConfiguration {
// final IRecordCounting recordCounting = new // final IRecordCounting recordCounting = new
// RecordCountingFilter(sink); // RecordCountingFilter(sink);
final ITraceReduction traceReduction = new TracePatternSummarizationFilter( final ITraceReduction traceReduction = new RemoveConstructorsFilter(sink);
TimeUnit.MILLISECONDS.toNanos(990), sink); // final ITraceReduction traceReduction = new
// TreeSummarization(recordCounting);
// final ITraceReduction traceReduction = new
// TracePatternSummarizationFilter(
// TimeUnit.MILLISECONDS.toNanos(990), sink);
final ITraceReconstruction traceReconstruction = new TraceReconstructionFilter( final ITraceReconstruction traceReconstruction = new TraceReconstructionFilter(
TimeUnit.SECONDS.toNanos(4), traceReduction); TimeUnit.SECONDS.toNanos(4), traceReduction);
......
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);
}
}
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);
}
}
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);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment