Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4a75abc

Browse files
Use some time compensation for dynamic classes transformation (#2551)
Use some time compensation in dynamic classes transformation
1 parent 0587302 commit 4a75abc

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

‎utbot-core/src/main/kotlin/org/utbot/common/StopWatch.kt‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,19 @@ class StopWatch {
2828
startTime = System.currentTimeMillis()
2929
}
3030
}
31-
32-
fun stop() {
31+
32+
/**
33+
* @param compensationMillis the duration in millis that should be subtracted from [elapsedMillis] to compensate
34+
* for stopping and restarting [StopWatch] taking some time, can also be used to compensate for some activities,
35+
* that are hard to directly detect (e.g. class loading).
36+
*
37+
* NOTE: [compensationMillis] will never cause [elapsedMillis] become negative.
38+
*/
39+
fun stop(compensationMillis: Long = 0) {
3340
lock.withLockInterruptibly {
34-
startTime?.let {
35-
elapsedMillis += (System.currentTimeMillis() - it)
36-
startTime = null
41+
startTime?.let { startTime ->
42+
elapsedMillis += ((System.currentTimeMillis() - startTime) - compensationMillis).coerceAtLeast(0)
43+
this.startTime = null
3744
}
3845
}
3946
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ class DynamicClassTransformer : ClassFileTransformer {
3535
classfileBuffer: ByteArray
3636
): ByteArray? {
3737
try {
38-
UtContext.currentContext()?.stopWatch?.stop()
38+
// since we got here we have loaded a new class, meaning program is not stuck and some "meaningful"
39+
// non-repeating actions are performed, so we assume that we should not time out for then next 65 ms
40+
UtContext.currentContext()?.stopWatch?.stop(compensationMillis = 65)
3941
val pathToClassfile = protectionDomain.codeSource?.location?.toURI()?.let(Paths::get)?.absolutePathString()
4042
return if (pathToClassfile in pathsToUserClasses ||
4143
packsToAlwaysTransform.any(className::startsWith)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /