File tree Expand file tree Collapse file tree 2 files changed +15
-6
lines changed
utbot-core/src/main/kotlin/org/utbot/common
utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/agent Expand file tree Collapse file tree 2 files changed +15
-6
lines changed Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff 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)
You can’t perform that action at this time.
0 commit comments