From 79a2f31c800c23539c413771a3f893c423275372 Mon Sep 17 00:00:00 2001 From: Fabian Mastenbroek Date: Thu, 28 Oct 2021 15:18:38 +0200 Subject: refactor(trace): Support gaps in trace data This change updates the implementation of the trace converter and SimTrace implementation to support cases where there is a gap between samples in the trace data. This change allows users to specify what to do in case samples are missing in the trace. The available options are specified in `SimTrace.FillMode`. Currently, we support either carrying the previous value forward or set the usage to zero. --- .../opendc/simulator/compute/workload/SimTrace.kt | 31 +++++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) (limited to 'opendc-simulator') diff --git a/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/workload/SimTrace.kt b/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/workload/SimTrace.kt index 4f567b55..4cf60605 100644 --- a/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/workload/SimTrace.kt +++ b/opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/workload/SimTrace.kt @@ -104,9 +104,28 @@ public class SimTrace( /** * Construct a new [FlowSource] for the specified [cpu]. + * + * @param cpu The [ProcessingUnit] for which to create the source. + * @param offset The time offset to use for the trace. + * @param fillMode The [FillMode] for filling missing data. */ - public fun newSource(cpu: ProcessingUnit, offset: Long): FlowSource { - return CpuConsumer(cpu, offset, usageCol, timestampCol, deadlineCol, coresCol, size) + public fun newSource(cpu: ProcessingUnit, offset: Long, fillMode: FillMode = FillMode.None): FlowSource { + return CpuConsumer(cpu, offset, fillMode, usageCol, timestampCol, deadlineCol, coresCol, size) + } + + /** + * An enumeration describing the modes for filling missing data. + */ + public enum class FillMode { + /** + * When a gap in the trace data occurs, the CPU usage will be set to zero. + */ + None, + + /** + * When a gap in the trace data occurs, the previous CPU usage will be used. + */ + Previous } /** @@ -183,6 +202,7 @@ public class SimTrace( private class CpuConsumer( cpu: ProcessingUnit, private val offset: Long, + private val fillMode: FillMode, private val usageCol: DoubleArray, private val timestampCol: LongArray, private val deadlineCol: LongArray, @@ -217,9 +237,12 @@ public class SimTrace( _idx = idx val timestamp = timestampCol[idx] - // Fragment is in the future + // There is a gap in the trace, since the next fragment starts in the future. if (timestamp > nowOffset) { - conn.push(0.0) + when (fillMode) { + FillMode.None -> conn.push(0.0) // Reset rate to zero + FillMode.Previous -> {} // Keep previous rate + } return timestamp - nowOffset } -- cgit v1.2.3