Top Description Inners Fields Constructors Methods
com.sun.javafx.logging

pack-priv Class PrintLogger

extends Logger
Class Inheritance
Imports
java.util.ArrayList, .Collections, .List, .Map, java.util.concurrent.ConcurrentHashMap, java.util.concurrent.atomic.AtomicInteger

Logs information on a per-pulse basis. When doing performance analysis, a very easy thing to start with is to run with the PulseLogger enabled, such that various statistics related to the scene graph and the pulse are recorded and dumped to the log.

The pulse logger is designed in such a way as to gather all of the pulse statistics together even though half of the pulse occurs on the FX thread and half on the render thread, and therefore two sets of pulse data are being accumulated concurrently. The pulseStart, pulseEnd, renderStart, and renderEnd methods must be called appropriately by the runtime to ensure that the logging system works correctly.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
PrintLogger.Counter

A mutable integer to be used in the counter map

private class
PrintLogger.PulseData

The data we collect per pulse.

pack-priv class

Field Summary

Modifier and TypeField and Description
private AtomicInteger
active

A synchronization object for printing arbitrage.

private static final int
AVAILABLE

PulseData object states

private static final int
private static final int
EXIT_ON_PULSE

Optionally exit after a given number of pulses

private volatile PrintLogger.PulseData
fxData

References to PulseData for the FX thread (fxData) and the Render thread (renderData).

private Thread
private PrintLogger.PulseData
head

The queue of all PulseData objects, both available and those in use.

private static final int
private static final int
private long
lastPulseStartTime

Keeps track of the start of the previous pulse, such that we can print out the time interval between the start of pulses.

private final ThreadLocal<PrintLogger.ThreadLocalData>
private int
pulseCount

We have a simple counter that keeps track of the current pulse number.

private volatile PrintLogger.PulseData
renderData

References to PulseData for the FX thread (fxData) and the Render thread (renderData).

private PrintLogger.PulseData
private static long
THRESHOLD

A time in milliseconds which defines the threshold.

private volatile int
wrapCount

When printing the truncated form of the pulse, we just print one truncated form after another, such as: [5][2][4] This way we don't cause the console to scroll far vertically in the case of fast pulses.

Constructor Summary

AccessConstructor and Description
private
PrintLogger()

Disallow instantiation.

Method Summary

Modifier and TypeMethod and Description
public void
addMessage(String
The message to log. A newline will be added automatically.
message
)

Overrides com.sun.javafx.logging.Logger.addMessage.

Adds a message to the log for the pulse.

private PrintLogger.PulseData
allocate(int n)

Allocate and initialize a PulseData object

public static Logger
public void
incrementCounter(String
The name for the counter.
counter
)

Overrides com.sun.javafx.logging.Logger.incrementCounter.

Increments the given named per-pulse counter.

public void
public void
pulseEnd()

Overrides com.sun.javafx.logging.Logger.pulseEnd.

Must be called at the end of the pulse.

public void
pulseStart()

Overrides com.sun.javafx.logging.Logger.pulseStart.

MUST be called at the start of every pulse.

public void
renderEnd()

Overrides com.sun.javafx.logging.Logger.renderEnd.

Must be called at the end of rendering, if a previous call to renderStart() had been made.

public void
renderStart()

Overrides com.sun.javafx.logging.Logger.renderStart.

Must be called before any set of render jobs for a given pulse begin.

Inherited from com.sun.javafx.logging.Logger:
newInput

Field Detail

activeback to summary
private AtomicInteger active

A synchronization object for printing arbitrage.

AVAILABLEback to summary
private static final int AVAILABLE

PulseData object states

COMPLETEback to summary
private static final int COMPLETE
EXIT_ON_PULSEback to summary
private static final int EXIT_ON_PULSE

Optionally exit after a given number of pulses

fxDataback to summary
private volatile PrintLogger.PulseData fxData

References to PulseData for the FX thread (fxData) and the Render thread (renderData).

fxThreadback to summary
private Thread fxThread
INCOMPLETEback to summary
private static final int INCOMPLETE
INTER_PULSE_DATAback to summary
private static final int INTER_PULSE_DATA
lastPulseStartTimeback to summary
private long lastPulseStartTime

Keeps track of the start of the previous pulse, such that we can print out the time interval between the start of pulses.

phaseDataback to summary
private final ThreadLocal<PrintLogger.ThreadLocalData> phaseData
pulseCountback to summary
private int pulseCount

We have a simple counter that keeps track of the current pulse number. INTER_PULSE_DATA is used to mark data that comes between pulses.

renderDataback to summary
private volatile PrintLogger.PulseData renderData

References to PulseData for the FX thread (fxData) and the Render thread (renderData).

tailback to summary
private PrintLogger.PulseData tail
THRESHOLDback to summary
private static long THRESHOLD

A time in milliseconds which defines the threshold. If a pulse lasts longer than the threshold, then it is logged, otherwise an abbreviated representation including only the time of the pulse is logged.

wrapCountback to summary
private volatile int wrapCount

When printing the truncated form of the pulse, we just print one truncated form after another, such as: [5][2][4] This way we don't cause the console to scroll far vertically in the case of fast pulses. We do this so that relevant information (pulses that exceed the threshold) is easy to find and remains visible as long as possible in the console. However, we don't want to scroll too far off to the right either, so we keep track of how many "quick pulses" have happened in a row. When we've exceeded some fixed number (20, say) then we will insert a newline into the log.

Constructor Detail

PrintLoggerback to summary
private PrintLogger()

Disallow instantiation.

Method Detail

addMessageback to summary
public void addMessage(String message)

Overrides com.sun.javafx.logging.Logger.addMessage.

Adds a message to the log for the pulse.

Parameters
message:String

The message to log. A newline will be added automatically.

Annotations
@Override
allocateback to summary
private PrintLogger.PulseData allocate(int n)

Allocate and initialize a PulseData object

createInstanceback to summary
public static Logger createInstance()
incrementCounterback to summary
public void incrementCounter(String counter)

Overrides com.sun.javafx.logging.Logger.incrementCounter.

Increments the given named per-pulse counter.

Parameters
counter:String

The name for the counter.

Annotations
@Override
newPhaseback to summary
public void newPhase(String name)

Overrides com.sun.javafx.logging.Logger.newPhase.

Annotations
@Override
pulseEndback to summary
public void pulseEnd()

Overrides com.sun.javafx.logging.Logger.pulseEnd.

Must be called at the end of the pulse. If there was no rendering started during this pulse, then this method will cause the pulse data to be logged. Otherwise, the pulse data is logged when rendering is ended. However, as soon as pulseEnd is called, we are ready for another call to pulseStart.

Annotations
@Override
pulseStartback to summary
public void pulseStart()

Overrides com.sun.javafx.logging.Logger.pulseStart.

MUST be called at the start of every pulse. This method will initialize the fxData buffer so that subsequent calls to fxMessage will write to this buffer.

Annotations
@Override
renderEndback to summary
public void renderEnd()

Overrides com.sun.javafx.logging.Logger.renderEnd.

Must be called at the end of rendering, if a previous call to renderStart() had been made. This will cause the pulse data to be logged.

Annotations
@Override
renderStartback to summary
public void renderStart()

Overrides com.sun.javafx.logging.Logger.renderStart.

Must be called before any set of render jobs for a given pulse begin. This method will initialize the renderData buffer so that subsequent calls to renderMessage will write to this buffer. I have found that sometimes renderMessage is called without a pulse being started. Such cases are exceptional and appear to happen only at startup, and such cases are simply not logged.

Annotations
@Override
com.sun.javafx.logging back to summary

private Class PrintLogger.Counter

extends Object
Class Inheritance

A mutable integer to be used in the counter map

Field Summary

Modifier and TypeField and Description
pack-priv int

Constructor Summary

AccessConstructor and Description
private

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

valueback to summary
pack-priv int value

Constructor Detail

Counterback to summary
private Counter()
com.sun.javafx.logging back to summary

private final Class PrintLogger.PulseData

extends Object
Class Inheritance

The data we collect per pulse. We store the pulse number associated with this pulse, along with what time it started at and the interval since the previous pulse. We also maintain the message buffer and counters.

Field Summary

Modifier and TypeField and Description
pack-priv Map<String, PrintLogger.Counter>
pack-priv long
pack-priv StringBuffer
pack-priv PrintLogger.PulseData
pack-priv int
pack-priv boolean
pack-priv long
pack-priv volatile int

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
pack-priv void
init(int n)

pack-priv void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

countersback to summary
pack-priv Map<String, PrintLogger.Counter> counters
intervalback to summary
pack-priv long interval
messageback to summary
pack-priv StringBuffer message
nextback to summary
pack-priv PrintLogger.PulseData next
pulseCountback to summary
pack-priv int pulseCount
pushedRenderback to summary
pack-priv boolean pushedRender
startTimeback to summary
pack-priv long startTime
stateback to summary
pack-priv volatile int state

Constructor Detail

PulseDataback to summary
private PulseData()

Method Detail

initback to summary
pack-priv void init(int n)
printAndResetback to summary
pack-priv void printAndReset()
com.sun.javafx.logging back to summary

pack-priv Class PrintLogger.ThreadLocalData

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv String
pack-priv long

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

phaseNameback to summary
pack-priv String phaseName
phaseStartback to summary
pack-priv long phaseStart

Constructor Detail

ThreadLocalDataback to summary
pack-priv ThreadLocalData()