Trace

public classTrace implementsParcelable


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

Summary

Constants

static finalParcelable.Creator<Trace>

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

static final int

Maximum allowed length of the Key of theTrace attribute

static final int

Maximum allowed length of the Value of theTrace attribute

static final int

Maximum allowed number of attributes allowed in a trace.

static final int

Maximum allowed length of the name of theTrace

Public fields

finalString

Public methods

int

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

@NullableString

Returns the value of an attribute.

@NonNullMap<StringString>

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

long

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

void
@Keep
incrementMetric(@NonNullString metricName, long incrementBy)

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

void

Sets a String value for the specified attribute.

void
@Keep
putMetric(@NonNullString metricName, long value)

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

void

Removes an already added attribute from the Traces.

void

Starts this trace.

void

Stops this trace.

void
@Keep
writeToParcel(@NonNullParcel out, int flags)

Flatten this object into a Parcel.

Extension functions

final @NonNull T
<T extends Object>PerformanceKt.trace(
    @NonNullTrace receiver,
    @ExtensionFunctionType @NonNull Function1<@NonNullTrace, @NonNull T> block
)

Measures the time it takes to run theblock wrapped by calls to start and stop usingTrace.

Inherited Constants

Fromandroid.os.Parcelable
static final int
static final int

Constants

CREATOR

@Keep
public static final Parcelable.Creator<TraceCREATOR

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

MAX_ATTRIBUTE_KEY_LENGTH

public static final int MAX_ATTRIBUTE_KEY_LENGTH = 40

Maximum allowed length of the Key of theTrace attribute

MAX_ATTRIBUTE_VALUE_LENGTH

public static final int MAX_ATTRIBUTE_VALUE_LENGTH = 100

Maximum allowed length of the Value of theTrace attribute

MAX_TRACE_CUSTOM_ATTRIBUTES

public static final int MAX_TRACE_CUSTOM_ATTRIBUTES = 5

Maximum allowed number of attributes allowed in a trace.

MAX_TRACE_NAME_LENGTH

public static final int MAX_TRACE_NAME_LENGTH = 100

Maximum allowed length of the name of theTrace

Public fields

name

public final String name

Public methods

describeContents

@Keep
public int describeContents()

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

Returns
int

always returns 0.

See also
Parcelable

getAttribute

@Keep
public @NullableString getAttribute(@NonNullString attribute)

Returns the value of an attribute.

Parameters
@NonNullString attribute

name of the attribute to fetch the value for

Returns
@NullableString

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

getAttributes

@Keep
public @NonNullMap<StringStringgetAttributes()

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

Returns
@NonNullMap<StringString>

map of attributes and its values currently added to this Trace

getLongMetric

@Keep
public long getLongMetric(@NonNullString metricName)

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
@NonNullString metricName

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
public void incrementMetric(@NonNullString metricName, long incrementBy)

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
@NonNullString metricName

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

long incrementBy

Amount by which the metric has to be incremented.

putAttribute

@Keep
public void putAttribute(@NonNullString attribute, @NonNullString value)

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 areMAX_TRACE_CUSTOM_ATTRIBUTES.

Parameters
@NonNullString attribute

Name of the attribute

@NonNullString value

Value of the attribute

putMetric

@Keep
public void putMetric(@NonNullString metricName, long value)

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
@NonNullString metricName

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

long value

The value to which the metric should be set to.

removeAttribute

@Keep
public void removeAttribute(@NonNullString attribute)

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

Parameters
@NonNullString attribute

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

start

@Keep
public void start()

Starts this trace.

stop

@Keep
public void stop()

Stops this trace.

writeToParcel

@Keep
public void writeToParcel(@NonNullParcel out, int flags)

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

Parameters
@NonNullParcel out

the Parcel in which the object should be written.

int flags

Additional flags about how the object should be written.

Extension functions

PerformanceKt.trace

public final @NonNull T <T extends Object>PerformanceKt.trace(
    @NonNullTrace receiver,
    @ExtensionFunctionType @NonNull Function1<@NonNullTrace, @NonNull T> block
)

Measures the time it takes to run theblock wrapped by calls to start and stop usingTrace.

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-07-21 UTC.