Giter Site home page Giter Site logo

manoelcampos / java-collections-advisor Goto Github PK

View Code? Open in Web Editor NEW
0.0 3.0 0.0 204 KB

An experimental Java 11 Agent to intercept JDK Collection calls, compute metrics and provide some advices (WIP)

Home Page: http://manoelcampos.com/java-collections-advisor

License: GNU General Public License v2.0

Shell 1.56% Java 98.44%
java byte-buddy java-agent instrumentation instrumentation-agent java-11

java-collections-advisor's Introduction

Java Collections Advisor Build Status

1. Introduction

2. Build and Running

In order to just try the agent you have two options:

  • run the com.manoelcampos.collectionsadvisor.AgentEntry class from the agent dir in your IDE;
  • or execute the agent/run.sh script.

2.1. Running an independent app

If you are building your own app and want to load the agent during application startup, check the sample-app project. Execute the sample-app/run.sh script to build and run the app using the agent.

The sample app has no agent code and the instrumentation happens in runtime.

3. Results after running the agent with your app

Current results are very basic since this is a working in progress. The agent is not giving any advice about collections utilization yet. Check an example of the agent results over a sample app using some Collections.

# Collections Advisor Agent
## Intercepted java.util.Collection methods calls from com.sample package

java.util.ArrayList from com.sample.ArrayListRegularSample:
  	Calls: 23 Lookups: 10 Clear Ups: 0
	Capacity changes: 1 -> inc 1 dec 0 | Size changes: 11 -> inc 10 dec 1
	Inserts: 10 -> head 0 middle 0 tail 10 moves 0
	Removals: 1 -> head 0 middle 0 tail 1 moves 0
java.util.ArrayList from com.sample.ArrayListAsQueueSample:
  	Calls: 31 Lookups: 0 Clear Ups: 0
	Capacity changes: 1 -> inc 1 dec 0 | Size changes: 20 -> inc 10 dec 10
	Inserts: 10 -> head 0 middle 0 tail 10 moves 0
	Removals: 10 -> head 9 middle 0 tail 1 moves 45
java.util.ArrayList from com.sample.ArrayListHeadAddSample:
  	Calls: 10 Lookups: 0 Clear Ups: 0
	Capacity changes: 1 -> inc 1 dec 0 | Size changes: 10 -> inc 10 dec 0
	Inserts: 10 -> head 9 middle 0 tail 1 moves 45
	Removals: 0 -> head 0 middle 0 tail 0 moves 0
java.util.LinkedList from com.sample.LinkedListSample:
  	Calls: 22 Lookups: 10 Clear Ups: 1
	Capacity changes: 0 -> inc 0 dec 0 | Size changes: 11 -> inc 10 dec 1
	Inserts: 10 -> head 0 middle 0 tail 10 moves 0
	Removals: 0 -> head 0 middle 0 tail 0 moves 0

4. References

java-collections-advisor's People

Contributors

manoelcampos avatar

Watchers

 avatar  avatar  avatar

java-collections-advisor's Issues

CollectionsAdvice.metricMap is empty when called from a different class

The map is updated inside the exit() method. However, when CollectionAdvice.printMetrics() is called from CollectionAgent, the map is empty.

Moving the map inside other classes such as CollectionAgent throws the following exception:

Starting com.manoelcampos.collectionsadvisor.Test
Exception in thread "main" java.lang.NoClassDefFoundError: com/manoelcampos/collectionsadvisor/CollectionAgent
	at java.base/java.util.LinkedList.add(LinkedList.java:343)
	at com.manoelcampos.collectionsadvisor.Test.<init>(Test.java:17)
	at com.manoelcampos.collectionsadvisor.CollectionAgent.main(CollectionAgent.java:40)

Extract metrics.jar from collections-advisor-agent uber jar in runtime

That will avoid having to place the metrics jar into some dir where the app is being executed.
That metrics.jar is load in the bootstrap class load because it's shared between the agent and the app.
This way, it enables the agent to store static data and the app to read it.

By requiring the sample jar to be into the app/agent dir so that the agent can load it on the bootstrap classloader, makes it more difficult to use the agent.
Since the agent is a uber jar that have the metrics as a dependency in the pom.xml, we can extract the metrics.jar dynamically from the uber jar and load it on the bootstrap class path.

For more details check #5.

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.