From d75f8e9aa32194c1ed4f78f5cd8f0e225fc48d40 Mon Sep 17 00:00:00 2001 From: Sam Harwell Date: Wed, 1 May 2013 22:06:00 -0500 Subject: [PATCH] Add the DETAILED_DFA_STATE_STATS option to TestPerformance, which shows a breakdown of DFA states by rule (parsers) or mode (lexers) --- .../org/antlr/v4/test/TestPerformance.java | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/tool/test/org/antlr/v4/test/TestPerformance.java b/tool/test/org/antlr/v4/test/TestPerformance.java index 7edb9c1cd..e04a14365 100644 --- a/tool/test/org/antlr/v4/test/TestPerformance.java +++ b/tool/test/org/antlr/v4/test/TestPerformance.java @@ -227,6 +227,11 @@ public class TestPerformance extends BaseTest { * is 0, otherwise the last file which was parsed on the first thread). */ private static final boolean SHOW_DFA_STATE_STATS = true; + /** + * If {@code true}, the DFA state statistics report includes a breakdown of + * the number of DFA states contained in each decision (with rule names). + */ + private static final boolean DETAILED_DFA_STATE_STATS = true; /** * Specify the {@link PredictionMode} used by the @@ -834,6 +839,24 @@ public class TestPerformance extends BaseTest { } System.out.format("There are %d lexer DFAState instances, %d configs (%d unique).%n", states, configs, uniqueConfigs.size()); + + if (DETAILED_DFA_STATE_STATS) { + System.out.format("\tMode\tStates\tConfigs\tMode%n"); + for (int i = 0; i < modeToDFA.length; i++) { + DFA dfa = modeToDFA[i]; + if (dfa == null) { + continue; + } + + int modeConfigs = 0; + for (DFAState state : dfa.states.values()) { + modeConfigs += state.configs.size(); + } + + String modeName = lexer.getModeNames()[i]; + System.out.format("\t%d\t%d\t%d\t%s%n", dfa.decision, dfa.states.size(), modeConfigs, modeName); + } + } } } @@ -863,6 +886,24 @@ public class TestPerformance extends BaseTest { } System.out.format("There are %d parser DFAState instances, %d configs (%d unique).%n", states, configs, uniqueConfigs.size()); + + if (DETAILED_DFA_STATE_STATS) { + System.out.format("\tDecision\tStates\tConfigs\tRule%n"); + for (int i = 0; i < decisionToDFA.length; i++) { + DFA dfa = decisionToDFA[i]; + if (dfa == null || dfa.states.isEmpty()) { + continue; + } + + int decisionConfigs = 0; + for (DFAState state : dfa.states.values()) { + decisionConfigs += state.configs.size(); + } + + String ruleName = parser.getRuleNames()[parser.getATN().decisionToState.get(dfa.decision).ruleIndex]; + System.out.format("\t%d\t%d\t%d\t%s%n", dfa.decision, dfa.states.size(), decisionConfigs, ruleName); + } + } } int localDfaCount = 0;