summaryrefslogtreecommitdiff
path: root/opendc-simulator
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2021-10-28 15:18:38 +0200
committerFabian Mastenbroek <mail.fabianm@gmail.com>2021-11-02 13:56:50 +0100
commit79a2f31c800c23539c413771a3f893c423275372 (patch)
tree014c96695dd0889db041c6f73f5332d22004e3fc /opendc-simulator
parenta8e2d460a3b6803845687585ae0b34e67a9445a3 (diff)
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.
Diffstat (limited to 'opendc-simulator')
-rw-r--r--opendc-simulator/opendc-simulator-compute/src/main/kotlin/org/opendc/simulator/compute/workload/SimTrace.kt31
1 files changed, 27 insertions, 4 deletions
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
}