Package org.jboss.byteman.sample.helper
Class ThreadHistoryMonitorHelper
- java.lang.Object
-
- org.jboss.byteman.rule.helper.Helper
-
- org.jboss.byteman.sample.helper.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).
-
-
Field Summary
Fields Modifier and Type Field Description private static java.util.Queue<ThreadMonitorEvent>createListprivate static booleanDEBUGorg.jboss.byteman.sample.helper.debug system property debug mode flagprivate static java.util.Queue<ThreadMonitorEvent>exitListprivate static ThreadHistoryMonitorHelperINSTANCEThe first instance of ThreadHistoryMonitorHelper that will be used as the mbean byregisterHelperMBean(String).private static java.util.Queue<ThreadMonitorEvent>interruptedListprivate static java.util.Map<ThreadMonitored,ThreadMonitored>monitoredThreadsprivate static java.util.Queue<ThreadMonitorEvent>runListprivate static java.util.Queue<ThreadMonitorEvent>startList
-
Constructor Summary
Constructors Modifier Constructor Description protectedThreadHistoryMonitorHelper(Rule rule)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static voidactivated()Looks to the org.jboss.byteman.sample.helper.debug system property to set the class DEBUG mode flag.private voiddoWriteAllEvents(java.lang.String path)ThreadMonitorEvent[]getCreateEvents()Get the array of thread creation events.java.lang.StringgetEventReport()Get a string description of all thread events.ThreadMonitorEvent[]getExitEvents()Get the array of thread exit events.private ThreadMonitoredgetMonitoredThread(java.lang.Thread thread)Returning monitored thread belonging to the provided thread object.ThreadMonitorEvent[]getRunEvents()Get the array of Runnable.run events.ThreadMonitorEvent[]getStartEvents()Get the array of thread start events.private java.util.Map<ThreadMonitored,ThreadMonitorEvent>getThreadEventMap(java.lang.Iterable<ThreadMonitorEvent> events)static voidinstalled(Rule rule)ThreadMonitorEventnewThreadEvent(ThreadMonitored threadMonitored, java.lang.Thread thread, ThreadMonitorEventType eventType)Common ThreadMonitorEvent creation method.voidregisterHelperMBean(java.lang.String name)Register the INSTANCE as an mbean under the given name.voidtraceCreate(java.lang.Thread thread, int depth)trace creation of the supplied thread to System.out this should only be triggered from theThreadconstructorvoidtraceExit(java.lang.Thread thread)trace exit of the supplied thread to System.out this should only be triggered from the call toThreadexit methodvoidtraceInterrupt(java.lang.Thread thread)trace interrupted of the supplied thread to System.out this should only be triggered from the call toThread.interrupt()voidtraceRun(java.lang.Runnable runnable)trace run of the supplied Runnable to System.out this should only be triggered from a call to an implementation ofRunnable.run()voidtraceStart(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"voidwriteAllEventsToFile(java.lang.String path)Write all events to the file given by pathvoidwriteAllEventsToFile(java.lang.String path, int sampleCount)Write all events to the file given by path, repeating sampleCount times at 5 second intervals.voidwriteEventsToFile(java.lang.String type, java.lang.String path)Write a report of all events of the indicated type to the given path.private voidwriteFullEvents(java.util.Formatter fw, java.lang.String title, java.util.Collection<ThreadMonitorEvent> events)private voidwriteThreadNames(java.util.Formatter fw, java.lang.String title, java.util.Collection<ThreadMonitorEvent> events)-
Methods inherited from class org.jboss.byteman.rule.helper.Helper
addCountDown, callerCheck, callerEquals, callerEquals, callerEquals, callerEquals, callerEquals, callerEquals, callerEquals, callerEquals, callerEquals, callerMatches, callerMatches, callerMatches, callerMatches, callerMatches, callerMatches, callerMatches, callerMatches, callerMatches, clear, clearLinks, clearLinks, closeTrace, countDown, createCountDown, createCounter, createCounter, createJoin, createLinkMap, createRendezvous, createRendezvous, createTimer, deactivated, debug, decrementCounter, delay, deleteCounter, deleteLinkMap, deleteRendezvous, deleteTimer, err, errTraceException, flag, flagged, formatAllStacks, formatAllStacks, formatAllStacks, formatAllStacks, formatStack, formatStack, formatStack, formatStack, formatStackBetween, formatStackBetween, formatStackBetween, formatStackBetween, formatStackBetween, formatStackBetween, formatStackBetweenMatches, formatStackBetweenMatches, formatStackBetweenMatches, formatStackBetweenMatches, formatStackBetweenMatches, formatStackBetweenMatches, formatStackMatching, formatStackMatching, formatStackMatching, formatStackMatching, formatStackMatching, formatStackMatching, formatStackRange, formatThreadStack, formatThreadStack, formatThreadStack, formatThreadStack, getCountDown, getElapsedTimeFromTimer, getObjectSize, getRendezvous, getStack, incrementCounter, incrementCounter, isCountDown, isJoin, isRendezvous, joinEnlist, joinWait, joinWait, killJVM, killJVM, killThread, link, link, linked, linked, linkNames, linkNames, linkValues, linkValues, matchIndex, noisy, noisyTraceException, openTrace, openTrace, out, outTraceException, printFrame, printlnFrame, readCounter, readCounter, rendezvous, rendezvous, resetTimer, setTriggering, signalKill, signalKill, signalThrow, signalThrow, signalWake, signalWake, toString, trace, trace, traceAllStacks, traceAllStacks, traceAllStacks, traceAllStacks, traceAllStacks, traceAllStacks, traceClose, traceln, traceln, traceOpen, traceOpen, traceStack, traceStack, traceStack, traceStack, traceStack, traceStack, traceStackBetween, traceStackBetween, traceStackBetween, traceStackBetween, traceStackBetween, traceStackBetween, traceStackBetween, traceStackBetween, traceStackBetween, traceStackBetweenMatches, traceStackBetweenMatches, traceStackBetweenMatches, traceStackBetweenMatches, traceStackBetweenMatches, traceStackBetweenMatches, traceStackBetweenMatches, traceStackBetweenMatches, traceStackBetweenMatches, traceStackMatching, traceStackMatching, traceStackMatching, traceStackMatching, traceStackMatching, traceStackMatching, traceStackMatching, traceStackMatching, traceStackMatching, traceStackRange, traceThreadStack, traceThreadStack, traceThreadStack, traceThreadStack, traceThreadStack, traceThreadStack, triggerIndex, uninstalled, unlink, unlink, verbose, verboseTraceException, waitFor, waitFor, waiting
-
-
-
-
Field Detail
-
monitoredThreads
private static java.util.Map<ThreadMonitored,ThreadMonitored> monitoredThreads
-
createList
private static java.util.Queue<ThreadMonitorEvent> createList
-
startList
private static java.util.Queue<ThreadMonitorEvent> startList
-
exitList
private static java.util.Queue<ThreadMonitorEvent> exitList
-
runList
private static java.util.Queue<ThreadMonitorEvent> runList
-
interruptedList
private static java.util.Queue<ThreadMonitorEvent> interruptedList
-
INSTANCE
private static ThreadHistoryMonitorHelper INSTANCE
The first instance of ThreadHistoryMonitorHelper that will be used as the mbean byregisterHelperMBean(String).
-
DEBUG
private static boolean DEBUG
org.jboss.byteman.sample.helper.debug system property debug mode flag
-
-
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 theThreadconstructor- Parameters:
thread- the newly created threaddepth- 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 toThreadexit 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 toThread.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 ofRunnable.run()- Parameters:
runnable- the runnable being run
-
getCreateEvents
public ThreadMonitorEvent[] getCreateEvents()
Description copied from interface:ThreadHistoryMonitorHelperMXBeanGet the array of thread creation events.- Specified by:
getCreateEventsin interfaceThreadHistoryMonitorHelperMXBean- Returns:
- the array of thread creation events in the order of occurrence.
-
getStartEvents
public ThreadMonitorEvent[] getStartEvents()
Description copied from interface:ThreadHistoryMonitorHelperMXBeanGet the array of thread start events.- Specified by:
getStartEventsin interfaceThreadHistoryMonitorHelperMXBean- Returns:
- the array of thread start events in the order of occurrence.
-
getExitEvents
public ThreadMonitorEvent[] getExitEvents()
Description copied from interface:ThreadHistoryMonitorHelperMXBeanGet the array of thread exit events.- Specified by:
getExitEventsin interfaceThreadHistoryMonitorHelperMXBean- Returns:
- the array of thread exit events in the order of occurrence.
-
getRunEvents
public ThreadMonitorEvent[] getRunEvents()
Description copied from interface:ThreadHistoryMonitorHelperMXBeanGet the array of Runnable.run events.- Specified by:
getRunEventsin interfaceThreadHistoryMonitorHelperMXBean- Returns:
- the array of Runnable.run events in the order of occurrence.
-
getEventReport
public java.lang.String getEventReport() throws java.io.IOExceptionDescription copied from interface:ThreadHistoryMonitorHelperMXBeanGet a string description of all thread events. This is the same event information written byThreadHistoryMonitorHelperMXBean.writeAllEventsToFile(String).- Specified by:
getEventReportin interfaceThreadHistoryMonitorHelperMXBean- Returns:
- a formatted text description of all thread events.
- Throws:
java.io.IOException- if an io error occurs
-
writeEventsToFile
public void writeEventsToFile(java.lang.String type, java.lang.String path) throws java.io.IOExceptionDescription copied from interface:ThreadHistoryMonitorHelperMXBeanWrite a report of all events of the indicated type to the given path.- Specified by:
writeEventsToFilein interfaceThreadHistoryMonitorHelperMXBean- Parameters:
type- - one of create, start, exit, run; case insensitivepath- - 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.IOExceptionWrite all events to the file given by path- Specified by:
writeAllEventsToFilein interfaceThreadHistoryMonitorHelperMXBean- 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.IOExceptionWrite 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 filesampleCount- - 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 eventeventType- - 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 toThreadHistoryMonitorHelper) then brand newThreadMonitoredobject 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
-
getThreadEventMap
private java.util.Map<ThreadMonitored,ThreadMonitorEvent> getThreadEventMap(java.lang.Iterable<ThreadMonitorEvent> events)
-
-