diff options
| author | Tim Volodine <timvolodine@google.com> | 2018-01-18 20:14:08 +0000 |
|---|---|---|
| committer | Tim Volodine <timvolodine@google.com> | 2018-02-15 13:26:39 +0000 |
| commit | 88604f2f8ac07283fa70ec2feb3aaeadcedaf0ce (patch) | |
| tree | 66f9c6638557683493db26096962d7a5402678ce /core/java/android/webkit/TracingController.java | |
| parent | e6c2b50229bb370b57fd769c28496c550c50c499 (diff) | |
WebView Tracing API: address comments from the API council.
Address comments from the API council regarding the WebView Tracing API.
android.webkit.TracingController:
* start() throws IllegalStateException if the system is already tracing
(this is instead of returning false)
* stop uses Executor instead of Handler
* removed stop() (the method w/o arguments)
* renamed stopAndFlush to stop
* use OutputStream instead of a custom callback interface TracingOutputStream
* dropped requirement for UI threading
* updated documentation
android.webkit.TracingFileOutputStream:
* removed the TracingFileOutputStream file completely (functionality
replaced by the existing FileOutputStream)
android.webkit.TracingConfig:
* removed example with CATEGORIES_NONE and “-input,-gpu”.
* customCategories are List<String> instead of String
* updated documentation
* added two more predefined categories: CATEGORIES_ALL,
CATEGORIES_ANDROID_WEBVIEW
* some refactoring, added a Builder class
* ensure that only include category patterns can be specified
* uniform addCategories interface for construction
* predefined category sets are a bitmask now
BUG: 71584598,71584599,63750258
Test: CTS
Change-Id: I615ef5f43d26968329182b09e7c26178f1f85ecc
Diffstat (limited to 'core/java/android/webkit/TracingController.java')
| -rw-r--r-- | core/java/android/webkit/TracingController.java | 78 |
1 files changed, 23 insertions, 55 deletions
diff --git a/core/java/android/webkit/TracingController.java b/core/java/android/webkit/TracingController.java index cadb8a184072..7871021a33c8 100644 --- a/core/java/android/webkit/TracingController.java +++ b/core/java/android/webkit/TracingController.java @@ -16,9 +16,12 @@ package android.webkit; +import android.annotation.CallbackExecutor; import android.annotation.NonNull; import android.annotation.Nullable; -import android.os.Handler; + +import java.io.OutputStream; +import java.util.concurrent.Executor; /** * Manages tracing of WebViews. In particular provides functionality for the app @@ -29,40 +32,22 @@ import android.os.Handler; * The resulting trace data is sent back as a byte sequence in json format. This * file can be loaded in "chrome://tracing" for further analysis. * <p> - * Note: All methods in this class must be called on the UI thread. All callbacks - * are also called on the UI thread. - * <p> * Example usage: * <pre class="prettyprint"> * TracingController tracingController = TracingController.getInstance(); - * tracingController.start(new TraceConfig(CATEGORIES_WEB_DEVELOPER)); + * tracingController.start(new TraceConfig.Builder() + * .addCategories(CATEGORIES_WEB_DEVELOPER).build()); * [..] - * tracingController.stopAndFlush(new TraceFileOutput("trace.json"), null); + * tracingController.stop(new FileOutputStream("trace.json"), + * Executors.newSingleThreadExecutor()); * </pre></p> */ public abstract class TracingController { /** - * Interface for capturing tracing data. - */ - public interface TracingOutputStream { - /** - * Will be called to return tracing data in chunks. - * Tracing data is returned in json format an array of bytes. - */ - void write(byte[] chunk); - - /** - * Called when tracing is finished and the data collection is over. - * There will be no calls to #write after #complete is called. - */ - void complete(); - } - - /** * Returns the default TracingController instance. At present there is * only one TracingController instance for all WebView instances, - * however this restriction may be relaxed in the future. + * however this restriction may be relaxed in a future Android release. * * @return the default TracingController instance */ @@ -72,55 +57,38 @@ public abstract class TracingController { } /** - * Starts tracing all webviews. Depeding on the trace mode in traceConfig + * Starts tracing all webviews. Depending on the trace mode in traceConfig * specifies how the trace events are recorded. * * For tracing modes {@link TracingConfig#RECORD_UNTIL_FULL}, * {@link TracingConfig#RECORD_CONTINUOUSLY} and * {@link TracingConfig#RECORD_UNTIL_FULL_LARGE_BUFFER} the events are recorded * using an internal buffer and flushed to the outputStream when - * {@link #stopAndFlush(TracingOutputStream, Handler)} is called. + * {@link #stop(OutputStream, Executor)} is called. * * @param tracingConfig configuration options to use for tracing - * @return false if the system is already tracing, true otherwise. + * @throws IllegalStateException if the system is already tracing. */ - public abstract boolean start(TracingConfig tracingConfig); + public abstract void start(@NonNull TracingConfig tracingConfig); /** - * Stops tracing and discards all tracing data. + * Stops tracing and flushes tracing data to the specified outputStream. * - * This method is particularly useful in conjunction with the - * {@link TracingConfig#RECORD_TO_CONSOLE} tracing mode because tracing data is logged to - * console and not sent to an outputStream as with - * {@link #stopAndFlush(TracingOutputStream, Handler)}. + * The data is sent to the specified output stream in json format typically + * in chunks by invoking {@link java.io.OutputStream#write(byte[])}. On completion + * the {@link java.io.OutputStream#close()} method is called. * + * @param outputStream the output steam the tracing data will be sent to. If null + * the tracing data will be discarded. + * @param executor the {@link java.util.concurrent.Executor} on which the + * outputStream #write and #close methods will be invoked. * @return false if the system was not tracing at the time of the call, true * otherwise. */ - public abstract boolean stop(); - - /** - * Stops tracing and flushes tracing data to the specifid outputStream. - * - * Note that if the {@link TracingConfig#RECORD_TO_CONSOLE} tracing mode is used - * nothing will be sent to the outputStream and no TracingOuputStream methods will be - * called. In that case it is more convenient to just use {@link #stop()} instead. - * - * @param outputStream the output steam the tracing data will be sent to. - * @param handler the {@link android.os.Handler} on which the outputStream callbacks - * will be invoked. If the handler is null the current thread's Looper - * will be used. - * @return false if the system was not tracing at the time of the call, true - * otherwise. - */ - public abstract boolean stopAndFlush(TracingOutputStream outputStream, - @Nullable Handler handler); + public abstract boolean stop(@Nullable OutputStream outputStream, + @NonNull @CallbackExecutor Executor executor); /** True if the system is tracing */ public abstract boolean isTracing(); - // TODO: consider adding getTraceBufferUsage, percentage and approx event count. - // TODO: consider adding String getCategories(), for obtaining the actual list - // of categories used (given that presets are ints). - } |
