Code Monkey home page Code Monkey logo

javaagent-bytebuddy's Introduction

javaagent-bytebuddy

This include several agents created using Byte-Buddy. Using this project we can get an idea how to create effective agents with byte-buddy.

How to use

1. Download iavaagent-bytebuddy project

git clone https://github.com/ShehanPerera/javaagent-bytebuddy.git

2. Install the project

mvn clean package

3.Run example java progaram

  • Go to the directory

javaagent-bytebuddy/samples/example-run/target

  • Run project

java -jar example-run-1.0-SNAPSHOT.jar

Please read My blog 'Java Agents with Byte-Buddy' to get an idea how the codes working.

Use agents with Byte-Buddy

1. Get all methods running in program

  • Copy get-methods-1.0-SNAPSHOT.jar form javaagent-bytebuddy/samples/get-methods/target to javaagent-bytebuddy/samples/example-run/target

  • Run example with agent

java -javaagent:get-methods-1.0-SNAPSHOT.jar -jar example-run-1.0-SNAPSHOT.jar

  • Results
    This is Sample main
    This is constructor 
    This is Method 1
    public void com.github.shehanperera.example.Method.method1()
    This is Method 2
    public void com.github.shehanperera.example.Method.method2()
    String :parameters and number :4 and boolean :true
    public void com.github.shehanperera.example.Method.method4(int,java.lang.String,boolean)
    public static void com.github.shehanperera.example.Sample.main(java.lang.String[])

2. Get execution time of all methods

  • Copy execution-time-1.0-SNAPSHOT.jar form javaagent-bytebuddy/samples/execution-time/target to javaagent-bytebuddy/samples/example-run/target

  • Run example with agent

java -javaagent:execution-time-1.0-SNAPSHOT.jar -jar example-run-1.0-SNAPSHOT.jar

  • Results
    This is Sample main
    This is constructor 
    This is Method 1
    public void com.github.shehanperera.example.Method.method1() took 500 milliseconds 
    This is Method 2
    public void com.github.shehanperera.example.Method.method2() took 1000 milliseconds 
    String :parameters and number :4 and boolean :true
    public void com.github.shehanperera.example.Method.method4(int,java.lang.String,boolean) took 1 milliseconds 
    public static void com.github.shehanperera.example.Sample.main(java.lang.String[]) took 1522 milliseconds 

Simillary we can use all other agents (get-parameters ,constructor-instrument ,add-field,add-method,ignore-class) as above way. Just copy agnet to javaagent-bytebuddy/samples/example-run/target and run it with agent

java -javaagent:***-1.0-SNAPSHOT.jar -jar example-run-1.0-SNAPSHOT.jar

javaagent-bytebuddy's People

Contributors

shehanperera avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.