From 82dd8c2c5e4ecf00d98eb851d919143e9eecef39 Mon Sep 17 00:00:00 2001 From: Johannes Mockenhaupt Date: Sat, 14 Oct 2017 18:07:12 +0200 Subject: [PATCH] Log summary after 10s, then every 60s. --- .../java/com/squareup/otto/LoggingBus.java | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/squareup/otto/LoggingBus.java b/app/src/main/java/com/squareup/otto/LoggingBus.java index 6fa53a60f9..044911363d 100644 --- a/app/src/main/java/com/squareup/otto/LoggingBus.java +++ b/app/src/main/java/com/squareup/otto/LoggingBus.java @@ -5,12 +5,24 @@ import org.slf4j.LoggerFactory; import java.lang.reflect.Field; import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; import info.nightscout.androidaps.events.Event; +/** Logs events has they're being posted to and dispatched from the event bus. + * + * A summary of references between sender and event and event and receiver is printed + * after 10s (after startup) and then again every 60s. + * */ public class LoggingBus extends Bus { private static Logger log = LoggerFactory.getLogger(LoggingBus.class); + private static long everyMinute = System.currentTimeMillis() + 10 * 1000; + private Map> event2Receiver = new HashMap<>(); + public LoggingBus(ThreadEnforcer enforcer) { super(enforcer); } @@ -48,10 +60,28 @@ public class LoggingBus extends Bus { Method targcetMethod = (Method) methodField.get(wrapper); String className = targcetMethod.getDeclaringClass().getSimpleName(); String methodName = targcetMethod.getName(); - log.debug(" receiver: " + className + "." + methodName); + String receiverMethod = className + "." + methodName; + log.debug(" receiver: " + receiverMethod); + + String key = event.getClass().getSimpleName(); + if (!event2Receiver.containsKey(key)) event2Receiver.put(key, new HashSet()); + event2Receiver.get(key).add(receiverMethod); } catch (ReflectiveOperationException e) { log.debug(" receiver: "); } + + if (everyMinute < System.currentTimeMillis()) { + log.debug("***************** The story so far ****************"); + for (Map.Entry> stringSetEntry : event2Receiver.entrySet()) { + log.debug(" " + stringSetEntry.getKey()); + for (String s : stringSetEntry.getValue()) { + log.debug(" -> " + s); + } + } + log.debug("***************************************************"); + everyMinute = System.currentTimeMillis() + 60 * 1000; + } + super.dispatch(event, wrapper); } }