Metrics
The Metrics Plugin is used to gather timing information about Player’s execution of a flow. There are also platform specific integrations to include render
and update
times.
The diagram below illistrates some of the timing information gathered:
Usage
Add the plugin to Player:
The onUpdate
callback will be invoked for any update to the metrics. There are also callbacks for finer-grained events (onRenderEnd
, onInteractive
, etc), as well as a hooks
based API for even more control.
Using a custom timer
By default, all time is measured in ms using performance.now()
with a fallback to the less-accurate Date.now()
.
If you wish to supply your own timer, simply use the getTime
option to set the function to use.
Measuring Render Time
For extensions of this plugin that wish to track the render (and update) times of nodes, add the trackRenderTime
flag to options
. You must then call metrics.renderEnd()
to denote when content is painted on the screen. This is automatically handled for the platform specific versions of this plugin.
The react
version of the Metrics Plugin adds support for render
and update
times to events. The API mirrors that of the core version:
The JVM
Metrics plugin can track render time for views in a flow.
In build.gradle
In Player constructor
The ios
version of the Metrics Plugin will track initial render time for each view in a flow. Due to current SwiftUI limitations, update time can’t be tracked yet. It can be used in conjunction with a core plugin that utilizes the events, through findPlugin
, or standalone.
CocoaPods
Add the subspec to your Podfile
Swift Usage
Beaconing
The Metrics Plugin also includes a plugin for the Beacon Plugin that adds render time to the hook context for viewed
beacons send for views. This plugin is automatically registered to the Beacon Plugin if the trackRenderTime
option is enabled.
In order to actually include the render-time in a beacon, you must create a BeaconPluginPlugin
that maps the renderTime from the hook’s context to the actual beacon object. It can be accessed through the MetricsViewBeaconPluginContextSymbol
key:
See the Beacon Plugin for more info.