Trace

public class Trace extends Object
implements Parcelable

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

Constant Summary

int MAX_ATTRIBUTE_KEY_LENGTH Maximum allowed length of the Key of the Trace attribute
int MAX_ATTRIBUTE_VALUE_LENGTH Maximum allowed length of the Value of the Trace attribute
int MAX_TRACE_CUSTOM_ATTRIBUTES Maximum allowed number of attributes allowed in a trace.
int MAX_TRACE_NAME_LENGTH Maximum allowed length of the name of the Trace

Inherited Constant Summary

Field Summary

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

Public Method Summary

int
describeContents()
Describes the kinds of special objects contained in this Parcelable's marshalled representation.
String
getAttribute(String attribute)
Returns the value of an attribute.
Map<StringString>
getAttributes()
Returns the map of all the attributes added to this trace.
long
getLongMetric(String metricName)
Gets the value of the metric with the given name in the current trace.
void
incrementCounter(String counterName, long incrementBy)
This method was deprecated. Please use incrementMetric(String, long) instead.
void
incrementCounter(String counterName)
This method was deprecated. Please use incrementMetric(String, long) instead.
void
incrementMetric(String metricName, long incrementBy)
Atomically increments the metric with the given name in this trace by the incrementBy value.
void
putAttribute(String attribute, String value)
Sets a String value for the specified attribute.
void
putMetric(String metricName, long value)
Sets the value of the metric with the given name in this trace to the value provided.
void
removeAttribute(String attribute)
Removes an already added attribute from the Traces.
void
start()
Starts this trace.
void
stop()
Stops this trace.
void
writeToParcel(Parcel out, int flags)
Flatten this object into a Parcel.

Inherited Method Summary

Constants

public static final int MAX_ATTRIBUTE_KEY_LENGTH

Maximum allowed length of the Key of the Trace attribute

Constant Value: 40

public static final int MAX_ATTRIBUTE_VALUE_LENGTH

Maximum allowed length of the Value of the Trace attribute

Constant Value: 100

public static final int MAX_TRACE_CUSTOM_ATTRIBUTES

Maximum allowed number of attributes allowed in a trace.

Constant Value: 5

public static final int MAX_TRACE_NAME_LENGTH

Maximum allowed length of the name of the Trace

Constant Value: 100

Fields

public static final Creator<Trace> CREATOR

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

Public Methods

public int describeContents ()

Describes the kinds of special objects contained in this Parcelable's marshalled representation. Please refer to //developer.android.com/reference/android/os/Parcelable.html

Returns
  • always returns 0.

public String getAttribute (String attribute)

Returns the value of an attribute.

Parameters
attribute name of the attribute to fetch the value for
Returns
  • the value of the attribute if it exists or null otherwise.

public Map<StringString> getAttributes ()

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

Returns
  • map of attributes and its values currently added to this Trace

public long getLongMetric (String 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
metricName Name of the metric to get. Requires no leading or trailing whitespace, no leading underscore '_' character, max length is 32 characters.
Returns
  • Value of the metric or 0 if it hasn't yet been set.

public void incrementCounter (String counterName, long incrementBy)

This method was deprecated.
Please use incrementMetric(String, long) instead.

Increments the counter in this trace with the given name by given value. If a counter does not already 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
counterName Name of the counter to be incremented. Requires no leading or trailing whitespace, no leading underscore [_] character, max length of 32 characters.
incrementBy Amount by which the counter has to be incremented.

public void incrementCounter (String counterName)

This method was deprecated.
Please use incrementMetric(String, long) instead.

Increments the counter in this trace with the given name by one. If a counter does not already 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
counterName Name of the counter to be incremented. Requires no leading or trailing whitespace, no leading underscore '_' character, max length is 32 characters.

public void incrementMetric (String 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
metricName Name of the metric to be incremented. Requires no leading or trailing whitespace, no leading underscore [_] character, max length of 32 characters.
incrementBy Amount by which the metric has to be incremented.

public void putAttribute (String attribute, String 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 are .MAX_TRACE_CUSTOM_ATTRIBUTES.

Parameters
attribute Name of the attribute
value Value of the attribute
Returns
  • true if the attribute was added, false otherwise.

public void putMetric (String 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
metricName Name of the metric to set. Requires no leading or trailing whitespace, no leading underscore '_' character, max length is 32 characters.
value The value to which the metric should be set to.

public void removeAttribute (String attribute)

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

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

public void start ()

Starts this trace.

public void stop ()

Stops this trace.

public void writeToParcel (Parcel out, int flags)

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

Parameters
out the Parcel in which the object should be written.
flags Additional flags about how the object should be written.