Commit 2b2eefcd authored by Noric Couderc's avatar Noric Couderc

Optimization: Implemented more efficient loading

The function uses the fact that rows in trace files are ordered
to make more efficient loading of the traces.
parent 7f76ee7e
......@@ -26,7 +26,7 @@ class TraceLoader {
data class TraceData(val location : String,
val object_id : Int,
val target_type : String,
val methods : List<String>)
val methods : MutableList<String>)
/**
* A class that represents many similar traces
......@@ -59,6 +59,36 @@ class TraceLoader {
}
}
/**
* Implementation of readCsvData that uses the fact that rows
* are sorted by object id and step.
* @param reader: The reader for the CSV file
* @param tsv: If the file is in TSV format or not
* @return a list of traces
*/
fun readCsvDataEfficient(reader : Reader, tsv : Boolean) : List<TraceData> {
val parser = if (tsv) CSVParser(reader, CSVFormat.TDF.withHeader())
else CSVParser(reader, CSVFormat.DEFAULT.withHeader())
var traces = ArrayList<TraceData>()
var currentTrace : TraceData? = null
for (record in parser) {
// Two cases, either we need to create a new trace
val object_id = Integer.parseInt(record["id"])
if (traces.isEmpty()
|| currentTrace!!.object_id != object_id) {
currentTrace = TraceData(
record["location"],
object_id,
record["target_type"],
mutableListOf(record["method"])
)
traces.add(currentTrace)
} else {
// Or we need to add a method to the previous trace
currentTrace.methods.add(record["method"])
}
}
return traces
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment