diff --git a/src/main/kotlin/me/msoucy/gbat/Analyze.kt b/src/main/kotlin/me/msoucy/gbat/Analyze.kt index c26f62f..6721d44 100644 --- a/src/main/kotlin/me/msoucy/gbat/Analyze.kt +++ b/src/main/kotlin/me/msoucy/gbat/Analyze.kt @@ -11,9 +11,6 @@ import me.msoucy.gbat.models.LineModel import me.msoucy.gbat.models.RiskModel fun analyze( - repoRoot : String, - projectRoot : String, - fname : String, riskModel : RiskModel, createdConstant : Double, historyItem : HistoryItem, @@ -35,7 +32,13 @@ fun analyze( } } - return condenseAnalysis(repoRoot, projectRoot, fname, lineModel, knowledgeModel, riskModel) + return condenseAnalysis( + historyItem.repoRoot.path, + historyItem.projectRoot.path, + historyItem.fname.path, + lineModel, + knowledgeModel, + riskModel) } private fun condenseAnalysis( diff --git a/src/main/kotlin/me/msoucy/gbat/Main.kt b/src/main/kotlin/me/msoucy/gbat/Main.kt index 94ce2d0..a4fe5ae 100644 --- a/src/main/kotlin/me/msoucy/gbat/Main.kt +++ b/src/main/kotlin/me/msoucy/gbat/Main.kt @@ -1,5 +1,8 @@ package me.msoucy.gbat +import me.msoucy.gbat.models.RiskModel +import me.msoucy.gbat.models.SummaryModel + import java.io.File import java.util.concurrent.Executors import kotlin.math.pow @@ -7,12 +10,17 @@ import kotlin.system.exitProcess import kotlin.text.Regex import kotlin.text.RegexOption import kotlin.text.startsWith +import kotlinx.coroutines.* +import kotlinx.coroutines.flow.* import com.xenomachina.argparser.ArgParser import com.xenomachina.argparser.InvalidArgumentException import com.xenomachina.argparser.default import com.xenomachina.argparser.mainBody +import org.jetbrains.exposed.sql.* +import org.jetbrains.exposed.sql.transactions.transaction + val REALLY_LONG_TIME = 864000 val DEFAULT_INTERESTING_RES = mutableListOf( "\\.java$", @@ -64,7 +72,7 @@ class GbatArgs(parser: ArgParser) { // Tuning options val risk_threshold by parser.storing("--risk-threshold", help="Threshold past which to summarize risk (defaults to default bus risk cubed)") { toDouble() }.default(null) - val creation_constant by parser.storing("--knowledge-creation-constant", help="How much knowledge a changed line should create if a new line creates 1 (defaults to 0.1)") { toDouble() }.default(null) + val creation_constant by parser.storing("--knowledge-creation-constant", help="How much knowledge a changed line should create if a new line creates 1 (defaults to 0.1)") { toDouble() }.default(0.1) // Misc options val git_exe by parser.storing("--git-exe", help="Path to the git executable", transform=::validateGit).default("git").addValidator { validateGit(value) } @@ -102,7 +110,7 @@ fun main(args: Array) = mainBody { throw InvalidArgumentException("Provided project root does not exist") } - val repo = GitRepo(project_root_file, validateGit(git_exe)) + val repo = GitRepo(projectRootFile, validateGit(git_exe)) fun String.isInteresting() : Boolean { var hasInterest = interesting_res.any { it.containsMatchIn(this) } @@ -124,15 +132,26 @@ fun main(args: Array) = mainBody { System.err.println("Found ${fnames.size} interesting files") } - val pool = Executors.newFixedThreadPool(num_analyzer_procs + num_git_procs + 1) + val riskModel = RiskModel(riskThresh, default_bus_risk, risk_file, departed) - fnames.forEach { fname -> - pool.submit { - parseHistory(repo, projectRootFile, File(fname)) + val dbFname = File(outDir, "summary.db") + val summaryDb = Database.connect(dbFname.absolutePath, "org.sqlite.JDBC") + transaction(summaryDb) { + exec("PRAGMA journal_mode = OFF") + exec("PRAGMA synchronous = OFF") + } + val summaryModel = SummaryModel(summaryDb) + + runBlocking { + flow { + fnames.forEach { fname -> + emit(parseHistory(repo, projectRootFile, File(fname))) + } + }.map { history -> + analyze(riskModel, creation_constant, history, verbose) + }.collect { analysis -> + summaryModel.summarize(analysis) } } - - val summ_result = mutableListOf() - val dbFname = File(outDir, "summary.db") } }