From 425ee4e142b13b29cf89b8f25c31245d026a35d1 Mon Sep 17 00:00:00 2001 From: Janmm14 Date: Sat, 4 Dec 2021 22:51:33 +0100 Subject: [PATCH] #3215: Add time measurement per event listener method --- .../src/main/java/net/md_5/bungee/event/EventBus.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/event/src/main/java/net/md_5/bungee/event/EventBus.java b/event/src/main/java/net/md_5/bungee/event/EventBus.java index a6d717f2c..b3effc8aa 100644 --- a/event/src/main/java/net/md_5/bungee/event/EventBus.java +++ b/event/src/main/java/net/md_5/bungee/event/EventBus.java @@ -42,6 +42,8 @@ public class EventBus { for ( EventHandlerMethod method : handlers ) { + long start = System.nanoTime(); + try { method.invoke( event ); @@ -55,6 +57,15 @@ public class EventBus { logger.log( Level.WARNING, MessageFormat.format( "Error dispatching event {0} to listener {1}", event, method.getListener() ), ex.getCause() ); } + + long elapsed = System.nanoTime() - start; + if ( elapsed > 20000000 ) + { + logger.log( Level.WARNING, "Plugin listener {0} took {1}ms to process event {2}!", new Object[] + { + method.getListener().getClass().getName(), elapsed / 1000000, event + } ); + } } } }