techzombie
techzombie

Reputation: 21

Logging System Metrics from JAR

Let's say there is an application x which uses an external jar y.

x uses datadog-api to log metrics and y too.

I want to see if it's possible to log system metrics which are specific to only the jar .i.e. how many gc cycles the jar is using ?

Using system.gc we can find out how many cycles the whole app is using on that host, but what about specific jar?

Please clarify if someone knows.

Upvotes: 0

Views: 121

Answers (1)

dan.m was user2321368
dan.m was user2321368

Reputation: 1705

All the classes that make up your application allocate memory from the same 'pool' of memory. While the JVM can know the site (e.g. class/method/line) of the memory allocation request that failed (and which resulted in a GC) it has no knowledge or concept of a class being 'responsible' for a GC.

It could be that x has allocated 99.99% of the memory available in the eden, and then some code in y comes along, attempts to allocate a few bytes, and a GC ensues. Is y really responsible for the GC?

If you wanted to determine which classes were responsible for the allocations that were using lots of heap, you'd need to run your code with a profiler of some sort. First you'd want to find which classes were the most allocated, then you'd want to where those class where being allocated from. Presumably, you'll be able to map the name of the method where it is being allocated from back to the jar that declares that method.

Upvotes: 1

Related Questions