Profiler.kt |
[Profiler] is being used to manage Firefox Profiler related features.
If you want to add a profiler marker to mark a point in time (without a duration)
you can directly use `engine.profiler?.addMarker("marker name")`.
Or if you want to provide more information, you can use
`engine.profiler?.addMarker("marker name", "extra information")`.
If you want to add a profiler marker with a duration (with start and end time)
you can use it like this, it will automatically get the end time inside the addMarker:
```
val startTime = engine.profiler?.getProfilerTime()
...some code you want to measure...
engine.profiler?.addMarker("name", startTime)
```
Or you can capture start and end time in somewhere, then add the marker in somewhere else:
```
val startTime = engine.profiler?.getProfilerTime()
...some code you want to measure (or end time can be collected in a callback)...
val endTime = engine.profiler?.getProfilerTime()
...somewhere else in the codebase...
engine.profiler?.addMarker("name", startTime, endTime)
```
Here's an [Profiler.addMarker] example with all the possible parameters:
```
val startTime = engine.profiler?.getProfilerTime()
...some code you want to measure...
val endTime = engine.profiler?.getProfilerTime()
...somewhere else in the codebase...
engine.profiler?.addMarker("name", startTime, endTime, "extra information")
```
[Profiler.isProfilerActive] method is handy when you want to get more information to
add inside the marker, but you think it's going to be computationally heavy (and useless)
when profiler is not running:
```
val startTime = engine.profiler?.getProfilerTime()
...some code you want to measure...
if (engine.profiler?.isProfilerActive()) {
val info = aFunctionYouDoNotWantToCallWhenProfilerIsNotActive()
engine.profiler?.addMarker("name", startTime, info)
}
```
|
6981 |