diff --git a/src/Application.kt b/src/Application.kt index eebae99..8ef404e 100644 --- a/src/Application.kt +++ b/src/Application.kt @@ -17,30 +17,29 @@ fun Application.module(testing: Boolean = false) { runBlocking { val cachedFile = File("/app/wave.wav").readBytes() val gson = GsonBuilder().setPrettyPrinting().create() - var startTime: Instant + var startTime : Instant var elapsed = Duration.ofSeconds(0) val targetTime = Duration.ofSeconds(System.getenv("WAITTIME").toLong()) var currIter = 1 - val timestamps = LinkedHashMap() - var currTimeStamp: Instant + val timestamps = LinkedHashMap() + var currTimeStamp : Instant val uploader = Uploader() val processResults = ProcessResults() environment.monitor.subscribe(ApplicationStarted) { - println("Starting benchmark") - startTime = Instant.now() - while (elapsed < targetTime) { - GlobalScope.launch { + val job = GlobalScope.launch { + println("Starting benchmark") + startTime = Instant.now() + while(elapsed < targetTime){ uploader.uploadData(currIter, gson, cachedFile) + currIter+=1 + currTimeStamp = Instant.now() + timestamps[currIter] = currTimeStamp + elapsed = Duration.between(startTime, currTimeStamp) } - currIter += 1 - currTimeStamp = Instant.now() - timestamps[currIter] = currTimeStamp - elapsed = Duration.between(startTime, currTimeStamp) + println("Benchmark ended") + processResults.mapToProcess = timestamps + processResults.process() } - println("Benchmark ended") - processResults.mapToProcess = timestamps - processResults.process() - } } } \ No newline at end of file