summaryrefslogtreecommitdiff
path: root/opendc-trace/opendc-trace-swf/src/main
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 /opendc-trace/opendc-trace-swf/src/main
parent214480d154771f0b783829b6e5ec82b837304ad2 (diff)
refactor(trace): Implement trace API for SWF reader
This change updates the SWF trace reader to support the new streaming trace API.
Diffstat (limited to 'opendc-trace/opendc-trace-swf/src/main')
-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.kt43
-rw-r--r--opendc-trace/opendc-trace-swf/src/main/resources/META-INF/services/org.opendc.trace.spi.TraceFormat1
5 files changed, 315 insertions, 0 deletions
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-trace/opendc-trace-swf/src/main/kotlin/org/opendc/trace/swf/SwfTraceFormat.kt b/opendc-trace/opendc-trace-swf/src/main/kotlin/org/opendc/trace/swf/SwfTraceFormat.kt
new file mode 100644
index 00000000..36c3122e
--- /dev/null
+++ b/opendc-trace/opendc-trace-swf/src/main/kotlin/org/opendc/trace/swf/SwfTraceFormat.kt
@@ -0,0 +1,43 @@
+/*
+ * 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.trace.swf
+
+import org.opendc.trace.spi.TraceFormat
+import java.net.URL
+import java.nio.file.Paths
+import kotlin.io.path.exists
+
+/**
+ * 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"
+
+ 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