From 834e48fc6d5dcc863e7aed984bbaf96987a92e84 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Thu, 11 Aug 2016 19:33:45 -0700 Subject: [PATCH] Display regular logs. --- .../com/beust/kobalt/internal/DynamicGraph.kt | 118 +++++++++++------- 1 file changed, 70 insertions(+), 48 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 c4e7330f..100d72ea 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 @@ -282,60 +282,82 @@ class DynamicGraphExecutor(val graph : DynamicGraph, val factory: IThreadW fun toSeconds(millis: Long) = (millis / 1000).toInt().toString() -// class CompressedLog(val timestamp: Long, val threadMap: HashMap) -// -// fun compressLog(historyLog: List): ArrayList { -// val compressed = arrayListOf() -// -// var currentLog: CompressedLog? = null -// -// historyLog.forEach { hl -> -// if (currentLog == null) { -// currentLog = CompressedLog(hl.timestamp, hashMapOf(hl.threadId to hl.name)) -// } else currentLog?.let { cl -> -// if (hl.timestamp - cl.timestamp < 1000) { -// cl.threadMap[hl.threadId] = hl.name -// } else { -// compressed.add(cl) -// currentLog = null -// } -// } -// } -// return compressed -// } -// -// compressLog(historyLog).forEach { -// val row = arrayListOf() -// row.add(toSeconds(it.timestamp)) -// it.threadMap.values.forEach { -// row.add(it) -// } -// table.addRow(row) -// } + fun displayCompressedLog(table: AsciiTable.Builder) : AsciiTable.Builder { + class CompressedLog(val timestamp: Long, val threadMap: HashMap) - val start = historyLog[0].timestamp - val projectStart = ConcurrentHashMap() - historyLog.forEach { line -> - val row = arrayListOf() - row.add(toSeconds(line.timestamp - start)) - threadIds.keys.forEach { - if (line.threadId == it) { - var duration = "" - if (line.start) { - projectStart[line.name] = line.timestamp - } else { - duration = " (" + ((line.timestamp - projectStart[line.name]!!) / 1000) - .toInt().toString() + ")" + fun compressLog(historyLog: List): ArrayList { + val compressed = arrayListOf() + + var currentLog: CompressedLog? = null + + val projectStart = hashMapOf() + historyLog.forEach { 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 + } else { + compressed.add(cl) + currentLog = null + } } - row.add((line.name + duration)) - } else { - row.add("") } + return compressed } - table.addRow(row) + + compressLog(historyLog).forEach { + val row = arrayListOf() + row.add(toSeconds(it.timestamp)) + it.threadMap.values.forEach { + row.add(it) + } + table.addRow(row) + } + + return table } - println(table.build()) + fun displayRegularLog(table: AsciiTable.Builder) : AsciiTable.Builder { + val start = historyLog[0].timestamp + val projectStart = ConcurrentHashMap() + historyLog.forEach { line -> + val row = arrayListOf() + row.add(toSeconds(line.timestamp - start)) + threadIds.keys.forEach { + if (line.threadId == it) { + var duration = "" + if (line.start) { + projectStart[line.name] = line.timestamp + } else { + duration = " (" + ((line.timestamp - projectStart[line.name]!!) / 1000) + .toInt().toString() + ")" + } + row.add((line.name + duration)) + } else { + row.add("") + } + } + table.addRow(row) + } + return table + } + + println(displayRegularLog(table).build()) } }