public void terminate() { for (DecisionEvent e : decisionEvents) { // System.out.println("decision "+e.decision.decision+": k="+e.k); e.decision.avgk += e.k; stats.avgkPerDecisionEvent += e.k; if (e.backtracks) { // doesn't count gated syn preds on DFA edges stats.avgkPerBacktrackingDecisionEvent += e.k; } } stats.averageDecisionPercentBacktracks = 0.0f; for (DecisionDescriptor d : decisions.values()) { stats.numDecisionsCovered++; d.avgk /= (double) d.n; if (d.couldBacktrack) { stats.numDecisionsThatPotentiallyBacktrack++; float percentBacktracks = d.numBacktrackOccurrences / (float) d.n; // System.out.println("dec "+d.decision+" backtracks "+percentBacktracks*100+"%"); stats.averageDecisionPercentBacktracks += percentBacktracks; } // ignore rules that backtrack along gated DFA edges if (d.numBacktrackOccurrences > 0) { stats.numDecisionsThatDoBacktrack++; } } stats.averageDecisionPercentBacktracks /= stats.numDecisionsThatPotentiallyBacktrack; stats.averageDecisionPercentBacktracks *= 100; // it's a percentage stats.avgkPerDecisionEvent /= stats.numDecisionEvents; stats.avgkPerBacktrackingDecisionEvent /= (double) stats.numBacktrackOccurrences; System.err.println(toString()); System.err.println(getDecisionStatsDump()); // String stats = toNotifyString(); // try { // Stats.writeReport(RUNTIME_STATS_FILENAME,stats); // } // catch (IOException ioe) { // System.err.println(ioe); // ioe.printStackTrace(System.err); // } }
public void enterDecision(int decisionNumber, boolean couldBacktrack) { lastRealTokenTouchedInDecision = null; stats.numDecisionEvents++; int startingLookaheadIndex = parser.getTokenStream().index(); TokenStream input = parser.getTokenStream(); if (dump) System.out.println( "enterDecision canBacktrack=" + couldBacktrack + " " + decisionNumber + " backtrack depth " + backtrackDepth + " @ " + input.get(input.index()) + " rule " + locationDescription()); String g = (String) currentGrammarFileName.peek(); DecisionDescriptor descriptor = decisions.get(g, decisionNumber); if (descriptor == null) { descriptor = new DecisionDescriptor(); decisions.put(g, decisionNumber, descriptor); descriptor.decision = decisionNumber; descriptor.fileName = (String) currentGrammarFileName.peek(); descriptor.ruleName = (String) currentRuleName.peek(); descriptor.line = (Integer) currentLine.peek(); descriptor.pos = (Integer) currentPos.peek(); descriptor.couldBacktrack = couldBacktrack; } descriptor.n++; DecisionEvent d = new DecisionEvent(); decisionStack.push(d); d.decision = descriptor; d.startTime = System.currentTimeMillis(); d.startIndex = startingLookaheadIndex; }