You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by GitBox <gi...@apache.org> on 2020/04/11 18:49:47 UTC
[GitHub] [calcite] xndai commented on a change in pull request #1910: [CALCITE-3915] Add rule listener to report rule attempts and time at …
xndai commented on a change in pull request #1910: [CALCITE-3915] Add rule listener to report rule attempts and time at …
URL: https://github.com/apache/calcite/pull/1910#discussion_r407097727
##########
File path: core/src/main/java/org/apache/calcite/plan/volcano/VolcanoPlanner.java
##########
@@ -1757,4 +1738,70 @@ protected void onMatch() {
this.callId = callId;
}
}
+
+ /** Listener for counting the attempts of each rule. Only enabled under DEBUG level.*/
+ private class RuleAttemptsListener implements RelOptListener {
+ private long totalAttempts;
+ private long beforeTimestamp;
+ private Map<String, Pair<Long, Long>> ruleAttempts;
+
+
+ RuleAttemptsListener() {
+ this.totalAttempts = 0;
+ ruleAttempts = new HashMap<>();
+ }
+
+ @Override public void relEquivalenceFound(RelEquivalenceEvent event) {
+ }
+
+ @Override public void ruleAttempted(RuleAttemptedEvent event) {
+ if (event.isBefore()) {
+ this.beforeTimestamp = System.nanoTime();
+ } else {
+ ++this.totalAttempts;
+ long elapsed = (System.nanoTime() - this.beforeTimestamp) / 1000;
+ String rule = event.getRuleCall().getRule().toString();
+ if (ruleAttempts.containsKey(rule)) {
+ Pair<Long, Long> p = ruleAttempts.get(rule);
+ ruleAttempts.put(rule, Pair.of(p.left + 1, p.right + elapsed));
+ } else {
+ ruleAttempts.put(rule, Pair.of(1L, elapsed));
+ }
+ }
+ }
+
+ @Override public void ruleProductionSucceeded(RuleProductionEvent event) {
+ }
+
+ @Override public void relDiscarded(RelDiscardedEvent event) {
+ }
+
+ @Override public void relChosen(RelChosenEvent event) {
+ }
+
+ public String dump() {
+ // Sort rules by number of attempts
+ List<Map.Entry<String, Pair<Long, Long>>> list =
+ new ArrayList<>(this.ruleAttempts.entrySet());
+ Collections.sort(list, new Comparator<Map.Entry<String, Pair<Long, Long>>>() {
Review comment:
Absolutely! Thanks.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services