Trace

class Trace : Parcelable


Trace allows you to set beginning and end of a certain action in your app.

Summary

Constants

const Parcelable.Creator<Trace!>!

A public static CREATOR field that implements Parcelable.Creator and generates instances of your Parcelable class from a Parcel.

const Int

Maximum allowed length of the Key of the Trace attribute

const Int

Maximum allowed length of the Value of the Trace attribute

const Int

Maximum allowed number of attributes allowed in a trace.

const Int

Maximum allowed length of the name of the Trace

Public functions

Int

Describes the kinds of special objects contained in this Parcelable's marshalled representation.

String?
@Keep
getAttribute(attribute: String)

Returns the value of an attribute.

(Mutable)Map<String!, String!>

Returns the map of all the attributes added to this trace.

Long
@Keep
getLongMetric(metricName: String)

Gets the value of the metric with the given name in the current trace.

Unit
@Keep
incrementMetric(metricName: String, incrementBy: Long)

Atomically increments the metric with the given name in this trace by the incrementBy value.

Unit
@Keep
putAttribute(attribute: String, value: String)

Sets a String value for the specified attribute.

Unit
@Keep
putMetric(metricName: String, value: Long)

Sets the value of the metric with the given name in this trace to the value provided.

Unit

Removes an already added attribute from the Traces.

Unit

Starts this trace.

Unit

Stops this trace.

Unit
@Keep
writeToParcel(out: Parcel, flags: Int)

Flatten this object into a Parcel.

Public properties

String!

Extension functions

inline T
<T : Any?> Trace.trace(block: Trace.() -> T)

Measures the time it takes to run the block wrapped by calls to start and stop using Trace.

inline T
<T : Any?> Trace.trace(block: Trace.() -> T)

This function is deprecated. Migrate to use the KTX API from the main module: https://firebase.google.com/docs/android/kotlin-migration.

Constants

CREATOR

@Keep
const val CREATORParcelable.Creator<Trace!>!

A public static CREATOR field that implements Parcelable.Creator and generates instances of your Parcelable class from a Parcel.

MAX_ATTRIBUTE_KEY_LENGTH

const val MAX_ATTRIBUTE_KEY_LENGTH = 40: Int

Maximum allowed length of the Key of the Trace attribute

MAX_ATTRIBUTE_VALUE_LENGTH

const val MAX_ATTRIBUTE_VALUE_LENGTH = 100: Int

Maximum allowed length of the Value of the Trace attribute

MAX_TRACE_CUSTOM_ATTRIBUTES

const val MAX_TRACE_CUSTOM_ATTRIBUTES = 5: Int

Maximum allowed number of attributes allowed in a trace.

MAX_TRACE_NAME_LENGTH

const val MAX_TRACE_NAME_LENGTH = 100: Int

Maximum allowed length of the name of the Trace

Public functions

describeContents

@Keep
fun describeContents(): Int

Describes the kinds of special objects contained in this Parcelable's marshalled representation.

Returns
Int

always returns 0.

See also
Parcelable

getAttribute

@Keep
fun getAttribute(attribute: String): String?

Returns the value of an attribute.

Parameters
attribute: String

name of the attribute to fetch the value for

Returns
String?

the value of the attribute if it exists or null otherwise.

getAttributes

@Keep
fun getAttributes(): (Mutable)Map<String!, String!>

Returns the map of all the attributes added to this trace.

Returns
(Mutable)Map<String!, String!>

map of attributes and its values currently added to this Trace

getLongMetric

@Keep
fun getLongMetric(metricName: String): Long

Gets the value of the metric with the given name in the current trace. If a metric with the given name doesn't exist, it is NOT created and a 0 is returned. This method is atomic.

Parameters
metricName: String

Name of the metric to get. Requires no leading or trailing whitespace, no leading underscore '_' character, max length is 100 characters.

Returns
Long

Value of the metric or 0 if it hasn't yet been set.

incrementMetric

@Keep
fun incrementMetric(metricName: String, incrementBy: Long): Unit

Atomically increments the metric with the given name in this trace by the incrementBy value. If the metric does not exist, a new one will be created. If the trace has not been started or has already been stopped, returns immediately without taking action.

Parameters
metricName: String

Name of the metric to be incremented. Requires no leading or trailing whitespace, no leading underscore [_] character, max length of 100 characters.

incrementBy: Long

Amount by which the metric has to be incremented.

putAttribute

@Keep
fun putAttribute(attribute: String, value: String): Unit

Sets a String value for the specified attribute. Updates the value of the attribute if the attribute already exists. If the trace has been stopped, this method returns without adding the attribute. The maximum number of attributes that can be added to a Trace are MAX_TRACE_CUSTOM_ATTRIBUTES.

Parameters
attribute: String

Name of the attribute

value: String

Value of the attribute

putMetric

@Keep
fun putMetric(metricName: String, value: Long): Unit

Sets the value of the metric with the given name in this trace to the value provided. If a metric with the given name doesn't exist, a new one will be created. If the trace has not been started or has already been stopped, returns immediately without taking action. This method is atomic.

Parameters
metricName: String

Name of the metric to set. Requires no leading or trailing whitespace, no leading underscore '_' character, max length is 100 characters.

value: Long

The value to which the metric should be set to.

removeAttribute

@Keep
fun removeAttribute(attribute: String): Unit

Removes an already added attribute from the Traces. If the trace has been stopped, this method returns without removing the attribute.

Parameters
attribute: String

Name of the attribute to be removed from the running Traces.

start

@Keep
fun start(): Unit

Starts this trace.

stop

@Keep
fun stop(): Unit

Stops this trace.

writeToParcel

@Keep
fun writeToParcel(out: Parcel, flags: Int): Unit

Flatten this object into a Parcel. Please refer to https://developer.android.com/reference/android/os/Parcelable.html

Parameters
out: Parcel

the Parcel in which the object should be written.

flags: Int

Additional flags about how the object should be written.

Public properties

name

val nameString!

Extension functions

trace

inline fun <T : Any?> Trace.trace(block: Trace.() -> T): T

Measures the time it takes to run the block wrapped by calls to start and stop using Trace.

trace

inline fun <T : Any?> Trace.trace(block: Trace.() -> T): T

Measures the time it takes to run the block wrapped by calls to start and stop using Trace.

Deprecation Notice: The Kotlin extensions (KTX) APIs have been added to their respective main modules, and the Kotlin extension (KTX) APIs in com.google.firebase.firebase-perf-ktx are now deprecated. As early as April 2024, we'll no longer release KTX modules. For details, see the FAQ about this initiative.