Top Description Inners Fields Constructors Methods
org.antlr.runtime.debug

public Class Profiler

extends BlankDebugEventListener
Class Inheritance
Imports
org.antlr.runtime.*, org.antlr.runtime.misc.DoubleKeyMap, java.util.*

Using the debug event interface, track what is happening in the parser and record statistics about the runtime.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
public static class
public static class

Field Summary

Modifier and TypeField and Description
protected int
protected Stack<String>
protected Stack<Integer>
protected Stack<Integer>
protected Stack<String>
public static final String
protected List<Profiler.DecisionEvent>
protected DoubleKeyMap<String, Integer, Profiler.DecisionDescriptor>
protected Stack<Profiler.DecisionEvent>
pack-priv static boolean
protected Token
public static final String
public DebugParser
parser

Ack, should not store parser; can't do remote stuff.

protected int
public static final String
pack-priv Profiler.ProfileStats
protected Set<String>
public static final String
Version

Because I may change the stats, I need to track that for later computations to be consistent.

Constructor Summary

AccessConstructor and Description
public
public

Method Summary

Modifier and TypeMethod and Description
public void
public void
public void
consumeToken(Token token)

Overrides org.antlr.runtime.debug.BlankDebugEventListener.consumeToken.

Implements org.antlr.runtime.debug.DebugEventListener.consumeToken.

An input token was consumed; matched by any kind of element.
protected Profiler.DecisionEvent
public void
endBacktrack(int level, boolean successful)

Overrides org.antlr.runtime.debug.BlankDebugEventListener.endBacktrack.

Implements org.antlr.runtime.debug.DebugEventListener.endBacktrack.

Successful or not, track how much lookahead synpreds use
public void
enterDecision(int decisionNumber, boolean couldBacktrack)

Overrides org.antlr.runtime.debug.BlankDebugEventListener.enterDecision.

Implements org.antlr.runtime.debug.DebugEventListener.enterDecision.

Every decision, fixed k or arbitrary, has an enter/exit event so that a GUI can easily track what LT/consume events are associated with prediction.
public void
enterRule(String grammarFileName, String ruleName)

Overrides org.antlr.runtime.debug.BlankDebugEventListener.enterRule.

Implements org.antlr.runtime.debug.DebugEventListener.enterRule.

The parser has just entered a rule.
public void
examineRuleMemoization(IntStream input, int ruleIndex, int stopIndex, String ruleName)

Track memoization; this is not part of standard debug interface but is triggered by profiling.

public void
public void
exitRule(String grammarFileName, String ruleName)

Overrides org.antlr.runtime.debug.BlankDebugEventListener.exitRule.

Implements org.antlr.runtime.debug.DebugEventListener.exitRule.

This is the last thing executed before leaving a rule.
public List<Profiler.DecisionEvent>
public DoubleKeyMap<String, Integer, Profiler.DecisionDescriptor>
public String
public int
getNumberOfHiddenTokens(int i, int j)

Get num hidden tokens between i..j inclusive

public Profiler.ProfileStats
public boolean
inDecision()

The parser is in a decision if the decision depth > 0.

public void
location(int line, int pos)

Overrides org.antlr.runtime.debug.BlankDebugEventListener.location.

Implements org.antlr.runtime.debug.DebugEventListener.location.

To watch a parser move through the grammar, the parser needs to inform the debugger what line/charPos it is passing in the grammar.
protected String
protected String
locationDescription(String file, String rule, int line, int pos)

public void
LT(int i, Token t)

Overrides org.antlr.runtime.debug.BlankDebugEventListener.LT.

Implements org.antlr.runtime.debug.DebugEventListener.LT.

Track refs to lookahead if in a fixed/nonfixed decision.
public void
mark(int i)

Overrides org.antlr.runtime.debug.BlankDebugEventListener.mark.

Implements org.antlr.runtime.debug.DebugEventListener.mark.

The parser is going to look arbitrarily ahead; mark this location, the token stream's marker is sent in case you need it.
public void
memoize(IntStream input, int ruleIndex, int ruleStartIndex, String ruleName)

Warning

doesn't track success/failure, just unique recording event

public void
public void
rewind(int i)

Overrides org.antlr.runtime.debug.BlankDebugEventListener.rewind.

Implements org.antlr.runtime.debug.DebugEventListener.rewind.

After an arbitrairly long lookahead as with a cyclic DFA (or with any backtrack), this informs the debugger that stream should be rewound to the position associated with marker.
public void
rewind()

Overrides org.antlr.runtime.debug.BlankDebugEventListener.rewind.

Implements org.antlr.runtime.debug.DebugEventListener.rewind.

Rewind to the input position of the last marker.
public void
semanticPredicate(boolean result, String predicate)

Overrides org.antlr.runtime.debug.BlankDebugEventListener.semanticPredicate.

Implements org.antlr.runtime.debug.DebugEventListener.semanticPredicate.

A semantic predicate was evaluate with this result and action text
public void
public void
protected int[]
public String
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
public static String
protected int[]
trim(int[] X, int n)

Inherited from org.antlr.runtime.debug.BlankDebugEventListener:
addChildbecomeRootbeginResynccommenceconsumeNodecreateNodecreateNodeendResyncenterAltenterSubRuleerrorNodeexitSubRuleLTnilNodesetTokenBoundaries

Field Detail

backtrackDepthback to summary
protected int backtrackDepth
currentGrammarFileNameback to summary
protected Stack<String> currentGrammarFileName
currentLineback to summary
protected Stack<Integer> currentLine
currentPosback to summary
protected Stack<Integer> currentPos
currentRuleNameback to summary
protected Stack<String> currentRuleName
DATA_SEPback to summary
public static final String DATA_SEP
decisionEventsback to summary
protected List<Profiler.DecisionEvent> decisionEvents
decisionsback to summary
protected DoubleKeyMap<String, Integer, Profiler.DecisionDescriptor> decisions
decisionStackback to summary
protected Stack<Profiler.DecisionEvent> decisionStack
dumpback to summary
pack-priv static boolean dump
lastRealTokenTouchedInDecisionback to summary
protected Token lastRealTokenTouchedInDecision
newlineback to summary
public static final String newline
parserback to summary
public DebugParser parser

Ack, should not store parser; can't do remote stuff. Well, we pass input stream around too so I guess it's ok.

ruleLevelback to summary
protected int ruleLevel
RUNTIME_STATS_FILENAMEback to summary
public static final String RUNTIME_STATS_FILENAME
statsback to summary
pack-priv Profiler.ProfileStats stats
uniqueRulesback to summary
protected Set<String> uniqueRules
Versionback to summary
public static final String Version

Because I may change the stats, I need to track that for later computations to be consistent.

Constructor Detail

Profilerback to summary
public Profiler()
Profilerback to summary
public Profiler(DebugParser parser)

Method Detail

beginBacktrackback to summary
public void beginBacktrack(int level)

Overrides org.antlr.runtime.debug.BlankDebugEventListener.beginBacktrack.

Implements org.antlr.runtime.debug.DebugEventListener.beginBacktrack.

Track backtracking decisions. You'll see a fixed or cyclic decision and then a backtrack. enter rule ... enter decision LA and possibly consumes (for cyclic DFAs) begin backtrack level mark m rewind m end backtrack level, success exit decision ... exit rule

Annotations
@Override
consumeHiddenTokenback to summary
public void consumeHiddenToken(Token token)

Overrides org.antlr.runtime.debug.BlankDebugEventListener.consumeHiddenToken.

Implements org.antlr.runtime.debug.DebugEventListener.consumeHiddenToken.

Doc from org.antlr.runtime.debug.DebugEventListener.consumeHiddenToken.

An off-channel input token was consumed. Trigger after the token was matched by things like match(), matchAny(). (unless of course the hidden token is first stuff in the input stream).

Annotations
@Override
consumeTokenback to summary
public void consumeToken(Token token)

Overrides org.antlr.runtime.debug.BlankDebugEventListener.consumeToken.

Implements org.antlr.runtime.debug.DebugEventListener.consumeToken.

Doc from org.antlr.runtime.debug.DebugEventListener.consumeToken.

An input token was consumed; matched by any kind of element. Trigger after the token was matched by things like match(), matchAny().

Annotations
@Override
currentDecisionback to summary
protected Profiler.DecisionEvent currentDecision()
endBacktrackback to summary
public void endBacktrack(int level, boolean successful)

Overrides org.antlr.runtime.debug.BlankDebugEventListener.endBacktrack.

Implements org.antlr.runtime.debug.DebugEventListener.endBacktrack.

Successful or not, track how much lookahead synpreds use

Annotations
@Override
enterDecisionback to summary
public void enterDecision(int decisionNumber, boolean couldBacktrack)

Overrides org.antlr.runtime.debug.BlankDebugEventListener.enterDecision.

Implements org.antlr.runtime.debug.DebugEventListener.enterDecision.

Doc from org.antlr.runtime.debug.DebugEventListener.enterDecision.

Every decision, fixed k or arbitrary, has an enter/exit event so that a GUI can easily track what LT/consume events are associated with prediction. You will see a single enter/exit subrule but multiple enter/exit decision events, one for each loop iteration.

Annotations
@Override
enterRuleback to summary
public void enterRule(String grammarFileName, String ruleName)

Overrides org.antlr.runtime.debug.BlankDebugEventListener.enterRule.

Implements org.antlr.runtime.debug.DebugEventListener.enterRule.

Doc from org.antlr.runtime.debug.DebugEventListener.enterRule.

The parser has just entered a rule. No decision has been made about which alt is predicted. This is fired AFTER init actions have been executed. Attributes are defined and available etc... The grammarFileName allows composite grammars to jump around among multiple grammar files.

Annotations
@Override
examineRuleMemoizationback to summary
public void examineRuleMemoization(IntStream input, int ruleIndex, int stopIndex, String ruleName)

Track memoization; this is not part of standard debug interface but is triggered by profiling. Code gen inserts an override for this method in the recognizer, which triggers this method. Called from alreadyParsedRule().

exitDecisionback to summary
public void exitDecision(int decisionNumber)

Overrides org.antlr.runtime.debug.BlankDebugEventListener.exitDecision.

Implements org.antlr.runtime.debug.DebugEventListener.exitDecision.

Annotations
@Override
exitRuleback to summary
public void exitRule(String grammarFileName, String ruleName)

Overrides org.antlr.runtime.debug.BlankDebugEventListener.exitRule.

Implements org.antlr.runtime.debug.DebugEventListener.exitRule.

Doc from org.antlr.runtime.debug.DebugEventListener.exitRule.

This is the last thing executed before leaving a rule. It is executed even if an exception is thrown. This is triggered after error reporting and recovery have occurred (unless the exception is not caught in this rule). This implies an "exitAlt" event. The grammarFileName allows composite grammars to jump around among multiple grammar files.

Annotations
@Override
getDecisionEventsback to summary
public List<Profiler.DecisionEvent> getDecisionEvents()
getDecisionStatsback to summary
public DoubleKeyMap<String, Integer, Profiler.DecisionDescriptor> getDecisionStats()
getDecisionStatsDumpback to summary
public String getDecisionStatsDump()
getNumberOfHiddenTokensback to summary
public int getNumberOfHiddenTokens(int i, int j)

Get num hidden tokens between i..j inclusive

getReportback to summary
public Profiler.ProfileStats getReport()
inDecisionback to summary
public boolean inDecision()

The parser is in a decision if the decision depth > 0. This works for backtracking also, which can have nested decisions.

locationback to summary
public void location(int line, int pos)

Overrides org.antlr.runtime.debug.BlankDebugEventListener.location.

Implements org.antlr.runtime.debug.DebugEventListener.location.

Doc from org.antlr.runtime.debug.DebugEventListener.location.

To watch a parser move through the grammar, the parser needs to inform the debugger what line/charPos it is passing in the grammar. For now, this does not know how to switch from one grammar to the other and back for island grammars etc... This should also allow breakpoints because the debugger can stop the parser whenever it hits this line/pos.

Annotations
@Override
locationDescriptionback to summary
protected String locationDescription()
locationDescriptionback to summary
protected String locationDescription(String file, String rule, int line, int pos)
LTback to summary
public void LT(int i, Token t)

Overrides org.antlr.runtime.debug.BlankDebugEventListener.LT.

Implements org.antlr.runtime.debug.DebugEventListener.LT.

Track refs to lookahead if in a fixed/nonfixed decision.

Annotations
@Override
markback to summary
public void mark(int i)

Overrides org.antlr.runtime.debug.BlankDebugEventListener.mark.

Implements org.antlr.runtime.debug.DebugEventListener.mark.

Doc from org.antlr.runtime.debug.DebugEventListener.mark.

The parser is going to look arbitrarily ahead; mark this location, the token stream's marker is sent in case you need it.

Annotations
@Override
memoizeback to summary
public void memoize(IntStream input, int ruleIndex, int ruleStartIndex, String ruleName)

Warning

doesn't track success/failure, just unique recording event

recognitionExceptionback to summary
public void recognitionException(RecognitionException e)

Overrides org.antlr.runtime.debug.BlankDebugEventListener.recognitionException.

Implements org.antlr.runtime.debug.DebugEventListener.recognitionException.

Doc from org.antlr.runtime.debug.DebugEventListener.recognitionException.

A recognition exception occurred such as NoViableAltException. I made this a generic event so that I can alter the exception hierachy later without having to alter all the debug objects. Upon error, the stack of enter rule/subrule must be properly unwound. If no viable alt occurs it is within an enter/exit decision, which also must be rewound. Even the rewind for each mark must be unwount. In the Java target this is pretty easy using try/finally, if a bit ugly in the generated code. The rewind is generated in DFA.predict() actually so no code needs to be generated for that. For languages w/o this "finally" feature (C++?), the target implementor will have to build an event stack or something. Across a socket for remote debugging, only the RecognitionException data fields are transmitted. The token object or whatever that caused the problem was the last object referenced by LT. The immediately preceding LT event should hold the unexpected Token or char. Here is a sample event trace for grammar: b : C ({;}A|B) // {;} is there to prevent A|B becoming a set | D ; The sequence for this rule (with no viable alt in the subrule) for input 'c c' (there are 3 tokens) is: commence LT(1) enterRule b location 7 1 enter decision 3 LT(1) exit decision 3 enterAlt1 location 7 5 LT(1) consumeToken [c/<4>,1:0] location 7 7 enterSubRule 2 enter decision 2 LT(1) LT(1) recognitionException NoViableAltException 2 1 2 exit decision 2 exitSubRule 2 beginResync LT(1) consumeToken [c/<4>,1:1] LT(1) endResync LT(-1) exitRule b terminate

Annotations
@Override
rewindback to summary
public void rewind(int i)

Overrides org.antlr.runtime.debug.BlankDebugEventListener.rewind.

Implements org.antlr.runtime.debug.DebugEventListener.rewind.

Doc from org.antlr.runtime.debug.DebugEventListener.rewind.

After an arbitrairly long lookahead as with a cyclic DFA (or with any backtrack), this informs the debugger that stream should be rewound to the position associated with marker.

Annotations
@Override
rewindback to summary
public void rewind()

Overrides org.antlr.runtime.debug.BlankDebugEventListener.rewind.

Implements org.antlr.runtime.debug.DebugEventListener.rewind.

Doc from org.antlr.runtime.debug.DebugEventListener.rewind.

Rewind to the input position of the last marker. Used currently only after a cyclic DFA and just before starting a sem/syn predicate to get the input position back to the start of the decision. Do not "pop" the marker off the state. mark(i) and rewind(i) should balance still.

Annotations
@Override
semanticPredicateback to summary
public void semanticPredicate(boolean result, String predicate)

Overrides org.antlr.runtime.debug.BlankDebugEventListener.semanticPredicate.

Implements org.antlr.runtime.debug.DebugEventListener.semanticPredicate.

Doc from org.antlr.runtime.debug.DebugEventListener.semanticPredicate.

A semantic predicate was evaluate with this result and action text

Annotations
@Override
setParserback to summary
public void setParser(DebugParser parser)
terminateback to summary
public void terminate()

Overrides org.antlr.runtime.debug.BlankDebugEventListener.terminate.

Implements org.antlr.runtime.debug.DebugEventListener.terminate.

Doc from org.antlr.runtime.debug.DebugEventListener.terminate.

Parsing is over; successfully or not. Mostly useful for telling remote debugging listeners that it's time to quit. When the rule invocation level goes to zero at the end of a rule, we are done parsing.

Annotations
@Override
toArrayback to summary
protected int[] toArray(List<Integer> a)
toNotifyStringback to summary
public String toNotifyString()
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
toStringback to summary
public static String toString(Profiler.ProfileStats stats)
trimback to summary
protected int[] trim(int[] X, int n)
org.antlr.runtime.debug back to summary

public Class Profiler.DecisionDescriptor

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
public float
public boolean
public int
public String
public int
public int
public int
n

public int
public int
public int
public String

Constructor Summary

AccessConstructor and Description
public

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

avgkback to summary
public float avgk
couldBacktrackback to summary
public boolean couldBacktrack
decisionback to summary
public int decision
fileNameback to summary
public String fileName
lineback to summary
public int line
maxkback to summary
public int maxk
nback to summary
public int n
numBacktrackOccurrencesback to summary
public int numBacktrackOccurrences
numSemPredEvalsback to summary
public int numSemPredEvals
posback to summary
public int pos
ruleNameback to summary
public String ruleName

Constructor Detail

DecisionDescriptorback to summary
public DecisionDescriptor()
org.antlr.runtime.debug back to summary

public Class Profiler.DecisionEvent

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
public boolean
public Profiler.DecisionDescriptor
public boolean
public int
k

public int
public int
public int
public long
public long

Constructor Summary

AccessConstructor and Description
public

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

backtracksback to summary
public boolean backtracks
decisionback to summary
public Profiler.DecisionDescriptor decision
evalSemPredback to summary
public boolean evalSemPred
kback to summary
public int k
numMemoizationCacheHitsback to summary
public int numMemoizationCacheHits
numMemoizationCacheMissesback to summary
public int numMemoizationCacheMisses
startIndexback to summary
public int startIndex
startTimeback to summary
public long startTime
stopTimeback to summary
public long stopTime

Constructor Detail

DecisionEventback to summary
public DecisionEvent()
org.antlr.runtime.debug back to summary

public Class Profiler.ProfileStats

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
public float
public int
public int
public float
public float
public int
public int
public int
public int
public int
public String
public int
public int
public int
public int
public int
public int
public int
public int
public int
public int
public int
public int
public int
public int
public int
public int
public int
public int
public int
public int
public int
public String

Constructor Summary

AccessConstructor and Description
public

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

averageDecisionPercentBacktracksback to summary
public float averageDecisionPercentBacktracks
avgDecisionMaxCyclicLookaheadsback to summary
public int avgDecisionMaxCyclicLookaheads
avgDecisionMaxFixedLookaheadsback to summary
public int avgDecisionMaxFixedLookaheads
avgkPerBacktrackingDecisionEventback to summary
public float avgkPerBacktrackingDecisionEvent
avgkPerDecisionEventback to summary
public float avgkPerDecisionEvent
maxDecisionMaxCyclicLookaheadsback to summary
public int maxDecisionMaxCyclicLookaheads
maxDecisionMaxFixedLookaheadsback to summary
public int maxDecisionMaxFixedLookaheads
maxRuleInvocationDepthback to summary
public int maxRuleInvocationDepth
minDecisionMaxCyclicLookaheadsback to summary
public int minDecisionMaxCyclicLookaheads
minDecisionMaxFixedLookaheadsback to summary
public int minDecisionMaxFixedLookaheads
nameback to summary
public String name
numBacktrackOccurrencesback to summary
public int numBacktrackOccurrences
numCharsMatchedback to summary
public int numCharsMatched
numCyclicDecisionsback to summary
public int numCyclicDecisions
numDecisionEventsback to summary
public int numDecisionEvents
numDecisionsCoveredback to summary
public int numDecisionsCovered
numDecisionsThatDoBacktrackback to summary
public int numDecisionsThatDoBacktrack
numDecisionsThatPotentiallyBacktrackback to summary
public int numDecisionsThatPotentiallyBacktrack
numFixedDecisionsback to summary
public int numFixedDecisions
numGuessingRuleInvocationsback to summary
public int numGuessingRuleInvocations
numHiddenCharsMatchedback to summary
public int numHiddenCharsMatched
numHiddenTokensback to summary
public int numHiddenTokens
numMemoizationCacheEntriesback to summary
public int numMemoizationCacheEntries
numMemoizationCacheHitsback to summary
public int numMemoizationCacheHits
numMemoizationCacheMissesback to summary
public int numMemoizationCacheMisses
numReportedErrorsback to summary
public int numReportedErrors
numRuleInvocationsback to summary
public int numRuleInvocations
numSemanticPredicatesback to summary
public int numSemanticPredicates
numTokensback to summary
public int numTokens
numUniqueRulesInvokedback to summary
public int numUniqueRulesInvoked
stddevDecisionMaxCyclicLookaheadsback to summary
public int stddevDecisionMaxCyclicLookaheads
stddevDecisionMaxFixedLookaheadsback to summary
public int stddevDecisionMaxFixedLookaheads
Versionback to summary
public String Version

Constructor Detail

ProfileStatsback to summary
public ProfileStats()