Class Instrumenter


  • public class Instrumenter
    extends Object
    Fluent entry point for registering instrumentation hooks and applying them to a set of classes.
    • Method Detail

      • forClassPool

        public static Instrumenter forClassPool​(ClassPool pool)
        Creates an instrumenter targeting every class in a pool.
        Parameters:
        pool - the class pool
        Returns:
        a new instrumenter
      • forClass

        public static Instrumenter forClass​(ClassFile classFile)
        Creates an instrumenter targeting one class.
        Parameters:
        classFile - the class file to instrument
        Returns:
        a new instrumenter
      • forClasses

        public static Instrumenter forClasses​(List<ClassFile> classes)
        Creates an instrumenter targeting a list of classes.
        Parameters:
        classes - the class files to instrument
        Returns:
        a new instrumenter
      • forClasses

        public static Instrumenter forClasses​(ClassFile... classes)
        Creates an instrumenter targeting the given classes.
        Parameters:
        classes - the class files to instrument
        Returns:
        a new instrumenter
      • skipAbstract

        public Instrumenter skipAbstract​(boolean skip)
        Sets whether abstract methods are left alone.
        Parameters:
        skip - true to skip them
        Returns:
        this instrumenter
      • skipNative

        public Instrumenter skipNative​(boolean skip)
        Sets whether native methods are left alone.
        Parameters:
        skip - true to skip them
        Returns:
        this instrumenter
      • skipConstructors

        public Instrumenter skipConstructors​(boolean skip)
        Sets whether constructors are left alone.
        Parameters:
        skip - true to skip them
        Returns:
        this instrumenter
      • skipStaticInitializers

        public Instrumenter skipStaticInitializers​(boolean skip)
        Sets whether static initializers are left alone.
        Parameters:
        skip - true to skip them
        Returns:
        this instrumenter
      • skipSynthetic

        public Instrumenter skipSynthetic​(boolean skip)
        Sets whether synthetic methods are left alone.
        Parameters:
        skip - true to skip them
        Returns:
        this instrumenter
      • skipBridge

        public Instrumenter skipBridge​(boolean skip)
        Sets whether bridge methods are left alone.
        Parameters:
        skip - true to skip them
        Returns:
        this instrumenter
      • failOnError

        public Instrumenter failOnError​(boolean fail)
        Sets whether a failure to instrument a method is rethrown instead of counted.
        Parameters:
        fail - true to rethrow
        Returns:
        this instrumenter
      • verbose

        public Instrumenter verbose​(boolean verbose)
        Sets whether instrumentation failures are printed to stderr.
        Parameters:
        verbose - true to print
        Returns:
        this instrumenter
      • apply

        public int apply()
        Applies all registered hooks to the target classes.
        Returns:
        the total number of instrumentation points applied
        Throws:
        RuntimeException - if a method fails to instrument and failOnError is set
      • applyWithReport

        public Instrumenter.InstrumentationReport applyWithReport()
        Applies all registered hooks and records the result as the last report.
        Returns:
        counts of points, classes, methods, and failures
        Throws:
        RuntimeException - if a method fails to instrument and failOnError is set