-
Notifications
You must be signed in to change notification settings - Fork 1k
Add Compilation JVM metric binder #1589
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/** | ||
* Copyright 2017 Pivotal Software, Inc. | ||
* <p> | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* <p> | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.micrometer.core.instrument.binder.jvm; | ||
|
||
import io.micrometer.core.instrument.FunctionCounter; | ||
import io.micrometer.core.instrument.MeterRegistry; | ||
import io.micrometer.core.instrument.Tag; | ||
import io.micrometer.core.instrument.Tags; | ||
import io.micrometer.core.instrument.binder.MeterBinder; | ||
import io.micrometer.core.lang.NonNullApi; | ||
import io.micrometer.core.lang.NonNullFields; | ||
|
||
import java.lang.management.CompilationMXBean; | ||
import java.lang.management.ManagementFactory; | ||
|
||
import static java.util.Collections.emptyList; | ||
|
||
@NonNullApi | ||
@NonNullFields | ||
public class CompilationMetrics implements MeterBinder { | ||
private final Iterable<Tag> tags; | ||
|
||
public CompilationMetrics() { | ||
this(emptyList()); | ||
} | ||
|
||
public CompilationMetrics(Iterable<Tag> tags) { | ||
this.tags = tags; | ||
} | ||
|
||
@Override | ||
public void bindTo(MeterRegistry registry) { | ||
CompilationMXBean compilationBean = ManagementFactory.getCompilationMXBean(); | ||
if (compilationBean.isCompilationTimeMonitoringSupported()) { | ||
FunctionCounter.builder("jvm.compilation.time.total", compilationBean, CompilationMXBean::getTotalCompilationTime) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am unsure about the naming and the baseUnit usage below. Unfortunately we can't make this a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That will become How about just There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
.tags(Tags.concat(tags, "compiler", compilationBean.getName())) | ||
.description("The approximate accumulated elapsed time spent in compilation") | ||
.baseUnit("ms") | ||
.register(registry); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* Copyright 2017 Pivotal Software, Inc. | ||
* <p> | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* <p> | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.micrometer.core.instrument.binder.jvm; | ||
|
||
import io.micrometer.core.instrument.MeterRegistry; | ||
import io.micrometer.core.instrument.simple.SimpleMeterRegistry; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | ||
|
||
class CompilationMetricsTest { | ||
@Test | ||
void compilationTimeMetric() { | ||
MeterRegistry registry = new SimpleMeterRegistry(); | ||
new CompilationMetrics().bindTo(registry); | ||
|
||
assertThat(registry.get("jvm.compilation.time.total").functionCounter().count()).isGreaterThan(0); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@shakuzen @jkschneider Should this class be named
JvmCompilationMetrics
since these are metrics around the JVM?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't mind renaming the class but there is already a
ClassLoaderMetrics
class which should be renamedJvmClassLoaderMetrics
in that case.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree
JvmCompilationMetrics
is more clear here.ClassLoaderMetrics
is already released public API so we can't change that without breaking all users of it.