The TimingLogger is useful to measure precisely the execution time of code blocks (or even just one line of code).

The Android docs show how it can be used. Below is a simple example:

1
2
3
4
5
6
7
8
9
TimingLogger timings = new TimingLogger("MYTAG", "MethodA");
// do some work A ...
timings.addSplit("work A");
// do some work B ...
timings.addSplit("work B);
// do some work C ...
timings.addSplit("work C");

timings.dumpToLog(); 
warning

The TimingLogger will not output anything unless it is manually enabled.

The following command enables the TimingLogger output for MYTAG

1
adb shell setprop log.tag.MYTAG VERBOSE

After the TimingLogger is enabled and the application has started generating logs, we can view them with the adb command:

1
adb logcat -v time MYTAG:W *:S