Class Generator


  • @NotThreadSafe
    public abstract class Generator
    extends java.lang.Object
    A Generator keeps track of what generation the PerfMark library is on. A generation is a way to group PerfMark recorded tasks and links together. This allows dynamically enabling and disabling PerfMark. Each time the library is enabled, a new generation is started and associated with all the recorded data.

    Normal users are not expected to use this class.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      static long FAILURE
      Represents a failure to enable PerfMark library.
      static int GEN_OFFSET
      The number of reserved bits at the bottom of the generation.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected Generator()  
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      long costOfGetNanos()
      Returns the approximate cost to read the generation.
      long costOfSetNanos()
      Returns the approximate cost to change the generation.
      abstract long getGeneration()
      Gets the current generation, shifted left by GEN_OFFSET.
      abstract void setGeneration​(long generation)
      Sets the current generation count.
      • Methods inherited from class java.lang.Object

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

      • GEN_OFFSET

        public static final int GEN_OFFSET
        The number of reserved bits at the bottom of the generation. All generations should be left-shifted by this amount.
        See Also:
        Constant Field Values
      • FAILURE

        public static final long FAILURE
        Represents a failure to enable PerfMark library. This can be used by subclasses to indicate a previous failure to set the generation. It can also be used to indicate the generation count has overflowed.
        See Also:
        Constant Field Values
    • Constructor Detail

      • Generator

        protected Generator()
    • Method Detail

      • setGeneration

        public abstract void setGeneration​(long generation)
        Sets the current generation count. This should be eventually noticeable for callers of getGeneration(). An odd number means the library is enabled, while an even number means the library is disabled.
        Parameters:
        generation - the generation id, shifted left by GEN_OFFSET.
      • getGeneration

        public abstract long getGeneration()
        Gets the current generation, shifted left by GEN_OFFSET. An odd number means the library is enabled, while an even number means the library is disabled.
        Returns:
        the current generation or FAILURE.
      • costOfSetNanos

        public long costOfSetNanos()
        Returns the approximate cost to change the generation.
        Returns:
        an approximate number of nanoseconds needed to change the generator value.
      • costOfGetNanos

        public long costOfGetNanos()
        Returns the approximate cost to read the generation.
        Returns:
        an approximate number of nanoseconds needed to read the generator value.