Class 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 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
    • Constructor Summary

      Constructors 
      Constructor Description
      GuiceProvisionDiagnostic​(boolean printStartupReport)
      Create report.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clear()
      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.String renderReport()  
      void run​(GuiceyEnvironment environment)
      Called on run phase.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait