Commit e124dfdc authored by Sören Henning's avatar Sören Henning

removed kieker components (they are now in kiekpad)

parent 384873c5
package teead.kieker;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.HashMap;
import java.util.Map;
import kieker.common.record.flow.IFlowRecord;
import kieker.common.record.flow.trace.TraceMetadata;
import kieker.common.record.flow.trace.operation.AbstractOperationEvent;
import kieker.common.record.flow.trace.operation.AfterOperationEvent;
import kieker.common.record.flow.trace.operation.AfterOperationFailedEvent;
import kieker.common.record.flow.trace.operation.BeforeOperationEvent;
import teetime.stage.basic.AbstractTransformation;
public class KiekerAdapterStage extends AbstractTransformation<IFlowRecord, MonitoringRecord> {
private final Map<Long, Trace> traces = new HashMap<>();
@Override
protected void execute(final IFlowRecord record) {
if (record instanceof TraceMetadata) {
this.handleMetadataRecord((TraceMetadata) record);
} else if (record instanceof AbstractOperationEvent) {
this.handleOperationEventRecord((AbstractOperationEvent) record);
}
}
private void handleMetadataRecord(final TraceMetadata record) {
// Create a new trace buffer for the new incoming trace
final long traceID = record.getTraceId();
final Trace trace = new Trace(record);
this.traces.put(traceID, trace);
}
private void handleOperationEventRecord(final AbstractOperationEvent event) {
// Check whether there was an incoming trace meta data record before
if (this.traces.get(event.getTraceId()) != null) {
if (event instanceof BeforeOperationEvent) {
this.handleBeforeOperationEventRecord((BeforeOperationEvent) event);
} else if (event instanceof AfterOperationEvent) {
this.handleAfterOperationEventRecord((AfterOperationEvent) event);
}
} else {
// TODO how to handle this?
}
}
private void handleBeforeOperationEventRecord(final BeforeOperationEvent event) {
this.traces.get(event.getTraceId()).pushEvent(event);
}
private void handleAfterOperationEventRecord(final AfterOperationEvent event) {
final Trace trace = this.traces.get(event.getTraceId());
final BeforeOperationEvent beforeEvent = trace.popEvent();
if (trace.isEmpty()) {
this.traces.remove(event.getTraceId());
}
if (event instanceof AfterOperationFailedEvent) {
// TODO
}
MonitoringRecord record = new MonitoringRecord();
record.setOperationSignature(event.getOperationSignature());
record.setClassSignature(event.getClassSignature());
record.setHostname(trace.getHostname());
record.setSessionId(trace.getSessionId());
record.setThreadId(trace.getThreadId());
record.setTimestamp(beforeEvent.getTimestamp());
record.setDuration(event.getTimestamp() - beforeEvent.getTimestamp());
this.outputPort.send(record);
}
private class Trace {
private final Deque<BeforeOperationEvent> buffer = new ArrayDeque<>();
private final String hostname;
private final String sessionId;
private final long threadId;
public Trace(final TraceMetadata record) {
this.hostname = record.getHostname();
this.sessionId = record.getSessionId();
this.threadId = record.getThreadId();
}
public void pushEvent(final BeforeOperationEvent event) {
this.buffer.push(event);
}
public BeforeOperationEvent popEvent() {
return this.buffer.pop();
}
public boolean isEmpty() {
return this.buffer.isEmpty();
}
public String getHostname() {
return hostname;
}
public String getSessionId() {
return sessionId;
}
public long getThreadId() {
return threadId;
}
}
}
package teead.kieker;
public class MonitoringRecord {
private String operationSignature;
private String classSignature;
private String hostname;
private String sessionId;
private long threadId;
// Java 8 Instant could be more useful
private long timestamp; // timestamp in nanoseconds returned by System.nanoTime()
// Java 8 Duration could be more useful
private long duration; // in nanoseconds
public MonitoringRecord() {}
public MonitoringRecord(final String operationSignature, final String classSignature, final String hostname, final String sessionId, final long threadId,
final long timestamp, final long duration) {
this.operationSignature = operationSignature;
this.classSignature = classSignature;
this.hostname = hostname;
this.sessionId = sessionId;
this.threadId = threadId;
this.timestamp = timestamp;
this.duration = duration;
}
public String getOperationSignature() {
return operationSignature;
}
public void setOperationSignature(final String operationSignature) {
this.operationSignature = operationSignature;
}
public String getClassSignature() {
return classSignature;
}
public void setClassSignature(final String classSignature) {
this.classSignature = classSignature;
}
public String getHostname() {
return hostname;
}
public void setHostname(final String hostname) {
this.hostname = hostname;
}
public String getSessionId() {
return sessionId;
}
public void setSessionId(final String sessionId) {
this.sessionId = sessionId;
}
public long getThreadId() {
return threadId;
}
public void setThreadId(final long threadId) {
this.threadId = threadId;
}
public long getTimestamp() {
return timestamp;
}
public void setTimestamp(final long timestamp) {
this.timestamp = timestamp;
}
public long getDuration() {
return duration;
}
public void setDuration(final long duration) {
this.duration = duration;
}
}
package teead.kieker;
import java.time.Instant;
import teead.measurement.Measurement;
import teetime.stage.basic.AbstractTransformation;
public class RecordConverterStage extends AbstractTransformation<MonitoringRecord, Measurement> {
@Override
protected void execute(final MonitoringRecord record) {
// TODO This is wrong! record.getTimestamp() delivers nanoseconds relative to
// an fixed arbitrary time...
final Instant time = Instant.ofEpochMilli(record.getTimestamp());
final double value = record.getDuration();
final Measurement measurement = new Measurement(time, value);
this.outputPort.send(measurement);
}
}
package teead.kieker;
import teead.util.Filter;
import teetime.framework.CompositeStage;
import teetime.framework.InputPort;
import teetime.framework.OutputPort;
import teetime.stage.basic.distributor.Distributor;
import teetime.stage.basic.distributor.strategy.CopyByReferenceStrategy;
public class RecordDistributorStage extends CompositeStage {
private final InputPort<MonitoringRecord> inputPort;
private final Distributor<MonitoringRecord> distributor;
public RecordDistributorStage() {
this.distributor = new Distributor<>(new CopyByReferenceStrategy());
this.inputPort = this.distributor.getInputPort();
}
public OutputPort<MonitoringRecord> getNewOutputPort(final RecordFilter filter) {
final Filter<MonitoringRecord> filterStage = new Filter<>(filter);
super.connectPorts(this.distributor.getNewOutputPort(), filterStage.getInputPort());
return filterStage.getOutputPort();
}
public InputPort<MonitoringRecord> getInputPort() {
return this.inputPort;
}
}
package teead.kieker;
import java.util.function.Predicate;
public class RecordFilter implements Predicate<MonitoringRecord> {
private String operationSignature = null;
private String classSignature = null;
private String hostname = null;
private String sessionId = null;
private Long threadId = null;
public RecordFilter() {}
public void setOperationSignature(final String operationSignature) {
this.operationSignature = operationSignature;
}
public void setClassSignature(final String classSignature) {
this.classSignature = classSignature;
}
public void setHostname(final String hostname) {
this.hostname = hostname;
}
public void setSessionId(final String sessionId) {
this.sessionId = sessionId;
}
public void setThreadId(final long threadId) {
this.threadId = threadId;
}
@Override
public boolean test(final MonitoringRecord record) {
if (this.operationSignature != null && !this.operationSignature.equals(record.getOperationSignature())) {
return false;
}
if (this.classSignature != null && !this.classSignature.equals(record.getClassSignature())) {
return false;
}
if (this.hostname != null && !this.hostname.equals(record.getHostname())) {
return false;
}
if (this.sessionId != null && !this.sessionId.equals(record.getSessionId())) {
return false;
}
if (this.threadId != null && this.threadId.longValue() != record.getThreadId()) {
return false;
}
return true;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment