Class ProfilerController

Object
org.mozilla.geckoview.ProfilerController

@UiThread public class ProfilerController extends Object
ProfilerController is used to manage GeckoProfiler related features.

If you want to add a profiler marker to mark a point in time (without a duration) you can directly use profilerController.addMarker("marker name"). Or if you want to provide more information, you can use profilerController.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: Double startTime = profilerController.getProfilerTime(); ...some code you want to measure... profilerController.addMarker("name", startTime); Or you can capture start and end time in somewhere, then add the marker in somewhere else: Double startTime = profilerController.getProfilerTime(); ...some code you want to measure (or end time can be collected in a callback)... Double endTime = profilerController.getProfilerTime(); ...somewhere else in the codebase... profilerController.addMarker("name", startTime, endTime); Here's an addMarker example with all the possible parameters: Double startTime = profilerController.getProfilerTime(); ...some code you want to measure... Double endTime = profilerController.getProfilerTime(); ...somewhere else in the codebase... profilerController.addMarker("name", startTime, endTime, "extra information"); 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:

 
     Double startTime = profilerController.getProfilerTime();
     ...some code you want to measure...
     if (profilerController.isProfilerActive()) {
         String info = aFunctionYouDoNotWantToCallWhenProfilerIsNotActive();
         profilerController.addMarker("name", startTime, info);
     }
 
 
FIXME(bug 1618560): Currently only works in the main thread.
  • Constructor Details

    • ProfilerController

      public ProfilerController()
  • Method Details

    • isProfilerActive

      public boolean isProfilerActive()
      Returns true if profiler is active and it's allowed the add markers. It's useful when it's computationally heavy to get startTime or the additional text for the marker. That code can be wrapped with isProfilerActive if check to reduce the overhead of it.
      Returns:
      true if profiler is active and safe to add a new marker.
    • getProfilerTime

      @Nullable public Double getProfilerTime()
      Get the profiler time to be able to mark the start of the marker events. can be used like this: Double startTime = profilerController.getProfilerTime(); ...some code you want to measure... profilerController.addMarker("name", startTime);
      Returns:
      profiler time as double or null if the profiler is not active.
    • addMarker

      public void addMarker(@NonNull String aMarkerName, @Nullable Double aStartTime, @Nullable Double aEndTime, @Nullable String aText)
      Add a profiler marker to Gecko Profiler with the given arguments. No-op if profiler is not active.
      Parameters:
      aMarkerName - Name of the event as a string.
      aStartTime - Start time as Double. It can be null if you want to mark a point of time.
      aEndTime - End time as Double. If it's null, this function implicitly gets the end time.
      aText - An optional string field for more information about the marker.
    • addMarker

      public void addMarker(@NonNull String aMarkerName, @Nullable Double aStartTime, @Nullable String aText)
      Add a profiler marker to Gecko Profiler with the given arguments. End time will be added automatically with the current profiler time when the function is called. No-op if profiler is not active. This is an overload of addMarker(String, Double, Double, String) for convenience.
      Parameters:
      aMarkerName - Name of the event as a string.
      aStartTime - Start time as Double. It can be null if you want to mark a point of time.
      aText - An optional string field for more information about the marker.
    • addMarker

      public void addMarker(@NonNull String aMarkerName, @Nullable Double aStartTime)
      Add a profiler marker to Gecko Profiler with the given arguments. End time will be added automatically with the current profiler time when the function is called. No-op if profiler is not active. This is an overload of addMarker(String, Double, Double, String) for convenience.
      Parameters:
      aMarkerName - Name of the event as a string.
      aStartTime - Start time as Double. It can be null if you want to mark a point of time.
    • addMarker

      public void addMarker(@NonNull String aMarkerName, @Nullable String aText)
      Add a profiler marker to Gecko Profiler with the given arguments. Time will be added automatically with the current profiler time when the function is called. No-op if profiler is not active. This is an overload of addMarker(String, Double, Double, String) for convenience.
      Parameters:
      aMarkerName - Name of the event as a string.
      aText - An optional string field for more information about the marker.
    • addMarker

      public void addMarker(@NonNull String aMarkerName)
      Add a profiler marker to Gecko Profiler with the given arguments. Time will be added automatically with the current profiler time when the function is called. No-op if profiler is not active. This is an overload of addMarker(String, Double, Double, String) for convenience.
      Parameters:
      aMarkerName - Name of the event as a string.
    • startProfiler

      public void startProfiler(@NonNull String[] aFilters, @NonNull String[] aFeaturesArr)
      Start the Gecko profiler with the given settings. This is used by embedders which want to control the profiler from the embedding app. This allows them to provide an easier access point to profiling, as an alternative to the traditional way of using a desktop Firefox instance connected via USB + adb.
      Parameters:
      aFilters - The list of threads to profile, as an array of string of thread names filters. Each filter is used as a case-insensitive substring match against the actual thread names.
      aFeaturesArr - The list of profiler features to enable for profiling, as a string array.
    • stopProfiler

      @NonNull public GeckoResult<byte[]> stopProfiler()
      Stop the profiler and capture the recorded profile. This method is asynchronous.
      Returns:
      GeckoResult for the captured profile. The profile is returned as a byte[] buffer containing a gzip-compressed payload (with gzip header) of the profile JSON.