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

Commit d208ee5f authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "[hoststubgen] Fix log.iTime()" into main

parents c54f721a 161c9a8b
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
@@ -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()
        }
    }
+22 −7
Original line number Diff line number Diff line
@@ -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()
        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))
            }
        }
    }

    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) {