Skip to content

Commit 63c9a44

Browse files
Add: indicators
1 parent 9f2fc15 commit 63c9a44

File tree

12 files changed

+759
-26
lines changed

12 files changed

+759
-26
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package org.utbot.common.statistics
2+
3+
import java.io.OutputStream
4+
import java.nio.file.OpenOption
5+
import java.nio.file.Path
6+
import java.nio.file.Paths
7+
import java.nio.file.StandardOpenOption
8+
import java.text.SimpleDateFormat
9+
import java.util.Date
10+
import kotlin.io.path.createDirectory
11+
import kotlin.io.path.createFile
12+
import kotlin.io.path.exists
13+
import kotlin.io.path.outputStream
14+
import kotlin.reflect.KClass
15+
16+
interface Indicator<T> {
17+
val name: String
18+
val header: String
19+
fun touch(data: T)
20+
fun clear()
21+
fun log(out: OutputStream)
22+
}
23+
24+
interface IndicatorStorage {
25+
operator fun <T : Indicator<*>>get(kClass: KClass<T>): T
26+
operator fun <T : Indicator<*>>set(kClass: KClass<T>, indicator: T)
27+
fun log()
28+
fun clear()
29+
}
30+
31+
open class FolderIndicatorStorage(
32+
folder: Path = Paths.get("./engine")
33+
) : IndicatorStorage {
34+
private val time = SimpleDateFormat("yyyy_MM_dd_HH_mm_ss").format(Date())
35+
36+
private val folder = folder.apply {
37+
if (!folder.exists()) {
38+
folder.createDirectory()
39+
}
40+
}
41+
42+
private val indicators = mutableMapOf<KClass<Indicator<*>>, Indicator<*>>()
43+
44+
override operator fun <T : Indicator<*>>get(kClass: KClass<T>): T =
45+
indicators.getValue(kClass as KClass<Indicator<*>>) as T
46+
47+
override fun <T : Indicator<*>> set(kClass: KClass<T>, indicator: T) {
48+
indicators[kClass as KClass<Indicator<*>>] = indicator
49+
}
50+
51+
override fun log() {
52+
indicators.onEach { (_, indicator) ->
53+
val name = "${indicator.name}_$time"
54+
val file = folder.resolve("$name.csv")
55+
if (!file.exists()) {
56+
file.createFile()
57+
file.outputStream().bufferedWriter().apply {
58+
appendLine(indicator.header)
59+
flush()
60+
}
61+
}
62+
indicator.log(file.outputStream(StandardOpenOption.APPEND))
63+
}
64+
}
65+
66+
override fun clear() {
67+
indicators.values.onEach { clear() }
68+
}
69+
}

utbot-framework-test/src/benchmarks/kotlin/org/utbot/benchmarks/BenchmarksTest.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@ import org.openjdk.jmh.annotations.Setup
99
import org.openjdk.jmh.annotations.State
1010
import org.openjdk.jmh.annotations.Threads
1111
import org.openjdk.jmh.annotations.Warmup
12+
import org.utbot.common.FileUtil
13+
import org.utbot.framework.plugin.api.TestCaseGenerator
1214
import org.utbot.framework.plugin.services.JdkInfoDefaultProvider
1315
import org.utbot.framework.util.SootUtils
16+
import org.utbot.tests.infrastructure.TestSpecificTestCaseGenerator
1417
import org.utbot.tests.infrastructure.UtValueTestCaseChecker
1518
import org.utbot.tests.infrastructure.ignoreExecutionsNumber
1619
import java.util.concurrent.TimeUnit
@@ -23,13 +26,20 @@ import java.util.concurrent.TimeUnit
2326
class BenchmarksTest : UtValueTestCaseChecker(
2427
Benchmarks::class,
2528
) {
29+
lateinit var testCaseGenerator: TestCaseGenerator
2630
@Setup
2731
fun setUp() {
32+
val testClass = Benchmarks::class.java
2833
SootUtils.runSoot(Benchmarks::class.java, true, JdkInfoDefaultProvider().info)
34+
testCaseGenerator = TestSpecificTestCaseGenerator(
35+
FileUtil.locateClassPath(testClass)!!.toPath(),
36+
classpath = null,
37+
dependencyPaths = System.getProperty("java.class.path"),
38+
39+
)
2940
}
3041

3142
@Benchmark
32-
@RepeatedTest(10)
3343
fun benchmarkLongMethod() {
3444
check(
3545
Benchmarks::longMethod,

utbot-framework-test/src/benchmarks/kotlin/org/utbot/benchmarks/ProfilerTest.kt

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,38 @@
11
package org.utbot.benchmarks
22

33
import org.utbot.common.FileUtil
4+
import org.utbot.framework.UtSettings
45
import org.utbot.framework.plugin.api.MockStrategyApi
5-
import org.utbot.framework.plugin.api.TestCaseGenerator
66
import org.utbot.framework.plugin.api.util.UtContext
77
import org.utbot.framework.plugin.api.util.executableId
88
import org.utbot.framework.plugin.api.util.withUtContext
9-
import org.utbot.framework.plugin.services.JdkInfoDefaultProvider
9+
import org.utbot.tests.infrastructure.TestSpecificTestCaseGenerator
1010

1111
fun main() {
1212
withUtContext(UtContext(ClassLoader.getSystemClassLoader())) {
1313

1414
val testClass = Benchmarks::class.java
1515

16-
val testCaseGenerator = TestCaseGenerator(
17-
listOf(FileUtil.locateClassPath(testClass)!!.toPath()),
16+
val testCaseGenerator = TestSpecificTestCaseGenerator(
17+
FileUtil.locateClassPath(testClass)!!.toPath(),
1818
classpath = null,
1919
dependencyPaths = System.getProperty("java.class.path"),
20-
jdkInfo = JdkInfoDefaultProvider().info
2120
)
2221

23-
repeat(10) {
22+
UtSettings.utBotGenerationTimeoutInMillis = 200_000
23+
24+
25+
repeat(2) {
2426
testCaseGenerator.generate(
2527
listOf(
2628
Benchmarks::cycle.executableId
2729
),
2830
mockStrategy = MockStrategyApi.NO_MOCKS,
2931
generate = { engine -> engine.traverse() }
3032
)
31-
}
32-
33-
repeat(10) {
3433
testCaseGenerator.generate(
3534
listOf(
36-
Benchmarks::cycle.executableId
35+
Benchmarks::longMethod.executableId
3736
),
3837
mockStrategy = MockStrategyApi.NO_MOCKS,
3938
generate = { engine -> engine.traverse() }

0 commit comments

Comments
 (0)