Add the ability to trace methods in internal builds.

Currently only for internal builds. Use the @Trace annotation to trace
methods for viewing in Perfetto.
This commit is contained in:
Greyson Parrelli
2020-11-10 12:40:50 -05:00
committed by Cody Henthorne
parent c3b5323010
commit 0b77b33902
52 changed files with 720 additions and 4 deletions

View File

@@ -0,0 +1,14 @@
package org.thoughtcrime.securesms.tracing;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import static java.lang.annotation.ElementType.CONSTRUCTOR;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.CLASS;
@Target({TYPE, METHOD, CONSTRUCTOR}) @Retention(CLASS)
public @interface Trace {
}

View File

@@ -0,0 +1,45 @@
package org.thoughtcrime.securesms.tracing;
import androidx.annotation.NonNull;
/**
* A class to create Perfetto-compatible traces.
*/
public interface Tracer {
TracerImpl INSTANCE = new TracerImpl();
static @NonNull Tracer getInstance() {
return INSTANCE;
}
/**
* True if enabled, otherwise false.
*/
boolean isEnabled();
/**
* Marks the start of a method call. Always follow this with a call to {@link #end(String)}.
*/
void start(@NonNull String methodName);
/**
* Marks the start of a method call. Always follow this with a call to {@link #end(String)}.
*
* Includes the ability to pass a key-value pair that will be shown in the trace when you click
* on the slice.
*/
void start(@NonNull String methodName, @NonNull String key, @NonNull String value);
/**
* Marks the end of a method call.
*/
void end(@NonNull String methodName);
/**
* Serializes the current state of the trace to a Perfetto-compatible byte array. Note that
* there's no locking here, and therefore tracing will continue. We're just grabbing a best-effort
* snapshot.
*/
@NonNull byte[] serialize();
}