Skip to content

Commit a365f4e

Browse files
committed
Improve logging time spent on concrete and conversion
1 parent 4362bd2 commit a365f4e

File tree

1 file changed

+13
-8
lines changed
  • utbot-junit-contest/src/main/kotlin/org/utbot/contest/usvm

1 file changed

+13
-8
lines changed

utbot-junit-contest/src/main/kotlin/org/utbot/contest/usvm/ContestUsvm.kt

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ import org.utbot.fuzzer.UtFuzzedExecution
4747
import org.utbot.summary.usvm.summarizeAll
4848
import java.io.File
4949
import java.net.URLClassLoader
50-
import kotlin.system.measureTimeMillis
5150
import kotlin.time.Duration.Companion.milliseconds
5251

5352
private val logger = KotlinLogging.logger {}
@@ -168,7 +167,7 @@ fun runUsvmGeneration(
168167
methods = jcMethods,
169168
targets = emptyList()
170169
) { state ->
171-
val jcExecution = accumulateMeasureTime("executor.execute(${cut.classId.name})", timeStats) {
170+
val jcExecution = accumulateMeasureTime("executor.execute(${cut.classId.name})", timeStats, state.entrypoint) {
172171
runCatching {
173172
executor.execute(state.entrypoint.typedMethod, state)
174173
}.getOrElse { e ->
@@ -177,7 +176,7 @@ fun runUsvmGeneration(
177176
}
178177
}
179178
val methodId = jcExecution.method.method.toExecutableId(jcContainer.cp)
180-
val utExecution = accumulateMeasureTime("JcToUtExecutionConverter.convert(${cut.classId.name})", timeStats) {
179+
val utExecution = accumulateMeasureTime("JcToUtExecutionConverter.convert(${cut.classId.name})", timeStats, jcExecution.method.method) {
181180
runCatching {
182181
JcToUtExecutionConverter(
183182
jcExecution = jcExecution,
@@ -281,14 +280,20 @@ fun JcMachine.analyzeAsync(
281280
} ?: logger.error { "analyzeAsync time exceeded hard time out" }
282281
}
283282

284-
inline fun <T> accumulateMeasureTime(
283+
private inline fun <T> accumulateMeasureTime(
285284
regionName: String,
286285
timeAccumulatorMillis: MutableMap<String, Long>,
286+
warnData: Any?,
287+
millisWarnThreshold: Long = 2_000,
287288
block: () -> T
288289
): T {
289-
var res: T
290-
timeAccumulatorMillis[regionName] = (timeAccumulatorMillis[regionName] ?: 0) + measureTimeMillis {
291-
res = block()
290+
val millisBefore = System.currentTimeMillis()
291+
try {
292+
return block()
293+
} finally {
294+
val millisTaken = System.currentTimeMillis() - millisBefore
295+
if (millisTaken > millisWarnThreshold)
296+
logger.warn("Spent $millisTaken ms on region [$regionName] for [$warnData]")
297+
timeAccumulatorMillis[regionName] = (timeAccumulatorMillis[regionName] ?: 0) + millisTaken
292298
}
293-
return res
294299
}

0 commit comments

Comments
 (0)