TracingController
abstract class TracingController
kotlin.Any | |
↳ | androidx.webkit.TracingController |
Manages tracing of WebViews. In particular provides functionality for the app to enable/disable tracing of parts of code and to collect tracing data. This is useful for profiling performance issues, debugging and memory usage analysis in production and real life scenarios.
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.
Example usage:
TracingController tracingController = TracingController.getInstance(); tracingController.start(new TracingConfig.Builder() .addCategories(CATEGORIES_WEB_DEVELOPER).build()); ... tracingController.stop(new FileOutputStream("trace.json"), Executors.newSingleThreadExecutor());
Summary
Public methods | |
---|---|
open static TracingController |
Returns the default |
abstract Boolean |
Returns whether the WebView framework is tracing. |
abstract Unit |
start(@NonNull tracingConfig: TracingConfig) Starts tracing all webviews. |
abstract Boolean |
stop(@Nullable outputStream: OutputStream?, @NonNull executor: Executor) Stops tracing and flushes tracing data to the specified outputStream. |
Public methods
getInstance
@NonNull open static fun getInstance(): TracingController
Returns the default TracingController
instance. At present there is only one TracingController instance for all WebView instances.
This method should only be called if WebViewFeature#isFeatureSupported(String)
returns true
for WebViewFeature#TRACING_CONTROLLER_BASIC_USAGE
.
isTracing
abstract fun isTracing(): Boolean
Returns whether the WebView framework is tracing.
Return | |
---|---|
Boolean |
True if tracing is enabled. |
start
abstract fun start(@NonNull tracingConfig: TracingConfig): Unit
Starts tracing all webviews. Depending on the trace mode in traceConfig specifies how the trace events are recorded.
For tracing modes android.webkit.TracingConfig#RECORD_UNTIL_FULL
and android.webkit.TracingConfig#RECORD_CONTINUOUSLY
the events are recorded using an internal buffer and flushed to the outputStream when stop(OutputStream, Executor)
is called.
This method should only be called if WebViewFeature#isFeatureSupported(String)
returns true
for WebViewFeature#TRACING_CONTROLLER_BASIC_USAGE
.
Parameters | |
---|---|
tracingConfig |
TracingConfig: Configuration options to use for tracing. |
Exceptions | |
---|---|
IllegalStateException |
If the system is already tracing. |
IllegalArgumentException |
If the configuration is invalid (e.g. invalid category pattern or invalid tracing mode). |
stop
abstract fun stop(
@Nullable outputStream: OutputStream?,
@NonNull executor: Executor
): Boolean
Stops tracing and flushes tracing data to the specified outputStream. The data is sent to the specified output stream in json format typically in chunks by invoking OutputStream#write(byte[])
. On completion the OutputStream#close() method is called.
This method should only be called if WebViewFeature#isFeatureSupported(String)
returns true
for WebViewFeature#TRACING_CONTROLLER_BASIC_USAGE
.
Parameters | |
---|---|
outputStream |
OutputStream?: The output stream the tracing data will be sent to. If null the tracing data will be discarded. |
executor |
Executor: The Executor on which the outputStream OutputStream#write(byte[]) and OutputStream#close() methods will be invoked. Callback and listener events are dispatched through this Executor, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use Context#getMainExecutor() . To dispatch events through a shared thread pool, you can use android.os.AsyncTask#THREAD_POOL_EXECUTOR . |
Return | |
---|---|
Boolean |
false if the WebView framework was not tracing at the time of the call, true otherwise. |