Skip to content

Commit 212ba1d

Browse files
committed
[concrete-executor-logs]
fixes #870 Moved logs in RuntimeTraceStorage and DynamicClassTransformer to ChildProcess.kt logging system
1 parent daa8aaa commit 212ba1d

File tree

3 files changed

+14
-16
lines changed

3 files changed

+14
-16
lines changed

utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/agent/DynamicClassTransformer.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package org.utbot.instrumentation.agent
22

33
import org.utbot.common.asPathToFile
44
import org.utbot.framework.plugin.api.util.UtContext
5+
import org.utbot.instrumentation.process.logError
6+
import org.utbot.instrumentation.process.logInfo
57
import java.lang.instrument.ClassFileTransformer
68
import java.security.ProtectionDomain
79

@@ -30,13 +32,13 @@ class DynamicClassTransformer : ClassFileTransformer {
3032
return if (pathToClassfile in pathsToUserClasses ||
3133
packsToAlwaysTransform.any(className::startsWith)
3234
) {
33-
System.err.println("Transforming: $className")
35+
logInfo { "Transforming: $className" }
3436
transformer.transform(loader, className, classBeingRedefined, protectionDomain, classfileBuffer)
3537
} else {
3638
null
3739
}
3840
} catch (e: Throwable) {
39-
System.err.println("Error while transforming: ${e.stackTraceToString()}")
41+
logError { "Error while transforming: ${e.stackTraceToString()}" }
4042
throw e
4143
} finally {
4244
UtContext.currentContext()?.stopWatch?.start()

utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/et/TraceHandler.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import org.objectweb.asm.MethodVisitor
99
import org.objectweb.asm.Opcodes
1010
import org.objectweb.asm.Type
1111
import org.objectweb.asm.commons.LocalVariablesSorter
12+
import org.utbot.instrumentation.process.logDebug
1213

1314
sealed class InstructionData {
1415
abstract val line: Int
@@ -151,7 +152,7 @@ object RuntimeTraceStorage {
151152
this.`$__trace__`[current] = id
152153
this.`$__counter__` = current + 1
153154
} else {
154-
System.err.println("Stack overflow (increase stack size Settings.TRACE_ARRAY_SIZE)")
155+
logDebug { "Stack overflow (increase stack size Settings.TRACE_ARRAY_SIZE)" }
155156
}
156157
}
157158
}

utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/process/ChildProcess.kt

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -69,36 +69,32 @@ private val logLevel = ChildProcessLogLevel.Info
6969

7070
// Logging
7171
private val dateFormatter: DateTimeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss.SSS")
72-
private fun log(level: ChildProcessLogLevel, any: () -> Any?) {
72+
private inline fun log(level: ChildProcessLogLevel, any: () -> Any?) {
7373
if (level < logLevel)
7474
return
7575

76-
System.err.println(LocalDateTime.now().format(dateFormatter) + " | ${any()}")
76+
System.err.println(LocalDateTime.now().format(dateFormatter) + " ${level.name.uppercase()}| ${any()}")
7777
}
7878

7979
// errors that must be address
80-
private fun logError(any: () -> Any?) {
80+
internal inline fun logError(any: () -> Any?) {
8181
log(ChildProcessLogLevel.Error, any)
8282
}
8383

84-
private fun logException(e: Throwable) {
85-
log(ChildProcessLogLevel.Error) { "$e |> ${e.stackTraceToString()}" }
86-
}
87-
8884
// default log level for irregular useful messages that does not pollute log
89-
private fun logInfo(any: () -> Any?) {
85+
internal inline fun logInfo(any: () -> Any?) {
9086
log(ChildProcessLogLevel.Info, any)
9187
}
9288

9389
// log level for frequent messages useful for debugging
94-
private fun logDebug(any: () -> Any?) {
90+
internal inline fun logDebug(any: () -> Any?) {
9591
log(ChildProcessLogLevel.Debug, any)
9692
}
9793

9894
// log level for internal rd logs and frequent messages
9995
// heavily pollutes log, useful only when debugging rpc
10096
// probably contains no info about utbot
101-
private fun logTrace(any: () -> Any?) {
97+
internal fun logTrace(any: () -> Any?) {
10298
log(ChildProcessLogLevel.Trace, any)
10399
}
104100

@@ -193,7 +189,7 @@ private fun <T, R> RdCall<T, R>.measureExecutionForTermination(block: (T) -> R)
193189
try {
194190
block(it)
195191
} catch (e: Throwable) {
196-
logException(e)
192+
logError { e.stackTraceToString() }
197193
throw e
198194
}
199195
}
@@ -319,7 +315,6 @@ private suspend fun initiate(lifetime: Lifetime, port: Int, pid: Int) {
319315
logInfo { "starting instrumenting" }
320316
deferred.await()
321317
} catch (e: Throwable) {
322-
logError { "Terminating process because exception occurred" }
323-
logException(e)
318+
logError { "Terminating process because exception occurred: ${e.stackTraceToString()}" }
324319
}
325320
}

0 commit comments

Comments
 (0)