Skip to content

Commit

Permalink
Improve performance logs to show skipped phases.
Browse files Browse the repository at this point in the history
  • Loading branch information
FilipDolnik committed Nov 2, 2023
1 parent 5deb8bc commit c3c1df6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ object SkiePerformanceAnalytics {
override fun produce(): String =
entries.toPrettyJson()

fun logSkipped(name: String) {
printLogIfEnabled("$name: Skipped")
}

@OptIn(ExperimentalTime::class)
fun <T> log(name: String, block: () -> T): T {
val timedValue = measureTimedValue {
Expand All @@ -33,18 +37,22 @@ object SkiePerformanceAnalytics {

entries[name] = timedValue.duration.toDouble(DurationUnit.SECONDS)

printLogIfEnabled(name, timedValue.duration)
printFormattedLogIfEnabled(name, timedValue.duration)

return timedValue.value
}

private fun printLogIfEnabled(name: String, duration: Duration) {
if (SkieConfigurationFlag.Debug_PrintSkiePerformanceLogs in skieConfiguration.enabledConfigurationFlags) {
val durationInSeconds = duration.toDouble(DurationUnit.SECONDS)
private fun printFormattedLogIfEnabled(name: String, duration: Duration) {
val durationInSeconds = duration.toDouble(DurationUnit.SECONDS)

val durationInSecondsAsString = String.format("%.6f", durationInSeconds)
val durationInSecondsAsString = String.format("%.6f", durationInSeconds)

println("$name: ${durationInSecondsAsString}s")
printLogIfEnabled("$name: ${durationInSecondsAsString}s")
}

private fun printLogIfEnabled(content: String) {
if (SkieConfigurationFlag.Debug_PrintSkiePerformanceLogs in skieConfiguration.enabledConfigurationFlags) {
println(content)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ class SkiePhaseGroup<P : SkiePhase<C>, C : SkiePhase.Context>(
fun run(context: C) {
with(context) {
buildPhases(context)
.filter { it.isActive() }
.forEach {
context.skiePerformanceAnalyticsProducer.log(it::class.nameForLogger) {
it.execute()
if (it.isActive()) {
context.skiePerformanceAnalyticsProducer.log(it::class.nameForLogger) {
it.execute()
}
} else {
context.skiePerformanceAnalyticsProducer.logSkipped(it::class.nameForLogger)
}
}
}
Expand Down

0 comments on commit c3c1df6

Please sign in to comment.