From 39c1b6f8d39c29e3dcee72262191003fd0eb889d Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Thu, 11 Aug 2016 22:32:58 -0800 Subject: [PATCH] Playing with thread log display. --- .../com/beust/kobalt/internal/DynamicGraph.kt | 38 +++++++++++-------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/DynamicGraph.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/DynamicGraph.kt index 100d72ea..c618472c 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/DynamicGraph.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/DynamicGraph.kt @@ -189,7 +189,7 @@ class DynamicGraphExecutor(val graph : DynamicGraph, val factory: IThreadW = Executors.newFixedThreadPool(threadCount, NamedThreadFactory("DynamicGraphExecutor")) val completion = ExecutorCompletionService>(executor) - class HistoryLog(val name: String, val timestamp: Long, val threadId: Long, val start: Boolean) + data class HistoryLog(val name: String, val timestamp: Long, val threadId: Long, val start: Boolean) val historyLog = arrayListOf() val threadIds = ConcurrentHashMap() @@ -283,7 +283,7 @@ class DynamicGraphExecutor(val graph : DynamicGraph, val factory: IThreadW fun toSeconds(millis: Long) = (millis / 1000).toInt().toString() fun displayCompressedLog(table: AsciiTable.Builder) : AsciiTable.Builder { - class CompressedLog(val timestamp: Long, val threadMap: HashMap) + data class CompressedLog(val timestamp: Long, val threadMap: HashMap) fun compressLog(historyLog: List): ArrayList { val compressed = arrayListOf() @@ -291,29 +291,35 @@ class DynamicGraphExecutor(val graph : DynamicGraph, val factory: IThreadW var currentLog: CompressedLog? = null val projectStart = hashMapOf() + fun toName(hl: HistoryLog) : String { + var duration = "" + if (! hl.start) { + val start = projectStart[hl.name] + if (start != null) { + duration = " (" + ((hl.timestamp - start) / 1000) + .toInt().toString() + ")" + } else { + println("DONOTCOMMIT") + } + } + return hl.name + duration + } + historyLog.forEach { hl -> + println("CURRENT LOG: " + currentLog + " HISTORY LINE: " + hl) if (hl.start) { projectStart[hl.name] = hl.timestamp } if (currentLog == null) { currentLog = CompressedLog(hl.timestamp, hashMapOf(hl.threadId to hl.name)) } else currentLog?.let { cl -> - if (hl.timestamp - cl.timestamp < 1000) { - var duration = "" - if (! hl.start) { - val start = projectStart[hl.name] - if (start != null) { - duration = " (" + ((hl.timestamp - start) / 1000) - .toInt().toString() + ")" - } else { - println("DONOTCOMMIT") - } - } - - cl.threadMap[hl.threadId] = hl.name + duration + if (! hl.start || hl.timestamp - cl.timestamp < 1000) { + println(" CURRENT LOG IS WITHING ONE SECOND: $hl") + cl.threadMap[hl.threadId] = toName(hl) } else { + println(" ADDING COMPRESSED LINE $cl") compressed.add(cl) - currentLog = null + currentLog = CompressedLog(hl.timestamp, hashMapOf(hl.threadId to toName(hl))) } } }