All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hubspot.chrome.devtools.client.core.tracing.Tracing Maven / Gradle / Ivy

package com.hubspot.chrome.devtools.client.core.tracing;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.hubspot.chrome.devtools.base.ChromeRequest;
import com.hubspot.chrome.devtools.base.ChromeSessionCore;
import java.util.List;
import java.util.concurrent.CompletableFuture;

public final class Tracing {
  ChromeSessionCore chromeSession;

  ObjectMapper objectMapper;

  public Tracing(ChromeSessionCore chromeSession, ObjectMapper objectMapper) {
    this.chromeSession = chromeSession;
    this.objectMapper = objectMapper;
  }

  /**
   * Stop trace events collection.
   */
  public void end() {
    ChromeRequest chromeRequest = new ChromeRequest("Tracing.end");
    chromeSession.send(chromeRequest);
  }

  /**
   * Stop trace events collection.
   */
  public void endAsync() {
    ChromeRequest chromeRequest = new ChromeRequest("Tracing.end");
    chromeSession.sendAsync(chromeRequest);
  }

  /**
   * Gets supported tracing categories.
   */
  public List getCategories() {
    ChromeRequest chromeRequest = new ChromeRequest("Tracing.getCategories");
    return chromeSession.send(chromeRequest, new TypeReference>(){});
  }

  /**
   * Gets supported tracing categories.
   */
  public CompletableFuture> getCategoriesAsync() {
    ChromeRequest chromeRequest = new ChromeRequest("Tracing.getCategories");
    return chromeSession.sendAsync(chromeRequest, new TypeReference>(){});
  }

  /**
   * Record a clock sync marker in the trace.
   *
   * @param syncId  The ID of this clock sync marker
   */
  public void recordClockSyncMarker(String syncId) {
    ChromeRequest chromeRequest = new ChromeRequest("Tracing.recordClockSyncMarker");
    chromeRequest
        .putParams("syncId", syncId);
    chromeSession.send(chromeRequest);
  }

  /**
   * Record a clock sync marker in the trace.
   *
   * @param syncId  The ID of this clock sync marker
   */
  public void recordClockSyncMarkerAsync(String syncId) {
    ChromeRequest chromeRequest = new ChromeRequest("Tracing.recordClockSyncMarker");
    chromeRequest
        .putParams("syncId", syncId);
    chromeSession.sendAsync(chromeRequest);
  }

  /**
   * Request a global memory dump.
   */
  public RequestMemoryDumpResult requestMemoryDump() {
    ChromeRequest chromeRequest = new ChromeRequest("Tracing.requestMemoryDump");
    return chromeSession.send(chromeRequest, new TypeReference(){});
  }

  /**
   * Request a global memory dump.
   */
  public CompletableFuture requestMemoryDumpAsync() {
    ChromeRequest chromeRequest = new ChromeRequest("Tracing.requestMemoryDump");
    return chromeSession.sendAsync(chromeRequest, new TypeReference(){});
  }

  /**
   * Start trace events collection.
   *
   * @param categories [Optional] Category/tag filter
   * @param options [Optional] Tracing options
   * @param bufferUsageReportingInterval [Optional] If set, the agent will issue bufferUsage events at this interval, specified in milliseconds
   * @param transferMode [Optional] Whether to report trace events as series of dataCollected events or to save trace to a
   * stream (defaults to `ReportEvents`).
   * @param streamCompression [Optional] Compression format to use. This only applies when using `ReturnAsStream`
   * transfer mode (defaults to `none`)
   */
  public void start(String categories, String options, Number bufferUsageReportingInterval,
      String transferMode, StreamCompression streamCompression, TraceConfig traceConfig) {
    ChromeRequest chromeRequest = new ChromeRequest("Tracing.start");
    chromeRequest
        .putParams("categories", categories)
        .putParams("options", options)
        .putParams("bufferUsageReportingInterval", bufferUsageReportingInterval)
        .putParams("transferMode", transferMode)
        .putParams("streamCompression", streamCompression)
        .putParams("traceConfig", traceConfig);
    chromeSession.send(chromeRequest);
  }

  /**
   * Start trace events collection.
   *
   * @param categories [Optional] Category/tag filter
   * @param options [Optional] Tracing options
   * @param bufferUsageReportingInterval [Optional] If set, the agent will issue bufferUsage events at this interval, specified in milliseconds
   * @param transferMode [Optional] Whether to report trace events as series of dataCollected events or to save trace to a
   * stream (defaults to `ReportEvents`).
   * @param streamCompression [Optional] Compression format to use. This only applies when using `ReturnAsStream`
   * transfer mode (defaults to `none`)
   */
  public void startAsync(String categories, String options, Number bufferUsageReportingInterval,
      String transferMode, StreamCompression streamCompression, TraceConfig traceConfig) {
    ChromeRequest chromeRequest = new ChromeRequest("Tracing.start");
    chromeRequest
        .putParams("categories", categories)
        .putParams("options", options)
        .putParams("bufferUsageReportingInterval", bufferUsageReportingInterval)
        .putParams("transferMode", transferMode)
        .putParams("streamCompression", streamCompression)
        .putParams("traceConfig", traceConfig);
    chromeSession.sendAsync(chromeRequest);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy