summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2021-08-31 18:08:14 +0200
committerFabian Mastenbroek <mail.fabianm@gmail.com>2021-09-02 11:30:15 +0200
commit5c6bf9739aa0ffd9651df4fcb4cd46a8545144f0 (patch)
tree9ec1f1b9db295b2d24e008aea9a48c07e498c96a
parent214480d154771f0b783829b6e5ec82b837304ad2 (diff)
refactor(trace): Implement trace API for SWF reader
This change updates the SWF trace reader to support the new streaming trace API.
-rw-r--r--opendc-format/src/main/kotlin/org/opendc/format/trace/swf/SwfTraceReader.kt176
-rw-r--r--opendc-trace/opendc-trace-swf/build.gradle.kts35
-rw-r--r--opendc-trace/opendc-trace-swf/src/main/kotlin/org/opendc/trace/swf/SwfTaskTable.kt63
-rw-r--r--opendc-trace/opendc-trace-swf/src/main/kotlin/org/opendc/trace/swf/SwfTaskTableReader.kt162
-rw-r--r--opendc-trace/opendc-trace-swf/src/main/kotlin/org/opendc/trace/swf/SwfTrace.kt46
-rw-r--r--opendc-trace/opendc-trace-swf/src/main/kotlin/org/opendc/trace/swf/SwfTraceFormat.kt (renamed from opendc-format/src/test/kotlin/org/opendc/format/trace/swf/SwfTraceReaderTest.kt)34
-rw-r--r--opendc-trace/opendc-trace-swf/src/main/resources/META-INF/services/org.opendc.trace.spi.TraceFormat1
-rw-r--r--opendc-trace/opendc-trace-swf/src/test/kotlin/org/opendc/trace/swf/SwfTraceFormatTest.kt107
-rw-r--r--opendc-trace/opendc-trace-swf/src/test/resources/trace.swf (renamed from opendc-format/src/test/resources/swf_trace.txt)0
-rw-r--r--settings.gradle.kts1
10 files changed, 431 insertions, 194 deletions
diff --git a/opendc-format/src/main/kotlin/org/opendc/format/trace/swf/SwfTraceReader.kt b/opendc-format/src/main/kotlin/org/opendc/format/trace/swf/SwfTraceReader.kt
deleted file mode 100644
index bda392a9..00000000
--- a/opendc-format/src/main/kotlin/org/opendc/format/trace/swf/SwfTraceReader.kt
+++ /dev/null
@@ -1,176 +0,0 @@
-/*
- * Copyright (c) 2020 AtLarge Research
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package org.opendc.format.trace.swf
-
-import org.opendc.format.trace.TraceEntry
-import org.opendc.format.trace.TraceReader
-import org.opendc.simulator.compute.workload.SimTraceWorkload
-import org.opendc.simulator.compute.workload.SimWorkload
-import java.io.BufferedReader
-import java.io.File
-import java.io.FileReader
-import java.util.*
-
-/**
- * A [TraceReader] for reading SWF traces into VM-modeled workloads.
- *
- * The standard is defined by the PWA, see here: https://www.cse.huji.ac.il/labs/parallel/workload/swf.html
- *
- * @param file The trace file.
- */
-public class SwfTraceReader(
- file: File,
- maxNumCores: Int = -1
-) : TraceReader<SimWorkload> {
- /**
- * The internal iterator to use for this reader.
- */
- private val iterator: Iterator<TraceEntry<SimWorkload>>
-
- /**
- * Initialize the reader.
- */
- init {
- val entries = mutableMapOf<Long, TraceEntry<SimWorkload>>()
-
- val jobNumberCol = 0
- val submitTimeCol = 1 // seconds (begin of trace is 0)
- val waitTimeCol = 2 // seconds
- val runTimeCol = 3 // seconds
- val numAllocatedCoresCol = 4 // We assume that single-core processors were used at the time
- val requestedMemoryCol = 9 // KB per processor/core (-1 if not specified)
-
- val sliceDuration = 5 * 60L
-
- var jobNumber: Long
- var submitTime: Long
- var waitTime: Long
- var runTime: Long
- var cores: Int
- var memory: Long
- var slicedWaitTime: Long
- var runtimePartialSliceRemainder: Long
-
- BufferedReader(FileReader(file)).use { reader ->
- reader.lineSequence()
- .filter { line ->
- // Ignore comments in the trace
- !line.startsWith(";") && line.isNotBlank()
- }
- .forEach { line ->
- val values = line.trim().split("\\s+".toRegex())
-
- jobNumber = values[jobNumberCol].trim().toLong()
- submitTime = values[submitTimeCol].trim().toLong()
- waitTime = values[waitTimeCol].trim().toLong()
- runTime = values[runTimeCol].trim().toLong()
- cores = values[numAllocatedCoresCol].trim().toInt()
- memory = values[requestedMemoryCol].trim().toLong()
-
- if (maxNumCores != -1 && cores > maxNumCores) {
- println("Skipped a task due to processor count ($cores > $maxNumCores).")
- return@forEach
- }
-
- if (memory == -1L) {
- memory = 1000L * cores // assume 1GB of memory per processor if not specified
- } else {
- memory /= 1000 // convert KB to MB
- }
-
- val flopsHistory = mutableListOf<SimTraceWorkload.Fragment>()
-
- // Insert waiting time slices
-
- // We ignore wait time remainders under one
- slicedWaitTime = 0L
- if (waitTime >= sliceDuration) {
- for (tick in submitTime until (submitTime + waitTime - sliceDuration) step sliceDuration) {
- flopsHistory.add(
- SimTraceWorkload.Fragment(
- tick,
- sliceDuration * 1000,
- 0.0,
- cores
- )
- )
- slicedWaitTime += sliceDuration
- }
- }
-
- // Insert run time slices
-
- runtimePartialSliceRemainder = runTime % sliceDuration
-
- for (
- tick in (submitTime + slicedWaitTime)
- until (submitTime + slicedWaitTime + runTime - sliceDuration)
- step sliceDuration
- ) {
- flopsHistory.add(
- SimTraceWorkload.Fragment(
- tick,
- sliceDuration * 1000L,
- 1.0,
- cores
- )
- )
- }
-
- if (runtimePartialSliceRemainder > 0) {
- flopsHistory.add(
- SimTraceWorkload.Fragment(
- submitTime + slicedWaitTime + runTime,
- sliceDuration,
- runtimePartialSliceRemainder / sliceDuration.toDouble(),
- cores
- )
- )
- }
-
- val uuid = UUID(0L, jobNumber)
- val workload = SimTraceWorkload(flopsHistory.asSequence())
- entries[jobNumber] = TraceEntry(
- uuid,
- jobNumber.toString(),
- submitTime,
- workload,
- mapOf(
- "cores" to cores,
- "required-memory" to memory,
- "workload" to workload
- )
- )
- }
- }
-
- // Create the entry iterator
- iterator = entries.values.sortedBy { it.start }.iterator()
- }
-
- override fun hasNext(): Boolean = iterator.hasNext()
-
- override fun next(): TraceEntry<SimWorkload> = iterator.next()
-
- override fun close() {}
-}
diff --git a/opendc-trace/opendc-trace-swf/build.gradle.kts b/opendc-trace/opendc-trace-swf/build.gradle.kts
new file mode 100644
index 00000000..c9eaa78d
--- /dev/null
+++ b/opendc-trace/opendc-trace-swf/build.gradle.kts
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2021 AtLarge Research
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+description = "Support for Standard Workload Format (SWF) traces in OpenDC"
+
+/* Build configuration */
+plugins {
+ `kotlin-library-conventions`
+ `testing-conventions`
+ `jacoco-conventions`
+}
+
+dependencies {
+ api(platform(projects.opendcPlatform))
+ api(projects.opendcTrace.opendcTraceApi)
+}
diff --git a/opendc-trace/opendc-trace-swf/src/main/kotlin/org/opendc/trace/swf/SwfTaskTable.kt b/opendc-trace/opendc-trace-swf/src/main/kotlin/org/opendc/trace/swf/SwfTaskTable.kt
new file mode 100644
index 00000000..12a51a2f
--- /dev/null
+++ b/opendc-trace/opendc-trace-swf/src/main/kotlin/org/opendc/trace/swf/SwfTaskTable.kt
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2021 AtLarge Research
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package org.opendc.trace.swf
+
+import org.opendc.trace.*
+import java.nio.file.Path
+import kotlin.io.path.bufferedReader
+
+/**
+ * A [Table] containing the tasks in a SWF trace.
+ */
+internal class SwfTaskTable(private val path: Path) : Table {
+ override val name: String = TABLE_TASKS
+
+ override val isSynthetic: Boolean = false
+
+ override fun isSupported(column: TableColumn<*>): Boolean {
+ return when (column) {
+ TASK_ID -> true
+ TASK_SUBMIT_TIME -> true
+ TASK_WAIT_TIME -> true
+ TASK_RUNTIME -> true
+ TASK_REQ_NCPUS -> true
+ TASK_ALLOC_NCPUS -> true
+ TASK_PARENTS -> true
+ TASK_STATUS -> true
+ TASK_GROUP_ID -> true
+ TASK_USER_ID -> true
+ else -> false
+ }
+ }
+
+ override fun newReader(): TableReader {
+ val reader = path.bufferedReader()
+ return SwfTaskTableReader(reader)
+ }
+
+ override fun newReader(partition: String): TableReader {
+ throw IllegalArgumentException("Invalid partition $partition")
+ }
+
+ override fun toString(): String = "SwfTaskTable"
+}
diff --git a/opendc-trace/opendc-trace-swf/src/main/kotlin/org/opendc/trace/swf/SwfTaskTableReader.kt b/opendc-trace/opendc-trace-swf/src/main/kotlin/org/opendc/trace/swf/SwfTaskTableReader.kt
new file mode 100644
index 00000000..5f879a54
--- /dev/null
+++ b/opendc-trace/opendc-trace-swf/src/main/kotlin/org/opendc/trace/swf/SwfTaskTableReader.kt
@@ -0,0 +1,162 @@
+/*
+ * Copyright (c) 2021 AtLarge Research
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package org.opendc.trace.swf
+
+import org.opendc.trace.*
+import java.io.BufferedReader
+
+/**
+ * A [TableReader] implementation for the SWF format.
+ */
+internal class SwfTaskTableReader(private val reader: BufferedReader) : TableReader {
+ /**
+ * The current row.
+ */
+ private var fields = emptyList<String>()
+
+ /**
+ * A [Regex] object to match whitespace.
+ */
+ private val whitespace = "\\s+".toRegex()
+
+ override fun nextRow(): Boolean {
+ var line: String
+ var num = 0
+
+ while (true) {
+ line = reader.readLine() ?: return false
+ num++
+
+ if (line.isBlank()) {
+ // Ignore empty lines
+ continue
+ } else if (line.startsWith(";")) {
+ // Ignore comments for now
+ continue
+ }
+
+ break
+ }
+
+ fields = line.trim().split(whitespace)
+
+ if (fields.size < 18) {
+ throw IllegalArgumentException("Invalid format at line $line")
+ }
+
+ return true
+ }
+
+ override fun hasColumn(column: TableColumn<*>): Boolean {
+ return when (column) {
+ TASK_ID -> true
+ TASK_SUBMIT_TIME -> true
+ TASK_WAIT_TIME -> true
+ TASK_RUNTIME -> true
+ TASK_REQ_NCPUS -> true
+ TASK_ALLOC_NCPUS -> true
+ TASK_PARENTS -> true
+ TASK_STATUS -> true
+ TASK_GROUP_ID -> true
+ TASK_USER_ID -> true
+ else -> false
+ }
+ }
+
+ override fun <T> get(column: TableColumn<T>): T {
+ val res: Any = when (column) {
+ TASK_ID -> getLong(TASK_ID)
+ TASK_SUBMIT_TIME -> getLong(TASK_SUBMIT_TIME)
+ TASK_WAIT_TIME -> getLong(TASK_WAIT_TIME)
+ TASK_RUNTIME -> getLong(TASK_RUNTIME)
+ TASK_REQ_NCPUS -> getInt(TASK_REQ_NCPUS)
+ TASK_ALLOC_NCPUS -> getInt(TASK_ALLOC_NCPUS)
+ TASK_PARENTS -> {
+ val parent = fields[COL_PARENT_JOB].toLong(10)
+ if (parent < 0) emptySet() else setOf(parent)
+ }
+ TASK_STATUS -> getInt(TASK_STATUS)
+ TASK_GROUP_ID -> getInt(TASK_GROUP_ID)
+ TASK_USER_ID -> getInt(TASK_USER_ID)
+ else -> throw IllegalArgumentException("Invalid column")
+ }
+
+ @Suppress("UNCHECKED_CAST")
+ return res as T
+ }
+
+ override fun getBoolean(column: TableColumn<Boolean>): Boolean {
+ throw IllegalArgumentException("Invalid column")
+ }
+
+ override fun getInt(column: TableColumn<Int>): Int {
+ return when (column) {
+ TASK_REQ_NCPUS -> fields[COL_REQ_NCPUS].toInt(10)
+ TASK_ALLOC_NCPUS -> fields[COL_ALLOC_NCPUS].toInt(10)
+ TASK_STATUS -> fields[COL_STATUS].toInt(10)
+ TASK_GROUP_ID -> fields[COL_GROUP_ID].toInt(10)
+ TASK_USER_ID -> fields[COL_USER_ID].toInt(10)
+ else -> throw IllegalArgumentException("Invalid column")
+ }
+ }
+
+ override fun getLong(column: TableColumn<Long>): Long {
+ return when (column) {
+ TASK_ID -> fields[COL_JOB_ID].toLong(10)
+ TASK_SUBMIT_TIME -> fields[COL_SUBMIT_TIME].toLong(10)
+ TASK_WAIT_TIME -> fields[COL_WAIT_TIME].toLong(10)
+ TASK_RUNTIME -> fields[COL_RUN_TIME].toLong(10)
+ else -> throw IllegalArgumentException("Invalid column")
+ }
+ }
+
+ override fun getDouble(column: TableColumn<Double>): Double {
+ throw IllegalArgumentException("Invalid column")
+ }
+
+ override fun close() {
+ reader.close()
+ }
+
+ /**
+ * Default column indices for the SWF format.
+ */
+ private val COL_JOB_ID = 0
+ private val COL_SUBMIT_TIME = 1
+ private val COL_WAIT_TIME = 2
+ private val COL_RUN_TIME = 3
+ private val COL_ALLOC_NCPUS = 4
+ private val COL_AVG_CPU_TIME = 5
+ private val COL_USED_MEM = 6
+ private val COL_REQ_NCPUS = 7
+ private val COL_REQ_TIME = 8
+ private val COL_REQ_MEM = 9
+ private val COL_STATUS = 10
+ private val COL_USER_ID = 11
+ private val COL_GROUP_ID = 12
+ private val COL_EXEC_NUM = 13
+ private val COL_QUEUE_NUM = 14
+ private val COL_PART_NUM = 15
+ private val COL_PARENT_JOB = 16
+ private val COL_PARENT_THINK_TIME = 17
+}
diff --git a/opendc-trace/opendc-trace-swf/src/main/kotlin/org/opendc/trace/swf/SwfTrace.kt b/opendc-trace/opendc-trace-swf/src/main/kotlin/org/opendc/trace/swf/SwfTrace.kt
new file mode 100644
index 00000000..d4da735e
--- /dev/null
+++ b/opendc-trace/opendc-trace-swf/src/main/kotlin/org/opendc/trace/swf/SwfTrace.kt
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2021 AtLarge Research
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package org.opendc.trace.swf
+
+import org.opendc.trace.TABLE_TASKS
+import org.opendc.trace.Table
+import org.opendc.trace.Trace
+import java.nio.file.Path
+
+/**
+ * [Trace] implementation for the SWF format.
+ */
+public class SwfTrace internal constructor(private val path: Path) : Trace {
+ override val tables: List<String> = listOf(TABLE_TASKS)
+
+ override fun containsTable(name: String): Boolean = TABLE_TASKS == name
+
+ override fun getTable(name: String): Table? {
+ if (!containsTable(name)) {
+ return null
+ }
+ return SwfTaskTable(path)
+ }
+
+ override fun toString(): String = "SwfTrace[$path]"
+}
diff --git a/opendc-format/src/test/kotlin/org/opendc/format/trace/swf/SwfTraceReaderTest.kt b/opendc-trace/opendc-trace-swf/src/main/kotlin/org/opendc/trace/swf/SwfTraceFormat.kt
index e0e049cf..36c3122e 100644
--- a/opendc-format/src/test/kotlin/org/opendc/format/trace/swf/SwfTraceReaderTest.kt
+++ b/opendc-trace/opendc-trace-swf/src/main/kotlin/org/opendc/trace/swf/SwfTraceFormat.kt
@@ -20,26 +20,24 @@
* SOFTWARE.
*/
-package org.opendc.format.trace.swf
+package org.opendc.trace.swf
-import org.junit.jupiter.api.Assertions.assertEquals
-import org.junit.jupiter.api.Test
-import org.opendc.simulator.compute.workload.SimTraceWorkload
-import java.io.File
+import org.opendc.trace.spi.TraceFormat
+import java.net.URL
+import java.nio.file.Paths
+import kotlin.io.path.exists
-class SwfTraceReaderTest {
- @Test
- internal fun testParseSwf() {
- val reader = SwfTraceReader(File(SwfTraceReaderTest::class.java.getResource("/swf_trace.txt").toURI()))
- var entry = reader.next()
- assertEquals(0, entry.start)
- // 1961 slices for waiting, 3 full and 1 partial running slices
- assertEquals(1965, (entry.workload as SimTraceWorkload).trace.toList().size)
+/**
+ * Support for the Standard Workload Format (SWF) in OpenDC.
+ *
+ * The standard is defined by the PWA, see here: https://www.cse.huji.ac.il/labs/parallel/workload/swf.html
+ */
+public class SwfTraceFormat : TraceFormat {
+ override val name: String = "swf"
- entry = reader.next()
- assertEquals(164472, entry.start)
- // 1188 slices for waiting, 0 full and 1 partial running slices
- assertEquals(1189, (entry.workload as SimTraceWorkload).trace.toList().size)
- assertEquals(0.25, (entry.workload as SimTraceWorkload).trace.toList().last().usage)
+ override fun open(url: URL): SwfTrace {
+ val path = Paths.get(url.toURI())
+ require(path.exists()) { "URL $url does not exist" }
+ return SwfTrace(path)
}
}
diff --git a/opendc-trace/opendc-trace-swf/src/main/resources/META-INF/services/org.opendc.trace.spi.TraceFormat b/opendc-trace/opendc-trace-swf/src/main/resources/META-INF/services/org.opendc.trace.spi.TraceFormat
new file mode 100644
index 00000000..6c6b0eb2
--- /dev/null
+++ b/opendc-trace/opendc-trace-swf/src/main/resources/META-INF/services/org.opendc.trace.spi.TraceFormat
@@ -0,0 +1 @@
+org.opendc.trace.swf.SwfTraceFormat
diff --git a/opendc-trace/opendc-trace-swf/src/test/kotlin/org/opendc/trace/swf/SwfTraceFormatTest.kt b/opendc-trace/opendc-trace-swf/src/test/kotlin/org/opendc/trace/swf/SwfTraceFormatTest.kt
new file mode 100644
index 00000000..9686891b
--- /dev/null
+++ b/opendc-trace/opendc-trace-swf/src/test/kotlin/org/opendc/trace/swf/SwfTraceFormatTest.kt
@@ -0,0 +1,107 @@
+/*
+ * Copyright (c) 2021 AtLarge Research
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package org.opendc.trace.swf
+
+import org.junit.jupiter.api.*
+import org.junit.jupiter.api.Assertions.*
+import org.opendc.trace.TABLE_TASKS
+import org.opendc.trace.TASK_ALLOC_NCPUS
+import org.opendc.trace.TASK_ID
+import java.net.URL
+
+/**
+ * Test suite for the [SwfTraceFormat] class.
+ */
+internal class SwfTraceFormatTest {
+ @Test
+ fun testTraceExists() {
+ val input = checkNotNull(SwfTraceFormatTest::class.java.getResource("/trace.swf"))
+ val format = SwfTraceFormat()
+ assertDoesNotThrow {
+ format.open(input)
+ }
+ }
+
+ @Test
+ fun testTraceDoesNotExists() {
+ val input = checkNotNull(SwfTraceFormatTest::class.java.getResource("/trace.swf"))
+ val format = SwfTraceFormat()
+ assertThrows<IllegalArgumentException> {
+ format.open(URL(input.toString() + "help"))
+ }
+ }
+
+ @Test
+ fun testTables() {
+ val input = checkNotNull(SwfTraceFormatTest::class.java.getResource("/trace.swf"))
+ val trace = SwfTraceFormat().open(input)
+
+ assertEquals(listOf(TABLE_TASKS), trace.tables)
+ }
+
+ @Test
+ fun testTableExists() {
+ val input = checkNotNull(SwfTraceFormatTest::class.java.getResource("/trace.swf"))
+ val table = SwfTraceFormat().open(input).getTable(TABLE_TASKS)
+
+ assertNotNull(table)
+ assertDoesNotThrow { table!!.newReader() }
+ }
+
+ @Test
+ fun testTableDoesNotExist() {
+ val input = checkNotNull(SwfTraceFormatTest::class.java.getResource("/trace.swf"))
+ val trace = SwfTraceFormat().open(input)
+
+ assertFalse(trace.containsTable("test"))
+ assertNull(trace.getTable("test"))
+ }
+
+ @Test
+ fun testReader() {
+ val input = checkNotNull(SwfTraceFormatTest::class.java.getResource("/trace.swf"))
+ val trace = SwfTraceFormat().open(input)
+ val reader = trace.getTable(TABLE_TASKS)!!.newReader()
+
+ assertAll(
+ { assertTrue(reader.nextRow()) },
+ { assertEquals(1, reader.getLong(TASK_ID)) },
+ { assertEquals(306, reader.getInt(TASK_ALLOC_NCPUS)) },
+ { assertTrue(reader.nextRow()) },
+ { assertEquals(2, reader.getLong(TASK_ID)) },
+ { assertEquals(17, reader.getInt(TASK_ALLOC_NCPUS)) },
+ )
+
+ reader.close()
+ }
+
+ @Test
+ fun testReaderPartition() {
+ val input = checkNotNull(SwfTraceFormatTest::class.java.getResource("/trace.swf"))
+ val trace = SwfTraceFormat().open(input)
+
+ assertThrows<IllegalArgumentException> {
+ trace.getTable(TABLE_TASKS)!!.newReader("test")
+ }
+ }
+}
diff --git a/opendc-format/src/test/resources/swf_trace.txt b/opendc-trace/opendc-trace-swf/src/test/resources/trace.swf
index c3ecf890..c3ecf890 100644
--- a/opendc-format/src/test/resources/swf_trace.txt
+++ b/opendc-trace/opendc-trace-swf/src/test/resources/trace.swf
diff --git a/settings.gradle.kts b/settings.gradle.kts
index fd1d404a..73d9a151 100644
--- a/settings.gradle.kts
+++ b/settings.gradle.kts
@@ -48,6 +48,7 @@ include(":opendc-telemetry:opendc-telemetry-api")
include(":opendc-telemetry:opendc-telemetry-sdk")
include(":opendc-trace:opendc-trace-api")
include(":opendc-trace:opendc-trace-gwf")
+include(":opendc-trace:opendc-trace-swf")
include(":opendc-trace:opendc-trace-bitbrains")
include(":opendc-trace:opendc-trace-parquet")
include(":opendc-harness:opendc-harness-api")