Skip to content

Most visited

Recently visited

navigation

TimingLogger

public class TimingLogger
extends Object

java.lang.Object
   ↳ android.util.TimingLogger


A utility class to help log timings splits throughout a method call. Typical usage is:

     TimingLogger timings = new TimingLogger(TAG, "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();
 

The dumpToLog call would add the following to the log:

     D/TAG     ( 3459): methodA: begin
     D/TAG     ( 3459): methodA:      9 ms, work A
     D/TAG     ( 3459): methodA:      1 ms, work B
     D/TAG     ( 3459): methodA:      6 ms, work C
     D/TAG     ( 3459): methodA: end, 16 ms
 

Summary

Public constructors

TimingLogger(String tag, String label)

Create and initialize a TimingLogger object that will log using the specific tag.

Public methods

void addSplit(String splitLabel)

Add a split for the current time, labeled with splitLabel.

void dumpToLog()

Dumps the timings to the log using Log.d().

void reset()

Clear and initialize a TimingLogger object that will log using the tag and label that was specified previously, either via the constructor or a call to reset(tag, label).

void reset(String tag, String label)

Clear and initialize a TimingLogger object that will log using the specific tag.

Inherited methods

From class java.lang.Object

Public constructors

TimingLogger

added in API level 1
TimingLogger (String tag, 
                String label)

Create and initialize a TimingLogger object that will log using the specific tag. If the Log.isLoggable is not enabled to at least the Log.VERBOSE level for that tag at creation time then the addSplit and dumpToLog call will do nothing.

Parameters
tag String: the log tag to use while logging the timings

label String: a string to be displayed with each log

Public methods

addSplit

added in API level 1
void addSplit (String splitLabel)

Add a split for the current time, labeled with splitLabel. If Log.isLoggable was not enabled to at least the Log.VERBOSE for the specified tag at construction or reset() time then this call does nothing.

Parameters
splitLabel String: a label to associate with this split.

dumpToLog

added in API level 1
void dumpToLog ()

Dumps the timings to the log using Log.d(). If Log.isLoggable was not enabled to at least the Log.VERBOSE for the specified tag at construction or reset() time then this call does nothing.

reset

added in API level 1
void reset ()

Clear and initialize a TimingLogger object that will log using the tag and label that was specified previously, either via the constructor or a call to reset(tag, label). If the Log.isLoggable is not enabled to at least the Log.VERBOSE level for that tag at creation time then the addSplit and dumpToLog call will do nothing.

reset

added in API level 1
void reset (String tag, 
                String label)

Clear and initialize a TimingLogger object that will log using the specific tag. If the Log.isLoggable is not enabled to at least the Log.VERBOSE level for that tag at creation time then the addSplit and dumpToLog call will do nothing.

Parameters
tag String: the log tag to use while logging the timings

label String: a string to be displayed with each log

This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields

Hooray!

Follow Google Developers on WeChat

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a short survey?
Help us improve the Android developer experience. (Dec 2017 Android Platform & Tools Survey)