Measure enhancement execution time

This commit is contained in:
Ming Ming 2022-05-15 13:42:12 +08:00
parent d5151f077f
commit f2b17ccc6b
2 changed files with 28 additions and 13 deletions

View file

@ -419,19 +419,22 @@ private open class ImageProcessorCommandTask(context: Context) :
handleCancel()
return try {
val fileUri = Uri.fromFile(file)
val output = when (cmd.method) {
ImageProcessorService.METHOD_ZERO_DCE -> ZeroDce(
context, cmd.maxWidth, cmd.maxHeight
).infer(
fileUri
)
ImageProcessorService.METHOD_DEEL_LAP_PORTRAIT -> DeepLab3Portrait(
context, cmd.maxWidth, cmd.maxHeight
).infer(fileUri)
else -> throw IllegalArgumentException(
"Unknown method: ${cmd.method}"
)
}
val output = measureTime(
TAG, "[handleCommand] Elapsed time", {
when (cmd.method) {
ImageProcessorService.METHOD_ZERO_DCE -> ZeroDce(
context, cmd.maxWidth, cmd.maxHeight
).infer(
fileUri
)
ImageProcessorService.METHOD_DEEL_LAP_PORTRAIT -> DeepLab3Portrait(
context, cmd.maxWidth, cmd.maxHeight
).infer(fileUri)
else -> throw IllegalArgumentException(
"Unknown method: ${cmd.method}"
)
}
})
handleCancel()
saveBitmap(output, cmd.filename, file)
} finally {

View file

@ -2,6 +2,7 @@ package com.nkming.nc_photos.plugin
import android.app.PendingIntent
import android.os.Build
import android.util.Log
import java.net.HttpURLConnection
fun getPendingIntentFlagImmutable(): Int {
@ -26,3 +27,14 @@ inline fun <T> HttpURLConnection.use(block: (HttpURLConnection) -> T): T {
inline fun ByteArray.transform(transform: (Byte) -> Byte) {
forEachIndexed{ i, v -> this[i] = transform(v) }
}
inline fun <T> measureTime(tag: String, message: String, block: () -> T): T {
val begin = System.currentTimeMillis()
try {
return block()
} finally {
val end = System.currentTimeMillis()
val elapsed = end - begin
Log.i(tag, "$message: ${elapsed}ms")
}
}