Skip to content

Commit 3aa6cb8

Browse files
committed
fix: native-image
1 parent 91b4414 commit 3aa6cb8

File tree

3 files changed

+44
-10
lines changed

3 files changed

+44
-10
lines changed

scripts/buildNativeImage.sh

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@ export SDKMAN_DIR="$HOME/.sdkman"
55

66
sdk use java 23.0.1-graal
77
./gradlew fatJar
8-
java -agentlib:native-image-agent=config-output-dir=/path/to/config-dir/ -jar ./build/libs/aoc-kt-0.24.0-all.jar all
9-
native-image -jar ./build/libs/aoc-kt-0.24.0-all.jar -o build/libs/aoc-kt -march=native
108

9+
JAR_FILE=$(ls ./build/libs/aoc-kt-*-all.jar)
10+
mkdir -p ./build/tmp/native
11+
java -agentlib:native-image-agent=config-merge-dir=./build/tmp/native -Djava.awt.headless=true -jar $JAR_FILE 2024:all --no-plot
12+
native-image \
13+
-march=native \
14+
-H:ConfigurationFileDirectories=./build/tmp/native \
15+
--parallelism=4 \
16+
--initialize-at-run-time=dev.mtib.aoc.aoc23.days.Day10\$SubGridPosition\$Companion \
17+
-Djava.awt.headless=true \
18+
-o build/libs/aoc-kt \
19+
-jar $JAR_FILE

scripts/runNativeImage.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ export USER_SNOWFLAKE
55
export REDIS_URL
66
export SESSION
77

8-
./build/libs/aoc-kt latest
8+
./build/libs/aoc-kt latest --no-plot

src/main/kotlin/dev/mtib/aoc/AocRunner.kt

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import kotlinx.coroutines.joinAll
2626
import kotlinx.coroutines.launch
2727
import kotlinx.coroutines.withContext
2828
import kotlinx.coroutines.yield
29+
import java.time.ZoneId
30+
import java.time.ZonedDateTime
2931
import kotlin.time.Duration
3032
import kotlin.time.Duration.Companion.microseconds
3133
import kotlin.time.Duration.Companion.milliseconds
@@ -39,6 +41,9 @@ private val cleanupScope = CoroutineScope(Dispatchers.IO)
3941
const val BENCHMARK_WINDOW = 100
4042
const val BENCHMARK_TIMEOUT_SECONDS = 5
4143
const val BENCHMARK_TIMEOUT_OVERRIDE_ENV = "BENCHMARK_TIMEOUT_SECONDS"
44+
45+
var plotFlag = true
46+
4247
suspend fun main(args: Array<String>) {
4348
logger.log(AocLogger.Main) { "starting advent of code" }
4449
AocDay.load()
@@ -59,6 +64,7 @@ suspend fun main(args: Array<String>) {
5964
return@forEach
6065
}
6166
when (arg) {
67+
"--no-plot" -> plotFlag = false
6268
"all" -> addAll(AocDay.getAll().days())
6369
"latest" -> AocDay.getAll(mostRecentYear).days().maxOrNull()?.also { add(it) }
6470
else -> {
@@ -161,8 +167,10 @@ suspend fun runDay(day: Day) {
161167
}
162168
}
163169

164-
cleanupScope.launch(start = CoroutineStart.LAZY) {
165-
BenchmarkProgressPlotter(day).plot()
170+
if (plotFlag) {
171+
cleanupScope.launch(start = CoroutineStart.LAZY) {
172+
BenchmarkProgressPlotter(day).plot()
173+
}
166174
}
167175
}
168176

@@ -245,8 +253,10 @@ private suspend fun benchmark(
245253
.microseconds
246254
val lastBest = Results.getLastSubmittedBenchmarkResult(puzzle)
247255
Results.send(BenchmarkResult(average, durations.size.toLong(), puzzle))
248-
cleanupScope.launch(start = CoroutineStart.LAZY) {
249-
BenchmarkWindowPlotter(puzzle, BENCHMARK_WINDOW, durations).plot()
256+
if (plotFlag) {
257+
cleanupScope.launch(start = CoroutineStart.LAZY) {
258+
BenchmarkWindowPlotter(puzzle, BENCHMARK_WINDOW, durations).plot()
259+
}
250260
}
251261
val styledCommand =
252262
(TextStyles.italic + TextColors.blue)("/aoc_benchmark day:${puzzle.day} part:${puzzle.part} time_milliseconds:${average.inWholeMicroseconds / 1000.0}")
@@ -261,12 +271,27 @@ private suspend fun benchmark(
261271
} else if (average == lastSubmittedDuration) {
262272
" ${TextColors.gray("stayed the same")}"
263273
} else {
264-
""
274+
null
265275
}
266-
} ?: " ${TextColors.brightBlue("new(?)")}"
276+
}
277+
val canReportWithDiscord = puzzle.year == ZonedDateTime.now(ZoneId.of("CET")).year
267278
logger.log(
268279
puzzle
269-
) { "averaged at ${TextColors.brightWhite(average.toString())}$improvementText, report with: $styledCommand" }
280+
) {
281+
buildString {
282+
append("averaged at ${TextColors.brightWhite(average.toString())}")
283+
284+
if (improvementText != null) {
285+
append(improvementText)
286+
} else if (canReportWithDiscord) {
287+
append(" ${TextColors.brightBlue("new(?)")}")
288+
}
289+
290+
if (canReportWithDiscord) {
291+
append(", report with: $styledCommand")
292+
}
293+
}
294+
}
270295
} catch (e: NotImplementedError) {
271296
logger.error(e = null, puzzle) { "not implemented" }
272297
} catch (e: AocDay.DayNotReleasedException) {

0 commit comments

Comments
 (0)