summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tools/hoststubgen/hoststubgen/src/com/android/hoststubgen/HostStubGen.kt9
-rw-r--r--tools/hoststubgen/hoststubgen/src/com/android/hoststubgen/HostStubGenLogger.kt29
2 files changed, 27 insertions, 11 deletions
diff --git a/tools/hoststubgen/hoststubgen/src/com/android/hoststubgen/HostStubGen.kt b/tools/hoststubgen/hoststubgen/src/com/android/hoststubgen/HostStubGen.kt
index 36bfbefdb086..c510eeea63de 100644
--- a/tools/hoststubgen/hoststubgen/src/com/android/hoststubgen/HostStubGen.kt
+++ b/tools/hoststubgen/hoststubgen/src/com/android/hoststubgen/HostStubGen.kt
@@ -334,13 +334,14 @@ class HostStubGen(val options: HostStubGenOptions) {
entry: ZipEntry,
out: ZipOutputStream,
) {
- BufferedInputStream(inZip.getInputStream(entry)).use { bis ->
+ // TODO: It seems like copying entries this way is _very_ slow,
+ // even with out.setLevel(0). Look for other ways to do it.
+
+ inZip.getInputStream(entry).use { ins ->
// Copy unknown entries as is to the impl out. (but not to the stub out.)
val outEntry = ZipEntry(entry.name)
out.putNextEntry(outEntry)
- while (bis.available() > 0) {
- out.write(bis.read())
- }
+ ins.transferTo(out)
out.closeEntry()
}
}
diff --git a/tools/hoststubgen/hoststubgen/src/com/android/hoststubgen/HostStubGenLogger.kt b/tools/hoststubgen/hoststubgen/src/com/android/hoststubgen/HostStubGenLogger.kt
index ee4a06fb983d..fcdf8247e7d0 100644
--- a/tools/hoststubgen/hoststubgen/src/com/android/hoststubgen/HostStubGenLogger.kt
+++ b/tools/hoststubgen/hoststubgen/src/com/android/hoststubgen/HostStubGenLogger.kt
@@ -121,7 +121,7 @@ class HostStubGenLogger {
return level.ordinal <= maxLogLevel.ordinal
}
- private fun println(level: LogLevel, message: String) {
+ fun println(level: LogLevel, message: String) {
printers.forEach {
if (it.logLevel.ordinal >= level.ordinal) {
it.println(level, indent, message)
@@ -129,7 +129,7 @@ class HostStubGenLogger {
}
}
- private fun println(level: LogLevel, format: String, vararg args: Any?) {
+ fun println(level: LogLevel, format: String, vararg args: Any?) {
if (isEnabled(level)) {
println(level, String.format(format, *args))
}
@@ -185,14 +185,29 @@ class HostStubGenLogger {
println(LogLevel.Debug, format, *args)
}
- inline fun <T> iTime(message: String, block: () -> T): T {
+ inline fun <T> logTime(level: LogLevel, message: String, block: () -> T): T {
val start = System.currentTimeMillis()
- val ret = block()
- val end = System.currentTimeMillis()
+ try {
+ return block()
+ } finally {
+ val end = System.currentTimeMillis()
+ if (isEnabled(level)) {
+ println(level,
+ String.format("%s: took %.1f second(s).", message, (end - start) / 1000.0))
+ }
+ }
+ }
- log.i("%s: took %.1f second(s).", message, (end - start) / 1000.0)
+ inline fun <T> iTime(message: String, block: () -> T): T {
+ return logTime(LogLevel.Info, message, block)
+ }
+
+ inline fun <T> vTime(message: String, block: () -> T): T {
+ return logTime(LogLevel.Verbose, message, block)
+ }
- return ret
+ inline fun <T> dTime(message: String, block: () -> T): T {
+ return logTime(LogLevel.Debug, message, block)
}
inline fun forVerbose(block: () -> Unit) {