Skip to content
Snippets Groups Projects
Commit 920b41b0 authored by Sören Henning's avatar Sören Henning
Browse files

moved statistics (maybe not final)

parent 1d77e82f
No related branches found
No related tags found
No related merge requests found
......@@ -9,8 +9,8 @@ import kieker.analysis.domain.systemdependency.Component;
import kieker.analysis.domain.systemdependency.Container;
import kieker.analysis.domain.systemdependency.Operation;
import kieker.analysis.domain.systemdependency.SoftwareSystem;
import kieker.analysis.traceanalysisutil.Statistics;
import kieker.analysis.traceanalysisutil.StatisticsUtility;
import kieker.analysis.util.Statistics;
import kieker.analysis.util.StatisticsUtility;
import teetime.stage.basic.AbstractTransformation;
......
......@@ -8,8 +8,8 @@ import kieker.analysis.domain.systemdependency.Component;
import kieker.analysis.domain.systemdependency.Container;
import kieker.analysis.domain.systemdependency.Operation;
import kieker.analysis.domain.systemdependency.SoftwareSystem;
import kieker.analysis.traceanalysisutil.Statistics;
import kieker.analysis.traceanalysisutil.StatisticsUtility;
import kieker.analysis.util.Statistics;
import kieker.analysis.util.StatisticsUtility;
import teetime.stage.basic.AbstractTransformation;
......
/***************************************************************************
* Copyright 2015 Kieker Project (http://kieker-monitoring.net)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
package kieker.analysis.stage.tracediagnosis;
import java.util.ArrayList;
import java.util.List;
import kieker.analysis.domain.AggregatedOperationCall;
import kieker.analysis.domain.AggregatedTrace;
import kieker.analysis.domain.OperationCall;
import kieker.analysis.domain.Trace;
import kieker.analysis.traceanalysisutil.Statistics;
import kieker.analysis.traceanalysisutil.StatisticsUtility;
import teetime.stage.basic.AbstractTransformation;
/**
* This class is a {@code TeeTime} stage adding statistics (via the corresponding setters) to instances of {@link AggregatedTrace}. The traces are forwarded to the
* output port.
*
* @author Nils Christian Ehmke
*/
public final class AggregatedTraceStatisticsDecorator extends AbstractTransformation<AggregatedTrace, AggregatedTrace> {
@Override
public void execute(final AggregatedTrace trace) {
AggregatedTraceStatisticsDecorator.addNumberOfCalls(trace.getRootOperationCall(), trace.getTraces().size());
AggregatedTraceStatisticsDecorator.addDurationStatistics(trace);
// The references are no longer needed
trace.getTraces().clear();
super.getOutputPort().send(trace);
}
private static void addNumberOfCalls(final AggregatedOperationCall call, final int calls) {
call.setCalls(calls);
for (final AggregatedOperationCall child : call.getChildren()) {
AggregatedTraceStatisticsDecorator.addNumberOfCalls(child, calls);
}
}
private static void addDurationStatistics(final AggregatedTrace trace) {
final TraceDurationVisitor traceDurationVisitor = new TraceDurationVisitor();
for (final Trace t : trace.getTraces()) {
traceDurationVisitor.visit(t);
}
traceDurationVisitor.addDurationStatistics(trace);
}
/**
* @author Nils Christian Ehmke
*/
private static final class TraceDurationVisitor {
private final List<List<Long>> durationsPerEdge = new ArrayList<>();
private int edgeIndex;
public void visit(final Trace trace) {
this.edgeIndex = -1;
this.visit(trace.getRootOperationCall());
}
private void visit(final OperationCall rootOperationCall) {
this.edgeIndex++;
if (this.durationsPerEdge.size() <= this.edgeIndex) {
this.durationsPerEdge.add(new ArrayList<Long>());
}
final List<Long> durationsOfCurrentEdge = this.durationsPerEdge.get(this.edgeIndex);
durationsOfCurrentEdge.add(rootOperationCall.getDuration());
for (final OperationCall child : rootOperationCall.getChildren()) {
this.visit(child);
}
}
public void addDurationStatistics(final AggregatedTrace trace) {
this.edgeIndex = -1;
this.addDurationStatistics(trace.getRootOperationCall());
}
private void addDurationStatistics(final AggregatedOperationCall rootOperationCall) {
this.edgeIndex++;
final List<Long> durationsOfCurrentEdge = this.durationsPerEdge.get(this.edgeIndex);
final Statistics statistics = StatisticsUtility.calculateStatistics(durationsOfCurrentEdge);
rootOperationCall.setMinDuration(statistics.getMinDuration());
rootOperationCall.setMaxDuration(statistics.getMaxDuration());
rootOperationCall.setMeanDuration(statistics.getMeanDuration());
rootOperationCall.setTotalDuration(statistics.getTotalDuration());
rootOperationCall.setMedianDuration(statistics.getMedianDuration());
for (final AggregatedOperationCall child : rootOperationCall.getChildren()) {
this.addDurationStatistics(child);
}
}
}
}
/***************************************************************************
* Copyright 2015 Kieker Project (http://kieker-monitoring.net)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
package kieker.analysis.stage.tracediagnosis;
import java.util.ArrayList;
import java.util.List;
import kieker.analysis.domain.AggregatedOperationCall;
import kieker.analysis.domain.AggregatedTrace;
import kieker.analysis.domain.OperationCall;
import kieker.analysis.domain.Trace;
import kieker.analysis.util.Statistics;
import kieker.analysis.util.StatisticsUtility;
import teetime.stage.basic.AbstractTransformation;
/**
* This class is a {@code TeeTime} stage adding statistics (via the corresponding setters) to instances of {@link AggregatedTrace}. The traces are forwarded to the
* output port.
*
* @author Nils Christian Ehmke
*/
public final class AggregatedTraceStatisticsDecorator extends AbstractTransformation<AggregatedTrace, AggregatedTrace> {
@Override
public void execute(final AggregatedTrace trace) {
AggregatedTraceStatisticsDecorator.addNumberOfCalls(trace.getRootOperationCall(), trace.getTraces().size());
AggregatedTraceStatisticsDecorator.addDurationStatistics(trace);
// The references are no longer needed
trace.getTraces().clear();
super.getOutputPort().send(trace);
}
private static void addNumberOfCalls(final AggregatedOperationCall call, final int calls) {
call.setCalls(calls);
for (final AggregatedOperationCall child : call.getChildren()) {
AggregatedTraceStatisticsDecorator.addNumberOfCalls(child, calls);
}
}
private static void addDurationStatistics(final AggregatedTrace trace) {
final TraceDurationVisitor traceDurationVisitor = new TraceDurationVisitor();
for (final Trace t : trace.getTraces()) {
traceDurationVisitor.visit(t);
}
traceDurationVisitor.addDurationStatistics(trace);
}
/**
* @author Nils Christian Ehmke
*/
private static final class TraceDurationVisitor {
private final List<List<Long>> durationsPerEdge = new ArrayList<>();
private int edgeIndex;
public void visit(final Trace trace) {
this.edgeIndex = -1;
this.visit(trace.getRootOperationCall());
}
private void visit(final OperationCall rootOperationCall) {
this.edgeIndex++;
if (this.durationsPerEdge.size() <= this.edgeIndex) {
this.durationsPerEdge.add(new ArrayList<Long>());
}
final List<Long> durationsOfCurrentEdge = this.durationsPerEdge.get(this.edgeIndex);
durationsOfCurrentEdge.add(rootOperationCall.getDuration());
for (final OperationCall child : rootOperationCall.getChildren()) {
this.visit(child);
}
}
public void addDurationStatistics(final AggregatedTrace trace) {
this.edgeIndex = -1;
this.addDurationStatistics(trace.getRootOperationCall());
}
private void addDurationStatistics(final AggregatedOperationCall rootOperationCall) {
this.edgeIndex++;
final List<Long> durationsOfCurrentEdge = this.durationsPerEdge.get(this.edgeIndex);
final Statistics statistics = StatisticsUtility.calculateStatistics(durationsOfCurrentEdge);
rootOperationCall.setMinDuration(statistics.getMinDuration());
rootOperationCall.setMaxDuration(statistics.getMaxDuration());
rootOperationCall.setMeanDuration(statistics.getMeanDuration());
rootOperationCall.setTotalDuration(statistics.getTotalDuration());
rootOperationCall.setMedianDuration(statistics.getMedianDuration());
for (final AggregatedOperationCall child : rootOperationCall.getChildren()) {
this.addDurationStatistics(child);
}
}
}
}
/***************************************************************************
* Copyright 2015 Kieker Project (http://kieker-monitoring.net)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
package kieker.analysis.stage.tracediagnosis;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import kieker.analysis.domain.AggregatedOperationCall;
import kieker.analysis.domain.OperationCall;
import kieker.analysis.traceanalysisutil.Statistics;
import kieker.analysis.traceanalysisutil.StatisticsUtility;
import teetime.stage.basic.AbstractTransformation;
/**
* @author Nils Christian Ehmke
*/
public final class OperationCallAggregator extends AbstractTransformation<OperationCall, AggregatedOperationCall> {
private final Map<String, List<OperationCall>> aggregationMap = new HashMap<>();
@Override
protected void execute(final OperationCall call) {
final String key = call.getIdentifierWithFailure();
if (!this.aggregationMap.containsKey(key)) {
final List<OperationCall> aggregationList = new ArrayList<>();
this.aggregationMap.put(key, aggregationList);
}
this.aggregationMap.get(key).add(call);
}
@Override
public void onTerminating() throws Exception {
for (final List<OperationCall> aggregationList : this.aggregationMap.values()) {
final List<Long> durations = this.extractDurations(aggregationList);
final Statistics statistics = StatisticsUtility.calculateStatistics(durations);
super.getOutputPort().send(
new AggregatedOperationCall(aggregationList.get(0).getContainer(), aggregationList.get(0).getComponent(), aggregationList.get(0).getOperation(),
aggregationList.get(0).getOrderIndex(), aggregationList.get(0).getFailedCause(), statistics.getTotalDuration(),
statistics.getMedianDuration(), statistics.getMinDuration(), statistics.getMaxDuration(), statistics.getMeanDuration(),
aggregationList.size()));
}
super.onTerminating();
}
private List<Long> extractDurations(final List<OperationCall> callList) {
final List<Long> result = new ArrayList<>();
for (final OperationCall call : callList) {
result.add(call.getDuration());
}
return result;
}
}
/***************************************************************************
* Copyright 2015 Kieker Project (http://kieker-monitoring.net)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
package kieker.analysis.stage.tracediagnosis;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import kieker.analysis.domain.AggregatedOperationCall;
import kieker.analysis.domain.OperationCall;
import kieker.analysis.util.Statistics;
import kieker.analysis.util.StatisticsUtility;
import teetime.stage.basic.AbstractTransformation;
/**
* @author Nils Christian Ehmke
*/
public final class OperationCallAggregator extends AbstractTransformation<OperationCall, AggregatedOperationCall> {
private final Map<String, List<OperationCall>> aggregationMap = new HashMap<>();
@Override
protected void execute(final OperationCall call) {
final String key = call.getIdentifierWithFailure();
if (!this.aggregationMap.containsKey(key)) {
final List<OperationCall> aggregationList = new ArrayList<>();
this.aggregationMap.put(key, aggregationList);
}
this.aggregationMap.get(key).add(call);
}
@Override
public void onTerminating() throws Exception {
for (final List<OperationCall> aggregationList : this.aggregationMap.values()) {
final List<Long> durations = this.extractDurations(aggregationList);
final Statistics statistics = StatisticsUtility.calculateStatistics(durations);
super.getOutputPort().send(
new AggregatedOperationCall(aggregationList.get(0).getContainer(), aggregationList.get(0).getComponent(), aggregationList.get(0).getOperation(),
aggregationList.get(0).getOrderIndex(), aggregationList.get(0).getFailedCause(), statistics.getTotalDuration(),
statistics.getMedianDuration(), statistics.getMinDuration(), statistics.getMaxDuration(), statistics.getMeanDuration(),
aggregationList.size()));
}
super.onTerminating();
}
private List<Long> extractDurations(final List<OperationCall> callList) {
final List<Long> result = new ArrayList<>();
for (final OperationCall call : callList) {
result.add(call.getDuration());
}
return result;
}
}
/***************************************************************************
* Copyright 2015 Kieker Project (http://kieker-monitoring.net)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
package kieker.analysis.traceanalysisutil;
/**
* @author Nils Christian Ehmke
*/
public final class Statistics {
private final long totalDuration;
private final long meanDuration;
private final long medianDuration;
private final long minDuration;
private final long maxDuration;
public Statistics(final long totalDuration, final long meanDuration, final long medianDuration, final long minDuration, final long maxDuration) {
this.totalDuration = totalDuration;
this.meanDuration = meanDuration;
this.medianDuration = medianDuration;
this.minDuration = minDuration;
this.maxDuration = maxDuration;
}
public long getTotalDuration() {
return this.totalDuration;
}
public long getMeanDuration() {
return this.meanDuration;
}
public long getMedianDuration() {
return this.medianDuration;
}
public long getMinDuration() {
return this.minDuration;
}
public long getMaxDuration() {
return this.maxDuration;
}
}
/***************************************************************************
* Copyright 2015 Kieker Project (http://kieker-monitoring.net)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
package kieker.analysis.util;
/**
* @author Nils Christian Ehmke
*/
public final class Statistics {
private final long totalDuration;
private final long meanDuration;
private final long medianDuration;
private final long minDuration;
private final long maxDuration;
public Statistics(final long totalDuration, final long meanDuration, final long medianDuration, final long minDuration, final long maxDuration) {
this.totalDuration = totalDuration;
this.meanDuration = meanDuration;
this.medianDuration = medianDuration;
this.minDuration = minDuration;
this.maxDuration = maxDuration;
}
public long getTotalDuration() {
return this.totalDuration;
}
public long getMeanDuration() {
return this.meanDuration;
}
public long getMedianDuration() {
return this.medianDuration;
}
public long getMinDuration() {
return this.minDuration;
}
public long getMaxDuration() {
return this.maxDuration;
}
}
/***************************************************************************
* Copyright 2015 Kieker Project (http://kieker-monitoring.net)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
package kieker.analysis.traceanalysisutil;
import java.util.Collections;
import java.util.List;
/**
* @author Nils Christian Ehmke
*/
public final class StatisticsUtility {
private StatisticsUtility() {}
public static Statistics calculateStatistics(final List<Long> durations) {
Collections.sort(durations);
long totalDuration = 0;
for (final Long duration : durations) {
totalDuration += duration;
}
final long minDuration = durations.get(0);
final long maxDuration = durations.get(durations.size() - 1);
final long meanDuration = totalDuration / durations.size();
final long medianDuration = durations.get(durations.size() / 2);
return new Statistics(totalDuration, meanDuration, medianDuration, minDuration, maxDuration);
}
}
/***************************************************************************
* Copyright 2015 Kieker Project (http://kieker-monitoring.net)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
package kieker.analysis.util;
import java.util.Collections;
import java.util.List;
/**
* @author Nils Christian Ehmke
*/
public final class StatisticsUtility {
private StatisticsUtility() {}
public static Statistics calculateStatistics(final List<Long> durations) {
Collections.sort(durations);
long totalDuration = 0;
for (final Long duration : durations) {
totalDuration += duration;
}
final long minDuration = durations.get(0);
final long maxDuration = durations.get(durations.size() - 1);
final long meanDuration = totalDuration / durations.size();
final long medianDuration = durations.get(durations.size() / 2);
return new Statistics(totalDuration, meanDuration, medianDuration, minDuration, maxDuration);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment