Package ru.vyarus.dropwizard.guice.debug
Class GuiceProvisionDiagnostic
- java.lang.Object
-
- ru.vyarus.dropwizard.guice.debug.GuiceProvisionDiagnostic
-
- All Implemented Interfaces:
GuiceyBundle
public class GuiceProvisionDiagnostic extends java.lang.Object implements GuiceyBundle
Guice beans creation (provision) time diagnostic. Records all requested beans creation time. By default, prints collected data after application startup (most of the beans created at startup).The report shows:
- Each bean creation time (mostly useful for providers, which might be slow)
- Number of created instances (for each type)
- All requested bindings, including JIT bindings - useful for unexpected JIT bindings detection
- Detects if the same type is requested with and without qualifier - usually this means incorrect usage (forgotten qualifier), but it might not be obvious (as guice create JIT binding in this case).
The report also could be used to measure runtime creations:
// false to avoid startup report GuiceProvisionDiagnostic report = new GuiceProvisionDiagnostic(false); // registre report GuiceBundle....bundles(report); // clear collected data before required point report.clear(); // do something requiring new beans creation injector.getInstance(JitService.class); // just an example // generate report after measured actions logger.info("Guice provision time {}", report.renderReport());- Since:
- 24.03.2025
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classGuiceProvisionDiagnostic.ProvisionListenerModuleModule records guice beans provision times.
-
Constructor Summary
Constructors Constructor Description GuiceProvisionDiagnostic(boolean printStartupReport)Create report.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Clear collected data (to record new data at runtime).com.google.common.collect.ListMultimap<com.google.inject.Binding<?>,java.time.Duration>getRecordedData()Map format: binding - provisions time.java.lang.StringrenderReport()voidrun(GuiceyEnvironment environment)Called on run phase.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface ru.vyarus.dropwizard.guice.module.installer.bundle.GuiceyBundle
initialize
-
-
-
-
Method Detail
-
run
public void run(GuiceyEnvironment environment) throws java.lang.Exception
Description copied from interface:GuiceyBundleCalled on run phase.GuiceyEnvironmentcontains almost the same methods asGuiceyBootstrap, which allows registering extensions and guice modules.Direct jersey specific registrations are possible through shortcuts
GuiceyEnvironment.register(Object...)andGuiceyEnvironment.register(Class[]). Complete dropwizard environment object is accessible withGuiceyEnvironment.environment()(assumed that it would not be directly required in most cases).Dropwizard configuration is accessible directly with
GuiceyEnvironment.configuration()and with advanced methodsGuiceyEnvironment.configuration(Class),GuiceyEnvironment.configuration(String),GuiceyEnvironment.configurations(Class)andGuiceyEnvironment.configurationTree().- Specified by:
runin interfaceGuiceyBundle- Parameters:
environment- guicey environment object- Throws:
java.lang.Exception- if something goes wrong
-
clear
public void clear()
Clear collected data (to record new data at runtime).
-
getRecordedData
public com.google.common.collect.ListMultimap<com.google.inject.Binding<?>,java.time.Duration> getRecordedData()
Map format: binding - provisions time.- Returns:
- recorded provision data
-
renderReport
public java.lang.String renderReport()
- Returns:
- generated report for collected data
-
-