#3215: Add time measurement per event listener method

This commit is contained in:
Janmm14 2021-12-04 22:51:33 +01:00 committed by GitHub
parent 42d8300bb7
commit 425ee4e142
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -42,6 +42,8 @@ public class EventBus
{ {
for ( EventHandlerMethod method : handlers ) for ( EventHandlerMethod method : handlers )
{ {
long start = System.nanoTime();
try try
{ {
method.invoke( event ); 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() ); 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
} );
}
} }
} }
} }