-
Notifications
You must be signed in to change notification settings - Fork 669
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* ported stats and removed redundant `project` receiver in release.gradle.kts --------- Co-authored-by: Frank Liu <[email protected]>
- Loading branch information
Showing
6 changed files
with
72 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
plugins { | ||
id ("com.github.spotbugs") apply false | ||
id("com.github.spotbugs") apply false | ||
ai.djl.release | ||
ai.djl.stats | ||
} | ||
|
||
//apply from: file("${rootProject.projectDir}/tools/gradle/stats.gradle") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ plugins { | |
`java-library` | ||
id("ai.djl.javaFormatter") | ||
id("ai.djl.check") | ||
id("ai.djl.stats") | ||
} | ||
|
||
tasks { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package ai.djl | ||
|
||
import org.gradle.api.plugins.ExtraPropertiesExtension | ||
import org.gradle.kotlin.dsl.support.serviceOf | ||
import org.gradle.tooling.events.FinishEvent | ||
import org.gradle.tooling.events.OperationCompletionListener | ||
import kotlin.time.Duration | ||
import kotlin.time.Duration.Companion.seconds | ||
import kotlin.time.ExperimentalTime | ||
import kotlin.time.TimeSource | ||
|
||
plugins { | ||
`java-library` | ||
} | ||
|
||
@ExperimentalTime | ||
val timeSource = TimeSource.Monotonic | ||
val testsResults = mutableMapOf<Duration, String>() | ||
|
||
val demoListener = gradle.sharedServices.registerIfAbsent("demoListener ", StatisticsService::class) { | ||
parameters.testsResults = testsResults | ||
} | ||
|
||
gradle.taskGraph.whenReady { | ||
gradle.serviceOf<BuildEventsListenerRegistry>().onTaskCompletion(demoListener) | ||
} | ||
|
||
abstract class StatisticsService : BuildService<StatisticsService.Parameters>, | ||
OperationCompletionListener, AutoCloseable { | ||
|
||
interface Parameters : BuildServiceParameters { | ||
var testsResults: MutableMap<Duration, String> | ||
} | ||
|
||
override fun onFinish(event: FinishEvent) {} | ||
|
||
override fun close() { | ||
if (parameters.testsResults.isNotEmpty()) { | ||
println("========== Test duration ========== ") | ||
for ((key, value) in parameters.testsResults.entries.sortedByDescending { it.key }.take(6)) { | ||
// `.inWholeSeconds.seconds` truncate to integer units, without decimals | ||
println("\t$value:\t${key.inWholeSeconds.seconds}") | ||
} | ||
} | ||
} | ||
} | ||
|
||
tasks.test { | ||
doFirst { | ||
@OptIn(ExperimentalTime::class) | ||
startTime = timeSource.markNow() | ||
} | ||
doLast { | ||
@OptIn(ExperimentalTime::class) | ||
if (state.didWork) | ||
demoListener.get().parameters.testsResults[timeSource.markNow() - startTime] = project.name | ||
} | ||
} | ||
|
||
@ExperimentalTime | ||
var Task.startTime: TimeSource.Monotonic.ValueTimeMark | ||
get() = ext.get("startTime") as TimeSource.Monotonic.ValueTimeMark | ||
set(value) = ext.set("startTime", value) | ||
|
||
val Task.ext: ExtraPropertiesExtension | ||
get() = (this as ExtensionAware).extensions.getByName<ExtraPropertiesExtension>("ext") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.