Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/llamalad7/jetbrainsproject-coverageagent
Small Java agent for logging code coverage as part of my JetBrains internship application.
https://github.com/llamalad7/jetbrainsproject-coverageagent
Last synced: 4 days ago
JSON representation
Small Java agent for logging code coverage as part of my JetBrains internship application.
- Host: GitHub
- URL: https://github.com/llamalad7/jetbrainsproject-coverageagent
- Owner: LlamaLad7
- Created: 2023-12-28T18:38:33.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-01-07T21:32:49.000Z (12 months ago)
- Last Synced: 2024-11-08T04:23:46.852Z (about 2 months ago)
- Language: Java
- Size: 74.2 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.MD
Awesome Lists containing this project
README
# Coverage Agent
This is a small Java agent which dumps a list of all classes within a specified package in which code is executed.
### Note: This is a new implementation using `INVOKEDYNAMIC`, my original one can be found [here](https://github.com/LlamaLad7/JetBrainsProject-CoverageAgent/tree/original-implementation).
## Usage
```bash
java -javaagent:""=package/to/monitor/ ...
```See also the [example](https://github.com/LlamaLad7/JetBrainsProject-CoverageAgent/tree/main/example), notably its
buildscript.The agent will keep track of all executed classes within the specified package, and will dump a list of them to
`executedClasses.txt`, both every 5 seconds and on JVM shutdown.The agent will not track calls to constructors and class initializers, since these are deemed not useful for monitoring
coverage. You can give other methods the same behaviour by annotating them with:```java
@DoNotTrack
```## Implementation
Consider this class:
```java
public class DemoClass {
public static void main(String[] args) {
System.out.println("Hi!");
}
}
```The agent will transform the class so it becomes equivalent to:
```java
public class DemoClass {
public static void main(String[] args) {
coverageAgent$notify();
System.out.println("Hi!");
}public static void coverageAgent$notify() {
IndySupport.notify(DemoClass.class);
}
}
```(The actual name of the generated method is not a legal Java/Kotlin identifier to ensure there will be no conflicts.)
The invokedynamic call will notify the agent of the class's execution, and then rebind itself to do nothing on
subsequent executions. The JVM should be able to see through this and optimize the call out entirely in hot code.The use of a generated method means there is only a single INDY call-site per class, so after any of the methods
trigger it, it will become inactive.We ignore interfaces which were compiled with Java <8, since their methods cannot have bodies.
## Considerations for the future
- Ideally the agent would be configurable via a more robust config file which could be passed in
- Maybe we should have some kind of system to ignore methods called from `` or ``, not just those methods
themselves?