Package com.android.utils
Class FlightRecorder
- java.lang.Object
-
- com.android.utils.FlightRecorder
-
public class FlightRecorder extends java.lang.ObjectFast in-memory log utilizing a cyclic buffer of a limited size. Intended to be used when alternative logging methods are too slow, for example, in the following scenario:- There is an expected behavior in the code, possibly caused by a race condition.
- You add logging to the code to investigate the problem.
- The problem is no longer reproducible with logging enabled.
You may try to replace the regular logging with:
FlightRecorder.initialize(100); ... FlightRecorder.log(something); ... FlightRecorder.log(somethingElse); ... if (unexpectedBehaviorDetected) { FlightRecorder.print(); }
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.util.List<java.lang.Object>getAndClear()Returns the contents of the log and clears the log.static voidinitialize(int sizeLimit)Initializes the log.static voidlog(java.lang.Object record)Writes a record to the log if it was initialized.static voidlog(java.util.function.Supplier<?> lazyRecord)Writes a record to the log if it was initialized.static voidprint()Prints the contents of the log to stdout and clears the log.
-
-
-
Method Detail
-
initialize
public static void initialize(int sizeLimit)
Initializes the log. At most lastsizeLimitrecords will be preserved in the log. The prior contents of the log up tosizeLimitrecords are preserved.- Parameters:
sizeLimit- the maximum number of records to store
-
log
public static void log(@NonNull java.lang.Object record)Writes a record to the log if it was initialized.- Parameters:
record- an arbitrary object to log
-
log
public static void log(@NonNull java.util.function.Supplier<?> lazyRecord)Writes a record to the log if it was initialized. The object being logged is evaluated only if the log was initialized with a non-zero size.- Parameters:
lazyRecord- the supplier of the object to log
-
getAndClear
@NonNull public static java.util.List<java.lang.Object> getAndClear()
Returns the contents of the log and clears the log.
-
print
public static void print()
Prints the contents of the log to stdout and clears the log.
-
-