Class ThreadHistoryMonitorHelper

  • All Implemented Interfaces:
    ThreadHistoryMonitorHelperMXBean

    public class ThreadHistoryMonitorHelper
    extends Helper
    implements ThreadHistoryMonitorHelperMXBean

    Helper class used by ThreadHistoryMonitorHelper script to trace thread operations. This is essentially an extension of the ThreadMonitorHelper which uses maps to store the thread history rather than writing it out.

    The helper also implements ThreadHistoryMonitorHelperMXBean to allow this class to be registered as an mbean @see #registerHelperMBean(String).

    • Constructor Detail

      • ThreadHistoryMonitorHelper

        protected ThreadHistoryMonitorHelper​(Rule rule)
    • Method Detail

      • activated

        public static void activated()
        Looks to the org.jboss.byteman.sample.helper.debug system property to set the class DEBUG mode flag.
      • installed

        public static void installed​(Rule rule)
      • registerHelperMBean

        public void registerHelperMBean​(java.lang.String name)
        Register the INSTANCE as an mbean under the given name.
        Parameters:
        name - - the object name string to register the INSTANCE under
      • traceCreate

        public void traceCreate​(java.lang.Thread thread,
                                int depth)
        trace creation of the supplied thread to System.out this should only be triggered from the Thread constructor
        Parameters:
        thread - the newly created thread
        depth - unused
      • traceStart

        public void traceStart​(java.lang.Thread thread)
        trace start of the supplied thread to System.out this should only be triggered from the call to java.lang.Thread.start"
        Parameters:
        thread - the newly starting thread
      • traceExit

        public void traceExit​(java.lang.Thread thread)
        trace exit of the supplied thread to System.out this should only be triggered from the call to Thread exit method
        Parameters:
        thread - the exiting thread
      • traceInterrupt

        public void traceInterrupt​(java.lang.Thread thread)
        trace interrupted of the supplied thread to System.out this should only be triggered from the call to Thread.interrupt()
        Parameters:
        thread - the interrupting thread
      • traceRun

        public void traceRun​(java.lang.Runnable runnable)
        trace run of the supplied Runnable to System.out this should only be triggered from a call to an implementation of Runnable.run()
        Parameters:
        runnable - the runnable being run
      • writeEventsToFile

        public void writeEventsToFile​(java.lang.String type,
                                      java.lang.String path)
                               throws java.io.IOException
        Description copied from interface: ThreadHistoryMonitorHelperMXBean
        Write a report of all events of the indicated type to the given path.
        Specified by:
        writeEventsToFile in interface ThreadHistoryMonitorHelperMXBean
        Parameters:
        type - - one of create, start, exit, run; case insensitive
        path - - the pathname of the file to write the event report to.
        Throws:
        java.io.IOException - if an io error occurs
      • writeAllEventsToFile

        public void writeAllEventsToFile​(java.lang.String path)
                                  throws java.io.IOException
        Write all events to the file given by path
        Specified by:
        writeAllEventsToFile in interface ThreadHistoryMonitorHelperMXBean
        Parameters:
        path - path to file
        Throws:
        java.io.IOException - if an io error occurs
      • writeAllEventsToFile

        public void writeAllEventsToFile​(java.lang.String path,
                                         int sampleCount)
                                  throws java.io.IOException
        Write all events to the file given by path, repeating sampleCount times at 5 second intervals. The actual filename of each sample report will be either path-n where n = [0,sampleCount] if path does not contain a suffix, for example: /tmp/report-0 /tmp/report-1 /tmp/report-3 or pathbase-n.suffix if there is a '.' delimited suffix (.txt), for example: /tmp/report-0.txt /tmp/report-1.txt /tmp/report-3.txt
        Parameters:
        path - - the path to the event report file
        sampleCount - - the number of samples to take
        Throws:
        java.io.IOException - - thrown on any IO failure
      • doWriteAllEvents

        private void doWriteAllEvents​(java.lang.String path)
                               throws java.io.IOException
        Throws:
        java.io.IOException
      • writeFullEvents

        private void writeFullEvents​(java.util.Formatter fw,
                                     java.lang.String title,
                                     java.util.Collection<ThreadMonitorEvent> events)
      • writeThreadNames

        private void writeThreadNames​(java.util.Formatter fw,
                                      java.lang.String title,
                                      java.util.Collection<ThreadMonitorEvent> events)
      • newThreadEvent

        public ThreadMonitorEvent newThreadEvent​(ThreadMonitored threadMonitored,
                                                 java.lang.Thread thread,
                                                 ThreadMonitorEventType eventType)
        Common ThreadMonitorEvent creation method.
        Parameters:
        thread - - the thread associated with the event
        eventType - - the type of the event.
        Returns:
        the ThreadMonitorEvent instance for the event.
      • getMonitoredThread

        private ThreadMonitored getMonitoredThread​(java.lang.Thread thread)
        Returning monitored thread belonging to the provided thread object. If such monitored thread does not exist (is not known to ThreadHistoryMonitorHelper) then brand new ThreadMonitored object is created and is added to the list checked by the helper class.
        Parameters:
        thread - thread that belonging ThreadMonitorThread is search for
        Returns:
        ThreadMonitorThread which belongs to provided thread or null in no such known