-
Notifications
You must be signed in to change notification settings - Fork 6
MX Bean support #43
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
Merged
MatthewKhouzam
merged 1 commit into
eclipse-tracecompass:main
from
MatthewKhouzam:frijoles
Feb 14, 2025
Merged
MX Bean support #43
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
src/main/java/org/eclipse/tracecompass/traceeventlogger/beans/ITraceEventLoggerBean.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| /******************************************************************************* | ||
| * Copyright (c) 2025 Ericsson | ||
| * | ||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| * of this software and associated documentation files (the “Software”), to deal | ||
| * in the Software without restriction, including without limitation the rights | ||
| * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| * copies of the Software, and to permit persons to whom the Software is | ||
| * furnished to do so, subject to the following conditions: | ||
| * | ||
| * The above copyright notice and this permission notice shall be included in | ||
| * all copies or substantial portions of the Software. | ||
| * | ||
| * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
| * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
| * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | ||
| * IN THE SOFTWARE. | ||
| * | ||
| * SPDX-License-Identifier: MIT | ||
| *******************************************************************************/ | ||
|
|
||
| package org.eclipse.tracecompass.traceeventlogger.beans; | ||
|
|
||
| import javax.management.MXBean; | ||
|
|
||
| /** | ||
| * Trace Event Logger Monitor MXBean interface. Needed to publish MXBeans. | ||
| * | ||
| * An MXBean is a managed java object that uses Java Management (JMX) to publish | ||
| * information. MXBeans have a pre-defined datatype, and in this case will be | ||
| * SimpleTypes. This allows the value to be easily plotted. | ||
| * | ||
| * @author Matthew Khouzam | ||
| */ | ||
| @MXBean | ||
| public interface ITraceEventLoggerBean { | ||
|
|
||
| /** | ||
| * Get the observed element name | ||
| * | ||
| * @return the observed element name | ||
| */ | ||
| String getObservedElementName(); | ||
|
|
||
| /** | ||
| * Get the mean (average) time | ||
| * | ||
| * @return the average time | ||
| */ | ||
| double getMeanTime(); | ||
|
|
||
| /** | ||
| * Get the total (sum) time | ||
| * | ||
| * @return the sum time | ||
| */ | ||
| long getTotalTime(); | ||
|
|
||
| /** | ||
| * Get the number of times (count) the element is added | ||
| * | ||
| * @return the count of elements added | ||
| */ | ||
| long getCount(); | ||
|
|
||
| /** | ||
| * Get the minimum time | ||
| * | ||
| * @return the minimum time | ||
| */ | ||
| long getMinTime(); | ||
|
|
||
| /** | ||
| * Get the maximum time | ||
| * | ||
| * @return the maximum time | ||
| */ | ||
| long getMaxTime(); | ||
| } |
120 changes: 120 additions & 0 deletions
120
src/main/java/org/eclipse/tracecompass/traceeventlogger/beans/TraceEventLoggerBean.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| /******************************************************************************* | ||
| * Copyright (c) 2025 Ericsson | ||
| * | ||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| * of this software and associated documentation files (the “Software”), to deal | ||
| * in the Software without restriction, including without limitation the rights | ||
| * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| * copies of the Software, and to permit persons to whom the Software is | ||
| * furnished to do so, subject to the following conditions: | ||
| * | ||
| * The above copyright notice and this permission notice shall be included in | ||
| * all copies or substantial portions of the Software. | ||
| * | ||
| * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
| * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
| * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | ||
| * IN THE SOFTWARE. | ||
| * | ||
| * SPDX-License-Identifier: MIT | ||
| *******************************************************************************/ | ||
|
|
||
| package org.eclipse.tracecompass.traceeventlogger.beans; | ||
|
|
||
| import java.lang.management.ManagementFactory; | ||
| import java.util.LongSummaryStatistics; | ||
| import java.util.logging.Level; | ||
| import java.util.logging.Logger; | ||
|
|
||
| import javax.management.JMException; | ||
| import javax.management.MBeanServer; | ||
| import javax.management.NotificationBroadcasterSupport; | ||
| import javax.management.ObjectName; | ||
|
|
||
| /** | ||
| * Trace Event Logger internal bean. | ||
| * | ||
| * A bean is a java standard object to publish information. | ||
| * | ||
| * Used to publish performance metrics and KPIs, can be seen with tools such as | ||
| * visualvm and jconsole. | ||
| * | ||
| * This class is internal, it should not be extended or made into API. | ||
| * | ||
| * @author Matthew Khouzam | ||
| */ | ||
| public final class TraceEventLoggerBean extends NotificationBroadcasterSupport implements ITraceEventLoggerBean { | ||
|
|
||
| private final LongSummaryStatistics fStats = new LongSummaryStatistics(); | ||
| private final String fLabel; | ||
|
|
||
| /** | ||
| * Constructor | ||
| * | ||
| * @param label | ||
| * the name of the bean, colons (':') will be replaced with | ||
| * hyphens ('-') | ||
| */ | ||
| public TraceEventLoggerBean(String label) { | ||
| fLabel = label; | ||
| /** | ||
| * Override potentially finer logging for these, as this breaks the | ||
| * resulting JSON trace file. This happens upon @{link | ||
| * ManagementFactory} use below. Use the default @{link Level.FINE}, | ||
| * which doesn't output any such breaking strings. Finer logging for | ||
| * this package isn't necessary anyway here. | ||
| */ | ||
| Logger.getLogger("javax.management").setLevel(Level.FINE); //$NON-NLS-1$ NOSONAR | ||
| MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); | ||
| String beanName = "org.eclipse.tracecompass.log:type=TraceEventLoggerBean,name=" + label.replace(':', '-'); //$NON-NLS-1$ | ||
| try { | ||
| ObjectName name = new ObjectName(beanName); | ||
| mbs.registerMBean(this, name); | ||
| } catch (JMException e) { | ||
| java.util.logging.Logger.getAnonymousLogger().log(Level.WARNING, "Cannot create bean", e); //$NON-NLS-1$ | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public String getObservedElementName() { | ||
| return fLabel; | ||
| } | ||
|
|
||
| @Override | ||
| public double getMeanTime() { | ||
| return fStats.getAverage(); | ||
| } | ||
|
|
||
| @Override | ||
| public long getMinTime() { | ||
| return fStats.getMin(); | ||
| } | ||
|
|
||
| @Override | ||
| public long getMaxTime() { | ||
| return fStats.getMax(); | ||
| } | ||
|
|
||
| @Override | ||
| public long getTotalTime() { | ||
| return fStats.getSum(); | ||
| } | ||
|
|
||
| @Override | ||
| public long getCount() { | ||
| return fStats.getCount(); | ||
| } | ||
|
|
||
| /** | ||
| * Accept a long to aggregate | ||
| * | ||
| * @param value | ||
| * the value to aggregate | ||
| */ | ||
| public void accept(long value) { | ||
| fStats.accept(value); | ||
| } | ||
| } |
83 changes: 83 additions & 0 deletions
83
src/main/java/org/eclipse/tracecompass/traceeventlogger/beans/TraceEventLoggerManager.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| /******************************************************************************* | ||
| * Copyright (c) 2025 Ericsson | ||
| * | ||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| * of this software and associated documentation files (the “Software”), to deal | ||
| * in the Software without restriction, including without limitation the rights | ||
| * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| * copies of the Software, and to permit persons to whom the Software is | ||
| * furnished to do so, subject to the following conditions: | ||
| * | ||
| * The above copyright notice and this permission notice shall be included in | ||
| * all copies or substantial portions of the Software. | ||
| * | ||
| * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
| * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
| * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | ||
| * IN THE SOFTWARE. | ||
| * | ||
| * SPDX-License-Identifier: MIT | ||
| *******************************************************************************/ | ||
| package org.eclipse.tracecompass.traceeventlogger.beans; | ||
| import java.util.LinkedHashMap; | ||
| import java.util.Map; | ||
|
|
||
| /** | ||
| * Trace Event Logger Monitor, shows the state of every scoped logger | ||
| * | ||
| * Use the {@link #update(String, long)} method to publish a new value | ||
| * | ||
| * @author Matthew Khouzam | ||
| */ | ||
| public final class TraceEventLoggerManager { | ||
|
|
||
| private final Map<String, TraceEventLoggerBean> fCounters = new LinkedHashMap<>(); | ||
|
|
||
| /** | ||
| * Instance, internal, do not use | ||
| */ | ||
| private static TraceEventLoggerManager sInstance = null; | ||
|
|
||
| private boolean fEnabled = false; | ||
|
|
||
| /** | ||
| * Constructor | ||
| */ | ||
| private TraceEventLoggerManager() { | ||
| String loggingProperty = System.getProperty("enableMonitoring", "false"); //$NON-NLS-1$ //$NON-NLS-2$ | ||
MatthewKhouzam marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // Convert to boolean | ||
| fEnabled = Boolean.parseBoolean(loggingProperty); | ||
| } | ||
|
|
||
| /** | ||
| * Update a value | ||
| * | ||
| * @param label | ||
| * the label to update | ||
| * @param value | ||
| * the value to update for a given label | ||
| */ | ||
| public synchronized void update(String label, long value) { | ||
| if (fEnabled) { | ||
| fCounters.computeIfAbsent(label, TraceEventLoggerBean::new).accept(value); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Get the instance of the manager | ||
| * | ||
| * @return the manager | ||
| */ | ||
| public static synchronized TraceEventLoggerManager getInstance() { | ||
| TraceEventLoggerManager instance = sInstance; | ||
| if (instance == null) { | ||
| instance = new TraceEventLoggerManager(); | ||
| sInstance = instance; | ||
| } | ||
| return instance; | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.