A utility class to help log timings splits throughout a method call. Typical usage is:
TimingLoggertimings=newTimingLogger(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:
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).
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
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.
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.
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.
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
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-02-10 UTC."],[],[],null,["# TimingLogger\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \nDeprecated in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)\n\nTimingLogger\n============\n\n*** ** * ** ***\n\nKotlin \\|[Java](/reference/android/util/TimingLogger \"View this page in Java\") \n\n```\nopen class TimingLogger\n```\n\n|---|--------------------------------|\n| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html) ||\n| ↳ | [android.util.TimingLogger](#) |\n\n*** ** * ** ***\n\n| **This class was deprecated in API level 30.**\n|\n| Use [android.os.Trace](../os/Trace.html#), or [Android Studio](https://developer.android.com/studio/profile/benchmark). In general, milliseconds is the wrong granularity for method-level tracing. Rounding errors can overemphasize cheap operations, or underemphasize repeated operations. This timing system also does not take CPU scheduling or frequency into account.\n\nA utility class to help log timings splits throughout a method call. Typical usage is: \n\n```kotlin\nTimingLogger timings = new TimingLogger(TAG, \"methodA\");\n // ... do some work A ...\n timings.addSplit(\"work A\");\n // ... do some work B ...\n timings.addSplit(\"work B\");\n // ... do some work C ...\n timings.addSplit(\"work C\");\n timings.dumpToLog();\n \n```\n\n\u003cbr /\u003e\n\nThe dumpToLog call would add the following to the log: \n\n```kotlin\nD/TAG ( 3459): methodA: begin\n D/TAG ( 3459): methodA: 9 ms, work A\n D/TAG ( 3459): methodA: 1 ms, work B\n D/TAG ( 3459): methodA: 6 ms, work C\n D/TAG ( 3459): methodA: end, 16 ms\n \n```\n\nSummary\n-------\n\n| Public constructors ||\n|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|\n| [TimingLogger](#TimingLogger(kotlin.String,%20kotlin.String))`(`tag:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!`, `label:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!`)` Create and initialize a TimingLogger object that will log using the specific tag. |\n\n| Public methods ||\n|-----------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| open [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [addSplit](#addSplit(kotlin.String))`(`splitLabel:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!`)` Add a split for the current time, labeled with splitLabel. |\n| open [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [dumpToLog](#dumpToLog())`()` Dumps the timings to the log using Log. |\n| open [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [reset](#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). |\n| open [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [reset](#reset(kotlin.String,%20kotlin.String))`(`tag:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!`, `label:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!`)` Clear and initialize a TimingLogger object that will log using the specific tag. |\n\nPublic constructors\n-------------------\n\n### TimingLogger\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nTimingLogger(\n tag: String!, \n label: String!)\n```\n\nCreate 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.\n\n| Parameters ||\n|---------|---------------------------------------------------------------------------------------------------------------------------------|\n| `tag` | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!: the log tag to use while logging the timings |\n| `label` | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!: a string to be displayed with each log |\n\nPublic methods\n--------------\n\n### addSplit\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen fun addSplit(splitLabel: String!): Unit\n```\n\n**Deprecated:** *Deprecated in Java.*\n\nAdd 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.\n\n| Parameters ||\n|--------------|--------------------------------------------------------------------------------------------------------------------------|\n| `splitLabel` | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!: a label to associate with this split. |\n\n### dumpToLog\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen fun dumpToLog(): Unit\n```\n\n**Deprecated:** *Deprecated in Java.*\n\nDumps 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. \n\n### reset\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen fun reset(): Unit\n```\n\n**Deprecated:** *Deprecated in Java.*\n\nClear 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. \n\n### reset\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen fun reset(\n tag: String!, \n label: String!\n): Unit\n```\n\n**Deprecated:** *Deprecated in Java.*\n\nClear 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.\n\n| Parameters ||\n|---------|---------------------------------------------------------------------------------------------------------------------------------|\n| `tag` | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!: the log tag to use while logging the timings |\n| `label` | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)!: a string to be displayed with each log |"]]