SharedPerformance

Entry point for creating performance metrics. This object can be used to measure or trace the time between events from different parts of the sdk. Be sure to complete the instances when you use this.

When to use Measure vs Trace:

Measure is for debug logging and can be used as an enhanced local logger.

  • This does not have indexing limitations so you can use it to log unique values or identifiers.

  • Useful for debug logging that can be helpful for understanding the performance. Trace is used for uploading performance metrics to service dashboards like Firebase.

  • Do not use this for logging unique values or identifiers as it has indexing limitations.

  • Useful for storing performance metrics in a database.

Functions

Link copied to clipboard
fun complete(trace: Trace)

Removes and tracks the completion of the Trace instance.

fun complete(traceName: TraceName)

Removes and tracks the completion of the TraceName instance.

fun complete(measure: Measure, block: () -> String? = null)

Removes the Measure instance from the shared performance tracking.

fun complete(name: String, block: () -> String? = null)

Removes and tracks the completion of the Trace instance. Removes and tracks the completion of the Measure instance.

Link copied to clipboard

Remove a prefix to disable performance tracking for. Measure or Trace created through this object will be disabled when the name starts with the prefix.

Link copied to clipboard
fun discard(prefix: String)

Removes and does not track the completion of the Measure instance. Removes and does not track the completion of the Trace instance.

Link copied to clipboard

Add a prefix to enable performance tracking for. Measure or Trace created through this object will be operational when the name starts with any of the prefixes.

Link copied to clipboard

Adds prefixes to enable performance tracking for. Measure or Trace created through this object will be operational when the name starts with any of the prefixes.

Link copied to clipboard
fun measure(name: String): Measure

Returns a sharable instance of Measure. Must be enabled by a prefix in order to run real measurements. Caller must call complete when done with the instance.

Link copied to clipboard

Caller manages the instance of the Measure. Must be enabled by a prefix in order to run real measurements. Instance is not held by the SharedPerformance object.

Link copied to clipboard

Caller manages the instance of the Trace. Must be enabled by a prefix in order to run real measurements. Instance is not held by the SharedPerformance object.

Link copied to clipboard
fun <R> runMeasure(name: String, block: (Measure) -> R): R

Run a single block of code with the Measure. Must be enabled by a prefix in order to run real measurements. Instance is not held by the SharedPerformance object.

Link copied to clipboard
fun <R> runTrace(name: TraceName, block: (Trace) -> R): R

Run a single block of code with the Trace. Must be enabled by a prefix in order to run real measurements. Instance is not held by the SharedPerformance object.

Link copied to clipboard
fun <R> runWhenEnabled(name: String, block: () -> R): R?

Run a block of code only if the prefix is enabled. Returns the result of the block if the prefix is enabled, otherwise null.

Link copied to clipboard

Set the factory to use to create a Trace instance. This allows you to use your own implementation of Trace. For example, you can implement FirebaseTrace to track the performance of your app in Firebase. Setting to null will disable tracing.

Link copied to clipboard
fun start(name: TraceName): Trace

Returns a sharable instance of Trace. Must be enabled by a prefix in order to run real measurements. Caller must call complete when done with the instance.