6
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【Android】TimingLoggerを使ってAPIの処理時間を計測する

Posted at

とりあえずシュッっと計測したい時にどうぞ。:rocket:

TimingLogger

実装例

SampleApi()の処理時間を計測する例です。

  • TimingLoggerのインスタンスを作る。
  • APIのonSuccessでdumpする。
val sampleApiLogger = TimingLogger("TIMING_LOGGER",
                                   SampleActivity::class.java.simpleName)
getSampleApi()
        .subscribe(
                { sampleData ->
                    sampleApiLogger.run {
                        addSplit("getSampleApi")
                        dumpToLog()
                    }
                },
                { e ->
                    e.printStackTrace()
                }
        ).let { disposables.add(it) }

計測の実行前にshellコマンドを叩く

shellコマンドでsetpropしてログ出力の設定をします。
log.tag.TIMING_LOGGERの部分を、先程の実装例にあるTimingLogger("TIMING_LOGGER", ...のラベルと一致させてください。

$ adb shell
# setprop log.tag.TIMING_LOGGER VERBOSE

出力例

Android StudioのLogcatでログを確認できます。
ログレベルをVerboseに設定してラベルでフィルタ(今回の場合はTIMING_LOGGER)すると見やすくて便利です。

09-21 12:23:06.863 7867-7867/com.sample.sampleApp.debug D/TIMING_LOGGER: SampleActivity: begin
    SampleActivity:      861 ms, getSampleApi
    SampleActivity: end, 861 ms

参考リンク

6
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?