Class TraceEventWriter


  • public final class TraceEventWriter
    extends java.lang.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 Summary

      Fields 
      Modifier and Type Field Description
      private static java.lang.String HEX_TABLE  
      private static java.util.logging.Logger logger  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      private static long getPid()  
      private static java.nio.file.Path guessDirectory()  
      private static boolean maybeAddComment​(java.io.Writer writer, boolean firstOf)  
      private static java.nio.file.Path pickNextDest​(java.nio.file.Path dir)  
      private static java.lang.String taskName​(Mark mark)  
      private static void writeString​(java.io.Writer writer, java.lang.String s)  
      private static void writeTraceEventObject​(java.io.Writer dest, java.util.List<TraceEvent> events)  
      static java.nio.file.Path writeTraceEvents()
      Writes trace events the home directory.
      static void writeTraceEvents​(java.io.Writer destination)
      Writes all trace events in JSON format to the given destination.
      static void writeTraceEvents​(java.io.Writer destination, java.util.List<? extends MarkList> markLists, long initNanoTime, long nowNanoTime, long pid)
      Writes the trace events gathered from Storage.read().
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • logger

        private static final java.util.logging.Logger logger
    • Constructor Detail

      • TraceEventWriter

        public TraceEventWriter()
    • Method Detail

      • writeTraceEvents

        @CanIgnoreReturnValue
        public static java.nio.file.Path writeTraceEvents()
                                                   throws java.io.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:
        java.io.IOException - if there is an error writing to the file.
      • writeTraceEvents

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

        public static void writeTraceEvents​(java.io.Writer destination,
                                            java.util.List<? extends MarkList> markLists,
                                            long initNanoTime,
                                            long nowNanoTime,
                                            long pid)
                                     throws java.io.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:
        java.io.IOException - if there are errors build the JSON, or can't write to the destination.
      • writeTraceEventObject

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

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

        private static java.nio.file.Path pickNextDest​(java.nio.file.Path dir)
                                                throws java.io.IOException
        Throws:
        java.io.IOException
      • guessDirectory

        private static java.nio.file.Path guessDirectory()
                                                  throws java.io.IOException
        Throws:
        java.io.IOException
      • getPid

        private static long getPid()
      • taskName

        private static java.lang.String taskName​(Mark mark)
      • writeString

        private static void writeString​(java.io.Writer writer,
                                        java.lang.String s)
                                 throws java.io.IOException
        Throws:
        java.io.IOException