Class TraceEventWriter

java.lang.Object
io.perfmark.tracewriter.TraceEventWriter

public final class TraceEventWriter extends Object
Writes the PerfMark results to a "Trace Event" JSON file usable by the Chromium Profiler "Catapult". The format is defined at ...

This code is NOT API stable, and may be removed in the future, or changed without notice.

Since:
0.16.0
  • Field Details

  • Constructor Details

    • TraceEventWriter

      public TraceEventWriter()
  • Method Details

    • writeTraceEvents

      @CanIgnoreReturnValue public static Path writeTraceEvents() throws IOException
      Writes trace events the home directory. By default, it prefers the location in $XDG_DATA_HOME/perfmark environment variable. If unset, it attempts to use $HOME/.local/share/perfmark.

      Authors note: if you are on Windows, or the above defaults aren't right, I'm not really sure where else is a good place to put this data. Please file an issue at https://www.perfmark.io/ if you have a preference.

      Updated in 0.17.0 to return the created path.

      Returns:
      the path used to create the trace file.
      Throws:
      IOException - if there is an error writing to the file.
    • writeTraceEvents

      public static void writeTraceEvents(Writer destination) throws IOException
      Writes all trace events in JSON format to the given destination.
      Parameters:
      destination - the destination for the JSON data.
      Throws:
      IOException - if there are errors build the JSON, or can't write to the destination.
    • writeTraceEvents

      public static void writeTraceEvents(Writer destination, List<? extends MarkList> markLists, long initNanoTime, long nowNanoTime, long pid) throws IOException
      Writes the trace events gathered from Storage.read(). This method is not API stable. It will be eventually.
      Parameters:
      destination - the destination for the JSON data.
      markLists - the data to use to build the trace event JSON
      initNanoTime - the time PerfMark classes were first loaded as specified by System.nanoTime()
      nowNanoTime - the current time as specified by System.nanoTime().
      pid - the PID of the current process.
      Throws:
      IOException - if there are errors build the JSON, or can't write to the destination.
    • writeTraceEventObject

      private static void writeTraceEventObject(Writer dest, List<TraceEvent> events) throws IOException
      Throws:
      IOException
    • maybeAddComment

      private static boolean maybeAddComment(Writer writer, boolean firstOf) throws IOException
      Throws:
      IOException
    • pickNextDest

      private static Path pickNextDest(Path dir) throws IOException
      Throws:
      IOException
    • guessDirectory

      private static Path guessDirectory() throws IOException
      Throws:
      IOException
    • getPid

      private static long getPid()
    • taskName

      private static String taskName(Mark mark)
    • writeString

      private static void writeString(Writer writer, String s) throws IOException
      Throws:
      IOException