Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 161c9a8b authored by Makoto Onuki's avatar Makoto Onuki
Browse files

[hoststubgen] Fix log.iTime()

- iTime() didn't print the log, if the `block` had a return.
  Let's just use a finally to fix it.
  (I din't want to print the log if the code threw, but it's not a big deal.)

- Add vTime() and dTime() while I'm at it.

- Also make copyZipEntry() _slightly_ faster. InputStream.transferTo() still
  uses `write(int)` to write byte-by-byte, but using it makes it a bit fast.
  Although apparently copying entries-by-entires this way is still surprisingly
  slow.

  (HostStubGen doesn't use this method too often, but "ravenizer" will use
  it more often, and that's where I noticed it.)

Test: $ANDROID_BUILD_TOP/frameworks/base/ravenwood/scripts/run-ravenwood-tests.sh
Flag: EXEMPT host side test change only
Bug: 292141694
Change-Id: Id2609d1b44055f92956207ee7f8b4c57e931ce44
parent 783fd952
Loading
Loading
Loading
Loading
+5 −4
Original line number Original line Diff line number Diff line
@@ -334,13 +334,14 @@ class HostStubGen(val options: HostStubGenOptions) {
            entry: ZipEntry,
            entry: ZipEntry,
            out: ZipOutputStream,
            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.)
            // Copy unknown entries as is to the impl out. (but not to the stub out.)
            val outEntry = ZipEntry(entry.name)
            val outEntry = ZipEntry(entry.name)
            out.putNextEntry(outEntry)
            out.putNextEntry(outEntry)
            while (bis.available() > 0) {
            ins.transferTo(out)
                out.write(bis.read())
            }
            out.closeEntry()
            out.closeEntry()
        }
        }
    }
    }
+22 −7
Original line number Original line Diff line number Diff line
@@ -121,7 +121,7 @@ class HostStubGenLogger {
        return level.ordinal <= maxLogLevel.ordinal
        return level.ordinal <= maxLogLevel.ordinal
    }
    }


    private fun println(level: LogLevel, message: String) {
    fun println(level: LogLevel, message: String) {
        printers.forEach {
        printers.forEach {
            if (it.logLevel.ordinal >= level.ordinal) {
            if (it.logLevel.ordinal >= level.ordinal) {
                it.println(level, indent, message)
                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)) {
        if (isEnabled(level)) {
            println(level, String.format(format, *args))
            println(level, String.format(format, *args))
        }
        }
@@ -185,14 +185,29 @@ class HostStubGenLogger {
        println(LogLevel.Debug, format, *args)
        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 start = System.currentTimeMillis()
        val ret = block()
        try {
            return block()
        } finally {
            val end = System.currentTimeMillis()
            val end = System.currentTimeMillis()
            if (isEnabled(level)) {
                println(level,
                    String.format("%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)
    }


        log.i("%s: took %.1f second(s).", message, (end - start) / 1000.0)
    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) {
    inline fun forVerbose(block: () -> Unit) {