Class GuiceProvisionDiagnostic

java.lang.Object
ru.vyarus.dropwizard.guice.debug.GuiceProvisionDiagnostic
All Implemented Interfaces:
GuiceyBundle

public class GuiceProvisionDiagnostic extends 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 is sorted by overall spent time: if guice bean (in prototype) scope was created several times - the summ of all creations is counted.

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