Skip to content

Commit

Permalink
Ignore gc alloc metrics when unsupported (#3225)
Browse files Browse the repository at this point in the history
* simply ignore when it's unsupported
  • Loading branch information
SylvainJuge committed Jul 10, 2023
1 parent 86184c5 commit 71bbdf7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Expand Up @@ -35,6 +35,7 @@ Use subheadings with the "=====" level for adding notes for unreleased changes:
===== Bug fixes
* Fixed agent programmatic attach with immutable config - {pull}3170[#3170]
* Prevent overriding `ELASTIC_APM_AWS_LAMBDA_HANDLER` in AWS lambda execution when explicitly set - {pull}3205[#3205]
* Ignore gc allocation metrics when unsupported - {pull}3225[#3225]
[[release-notes-1.x]]
=== Java Agent version 1.x
Expand Down
Expand Up @@ -62,11 +62,17 @@ public double get() {
// J9 does contain com.sun.management.ThreadMXBean in classpath
// but the actual MBean it uses (com.ibm.lang.management.internal.ExtendedThreadMXBeanImpl) does not implement it
if (sunBeanClass.isInstance(ManagementFactory.getThreadMXBean())) {

DoubleSupplier supplier = (DoubleSupplier) Class.forName(getClass().getName() + "$HotspotAllocationSupplier").getEnumConstants()[0];

// attempt to read it at least once before registering
supplier.get();

// in reference to JMH's GC profiler (gc.alloc.rate)
registry.add("jvm.gc.alloc", Labels.EMPTY,
(DoubleSupplier) Class.forName(getClass().getName() + "$HotspotAllocationSupplier").getEnumConstants()[0]);
registry.add("jvm.gc.alloc", Labels.EMPTY, supplier);
}
} catch (ClassNotFoundException ignore) {
} catch (UnsupportedOperationException ignore){
}
}

Expand Down

0 comments on commit 71bbdf7

Please sign in to comment.