Package ru.vyarus.dropwizard.guice.debug
Class GuiceProvisionDiagnostic
java.lang.Object
ru.vyarus.dropwizard.guice.debug.GuiceProvisionDiagnostic
- All Implemented Interfaces:
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 ClassesModifier and TypeClassDescriptionstatic classModule records guice beans provision times. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clear collected data (to record new data at runtime).com.google.common.collect.ListMultimap<com.google.inject.Binding<?>,Duration> Map format: binding - provisions time.voidrun(GuiceyEnvironment environment) Called on run phase.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ru.vyarus.dropwizard.guice.module.installer.bundle.GuiceyBundle
initialize
-
Constructor Details
-
GuiceProvisionDiagnostic
public GuiceProvisionDiagnostic(boolean printStartupReport) Create report.- Parameters:
printStartupReport- true to print report after application startup
-
-
Method Details
-
run
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:
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<?>,Duration> getRecordedData()Map format: binding - provisions time.- Returns:
- recorded provision data
-
renderReport
- Returns:
- generated report for collected data
-