summaryrefslogtreecommitdiff
path: root/opendc-trace/opendc-trace-azure/src/main
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2021-10-11 09:38:45 +0200
committerFabian Mastenbroek <mail.fabianm@gmail.com>2021-10-25 16:36:35 +0200
commit6fe536c63a70eec9a378b2f82a925f8063bf787a (patch)
tree942ac4315d28dde0f156fbea3964a01062ff51e9 /opendc-trace/opendc-trace-azure/src/main
parenta41cd2504f15f3e3e49eb533faca390911cc5110 (diff)
refactor(trace): Support GZIP files in Azure trace
This change updates the Azure VM trace format implementation to directly support loading a trace in GZIP format in order to prevent users having to decompress the trace files so they can be opened by OpenDC.
Diffstat (limited to 'opendc-trace/opendc-trace-azure/src/main')
-rw-r--r--opendc-trace/opendc-trace-azure/src/main/kotlin/org/opendc/trace/azure/AzureTraceFormat.kt17
1 files changed, 11 insertions, 6 deletions
diff --git a/opendc-trace/opendc-trace-azure/src/main/kotlin/org/opendc/trace/azure/AzureTraceFormat.kt b/opendc-trace/opendc-trace-azure/src/main/kotlin/org/opendc/trace/azure/AzureTraceFormat.kt
index 253c7057..c9982877 100644
--- a/opendc-trace/opendc-trace-azure/src/main/kotlin/org/opendc/trace/azure/AzureTraceFormat.kt
+++ b/opendc-trace/opendc-trace-azure/src/main/kotlin/org/opendc/trace/azure/AzureTraceFormat.kt
@@ -31,8 +31,9 @@ import org.opendc.trace.util.CompositeTableReader
import java.nio.file.Files
import java.nio.file.Path
import java.util.stream.Collectors
-import kotlin.io.path.extension
-import kotlin.io.path.nameWithoutExtension
+import java.util.zip.GZIPInputStream
+import kotlin.io.path.inputStream
+import kotlin.io.path.name
/**
* A format implementation for the Azure v1 format.
@@ -81,7 +82,10 @@ public class AzureTraceFormat : TraceFormat {
override fun newReader(path: Path, table: String): TableReader {
return when (table) {
- TABLE_RESOURCES -> AzureResourceTableReader(factory.createParser(path.resolve("vmtable/vmtable.csv").toFile()))
+ TABLE_RESOURCES -> {
+ val stream = GZIPInputStream(path.resolve("vmtable/vmtable.csv.gz").inputStream())
+ AzureResourceTableReader(factory.createParser(stream))
+ }
TABLE_RESOURCE_STATES -> newResourceStateReader(path)
else -> throw IllegalArgumentException("Table $table not supported")
}
@@ -96,8 +100,8 @@ public class AzureTraceFormat : TraceFormat {
*/
private fun newResourceStateReader(path: Path): TableReader {
val partitions = Files.walk(path.resolve("vm_cpu_readings"), 1)
- .filter { !Files.isDirectory(it) && it.extension == "csv" }
- .collect(Collectors.toMap({ it.nameWithoutExtension }, { it }))
+ .filter { !Files.isDirectory(it) && it.name.endsWith(".csv.gz") }
+ .collect(Collectors.toMap({ it.name.removeSuffix(".csv.gz") }, { it }))
.toSortedMap()
val it = partitions.iterator()
@@ -105,7 +109,8 @@ public class AzureTraceFormat : TraceFormat {
override fun nextReader(): TableReader? {
return if (it.hasNext()) {
val (_, partPath) = it.next()
- return AzureResourceStateTableReader(factory.createParser(partPath.toFile()))
+ val stream = GZIPInputStream(partPath.inputStream())
+ return AzureResourceStateTableReader(factory.createParser(stream))
} else {
null
}