Class PerformanceMetrics


  • public final class PerformanceMetrics
    extends Object
    Performance metrics aid to collect time spent for execution of operation, including any sub operations, which results could be expected before the actual operation takes place. Each operation could be traced by key and level. Key should stay the same for all dependent measurements, when the level should vary depends on the step of measured sub operation.
    • Method Detail

      • createNew

        public static PerformanceMetrics createNew​(String action,
                                                   String descriptor,
                                                   String correlationId)
        Creates new instance of performance metrics. Generates new metrics key and assigns zero level.
        Parameters:
        action - a short name of measured operation, typically a first prefix of descriptor
        descriptor - a full description of measured operation
        correlationId - a reference to the request, which caused the operation
        Returns:
        PerformanceMetrics a new instance of performance metrics
      • createNext

        public PerformanceMetrics createNext​(String nextAction,
                                             String nextDescriptor)
        Creates new instance of performance metrics. Stores the key and correlation id of the parent metrics instance. Assigns next level.
        Parameters:
        nextAction - a short name of measured operation, typically a first prefix of descriptor
        nextDescriptor - a full description of measured operation
        Returns:
        PerformanceMetrics a new instance of performance metrics with stored key and correlationId from the parent metrics and assigned next level
      • createNext

        public PerformanceMetrics createNext​(String nextAction,
                                             String nextDescriptor,
                                             Class nextActionClass)
        Creates new instance of performance metrics. Stores the key and correlation id of the parent metrics instance. Assigns next level.
        Parameters:
        nextAction - a short name of measured operation, typically a first prefix of descriptor
        nextActionClass - a class which implements the action
        nextDescriptor - a full description of measured operation
        Returns:
        PerformanceMetrics a new instance of performance metrics with stored key and correlationId from the parent metrics and assigned next level
      • getStartAction

        public rx.functions.Action0 getStartAction()
        When called, start action sets time stamp to identify start time of operation.
        Returns:
        Action0
      • getEndAction

        public rx.functions.Action0 getEndAction()
        When called, end action sets time stamp to identify end time of operation and logs the metrics.
        Returns:
        Action0
      • getOnNextAction

        public <T> rx.functions.Action1<T> getOnNextAction()
        When called, end action sets time stamp to identify end time of operation and logs the metrics.
        Type Parameters:
        T - Any type
        Returns:
        Action0
      • setStartTimestamp

        public void setStartTimestamp()
        Set time stamp of operation start.
      • setOperationTimestamp

        public void setOperationTimestamp()
        Set time stamp of operation delegation.
      • setEndTimestamp

        public void setEndTimestamp()
        Set time stamp of operation end.
      • isCharged

        public boolean isCharged()
        Returns:
        true if start and end time of measured operation are set
      • isPreviousCharged

        public boolean isPreviousCharged()
        Returns:
        true if there is a sub operation, which start and end time are set
      • getLevel

        public Integer getLevel()
      • getAction

        public String getAction()
      • getActionClass

        public Class getActionClass()
      • getDescriptor

        public String getDescriptor()
      • getCorrelationId

        public String getCorrelationId()
      • getStartTime

        public Long getStartTime()
      • getOperationTime

        public Long getOperationTime()
      • getEndTime

        public Long getEndTime()
      • getTakenTimeByStep

        public Long getTakenTimeByStep()
        Returns:
        time in milliseconds taken by actual operation, excludes time taken by any measured sub operation
      • getTakenTimeByStepStart

        public Long getTakenTimeByStepStart()
        Returns:
        time in milliseconds spent by operation before sub operation was called
      • getTakenTimeByStepOperation

        public Long getTakenTimeByStepOperation()
        Returns:
        time in milliseconds spent by operation after sub operation was released
      • size

        public int size()
        Returns:
        integer a count of metric entities from the first till the last one in the whole story