Skip to content
This repository has been archived by the owner on Oct 10, 2024. It is now read-only.
/ spring-profiler Public archive

Enables simple profiling of methods or code-snippets in spring-projects

License

Notifications You must be signed in to change notification settings

avides/spring-profiler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

spring-profiler

Maven Central Codacy Badge Coverage Status Build Status

Maven

<dependency>
    <groupId>com.avides.spring</groupId>
    <artifactId>spring-profiler</artifactId>
    <version>0.1.0.RELEASE</version>
</dependency>

Simple example

Profiler profiler = Profiler.startProfiling("anyIdentifier");
Thread.sleep(100);
// or any other code you want to profile
profiler.stop();

This will give you a log-message (debug-level) that looks similar to this:

execution time for anyIdentifier: 102ms

After stopping the profiler, you have access to some execution details, for example the exact execution-time by calling profiler.getDurationMillis()

Example with explicit given ProfilingHandler and allowedMillis

Profiler profiler = Profiler.startProfiling("anyIdentifier", new SysoutProfilingHandler());
Thread.sleep(100);
// or any other code you want to profile
profiler.stop(50);

This will give you an output to the System.out that looks similar to this:

WARNING: execution time for anyIdentifier: 102ms (allowed: 50ms)

If you do not specify a ProfilingHandler, a LoggingProfilingHandler is used as default (see example above). If you do so and the allowed time is exceeded, the logging-level switches to warning.

Of course, you can give your own ProfilingHandler-implementation (and even several at once) that meets your needs

Profiling of methods simply by annotation (only supported in a spring-application)

@Component
public class anyClass
{
    @Profiling
    public void anyMethod()
    {
        Thread.sleep(100);
        // or any other code you want to profile
    }
}

To get this working, simply add an @EnableProfiling-annotation at any of your configuration-classes (or the Application-class). After executing the method "anyMethod", it will give you a log-message (debug-level) that looks similar to this:

execution time for method anyClass.anyMethod(): 102ms

Explicit ProfilingHandlers and allowedMillis (explained in example above) can be set via the @Profiling-annotation-attributes (which also are well documented in javadoc)

About

Enables simple profiling of methods or code-snippets in spring-projects

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages