Пример #1
0
 public String getDecisionStatsDump() {
   StringBuffer buf = new StringBuffer();
   buf.append("location");
   buf.append(DATA_SEP);
   buf.append("n");
   buf.append(DATA_SEP);
   buf.append("avgk");
   buf.append(DATA_SEP);
   buf.append("maxk");
   buf.append(DATA_SEP);
   buf.append("synpred");
   buf.append(DATA_SEP);
   buf.append("sempred");
   buf.append(DATA_SEP);
   buf.append("canbacktrack");
   buf.append("\n");
   for (String fileName : decisions.keySet()) {
     for (int d : decisions.keySet(fileName)) {
       DecisionDescriptor s = decisions.get(fileName, d);
       buf.append(s.decision);
       buf.append("@");
       buf.append(locationDescription(s.fileName, s.ruleName, s.line, s.pos)); // decision number
       buf.append(DATA_SEP);
       buf.append(s.n);
       buf.append(DATA_SEP);
       buf.append(String.format("%.2f", s.avgk));
       buf.append(DATA_SEP);
       buf.append(s.maxk);
       buf.append(DATA_SEP);
       buf.append(s.numBacktrackOccurrences);
       buf.append(DATA_SEP);
       buf.append(s.numSemPredEvals);
       buf.append(DATA_SEP);
       buf.append(s.couldBacktrack ? "1" : "0");
       buf.append(newline);
     }
   }
   return buf.toString();
 }
Пример #2
0
  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;
  }
Пример #3
0
  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);
    //		}
  }