-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Fix #9177 dump JVM info #11845
Merged
Merged
Fix #9177 dump JVM info #11845
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a4f680a
Fix #9177 dump JVM info
gregw 499c18b
Experiment providing random access to fields.
gregw f64c059
Experiment providing random access to fields.
gregw c8dc5ad
Experiment providing random access to fields.
gregw 6359cf8
Experiment providing random access to fields.
gregw 1cbc97e
Experiment providing random access to fields.
gregw e95b14d
Experiment providing random access to fields.
gregw 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 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 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 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 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 |
---|---|---|
|
@@ -23,6 +23,7 @@ | |
import java.util.Objects; | ||
import java.util.stream.Stream; | ||
|
||
import org.eclipse.jetty.util.Jetty; | ||
import org.eclipse.jetty.util.StringUtil; | ||
import org.eclipse.jetty.util.TypeUtil; | ||
import org.eclipse.jetty.util.annotation.ManagedObject; | ||
|
@@ -31,7 +32,7 @@ | |
@ManagedObject("Dumpable Object") | ||
public interface Dumpable | ||
{ | ||
String KEY = "key: +- bean, += managed, +~ unmanaged, +? auto, +: iterable, +] array, +@ map, +> undefined"; | ||
String KEY = "key: +- bean, += managed, +~ unmanaged, +? auto, +: iterable, +] array, +@ map, +> undefined\n"; | ||
|
||
@ManagedOperation(value = "Dump the nested Object state as a String", impact = "INFO") | ||
default String dump() | ||
|
@@ -50,24 +51,46 @@ default String dump() | |
void dump(Appendable out, String indent) throws IOException; | ||
|
||
/** | ||
* Utility method to implement {@link #dump()} by calling {@link #dump(Appendable, String)} | ||
* Utility method to call dump to a {@link String} | ||
* | ||
* @param dumpable The dumpable to dump | ||
* @return The dumped string | ||
* @see #dump(Appendable, String) | ||
*/ | ||
static String dump(Dumpable dumpable) | ||
{ | ||
StringBuilder b = new StringBuilder(); | ||
dump(dumpable, b); | ||
return b.toString(); | ||
} | ||
|
||
/** | ||
* Utility method to dump to an {@link Appendable} | ||
* | ||
* @param dumpable The dumpable to dump | ||
* @param out The destination of the dump | ||
*/ | ||
static void dump(Dumpable dumpable, Appendable out) | ||
{ | ||
try | ||
{ | ||
dumpable.dump(b, ""); | ||
dumpable.dump(out, ""); | ||
|
||
out.append(KEY); | ||
Runtime runtime = Runtime.getRuntime(); | ||
out.append("JVM: %s %s; Jetty: %s; CPUs: %d; mem(free/total/max)B:%,d/%,d/%,d".formatted( | ||
System.getProperty("java.runtime.name"), | ||
System.getProperty("java.runtime.version"), | ||
Jetty.VERSION, | ||
runtime.availableProcessors(), | ||
runtime.freeMemory(), | ||
runtime.totalMemory(), | ||
runtime.maxMemory())); | ||
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'd format in MiB (so divide by 1024*1024). I'd also see what OS it is, so sysprop 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. Now looks like:
|
||
} | ||
catch (IOException e) | ||
{ | ||
b.append(e.toString()); | ||
throw new RuntimeException(e); | ||
gregw marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
b.append(KEY); | ||
return b.toString(); | ||
} | ||
|
||
/** | ||
|
@@ -301,7 +324,7 @@ public void dump(Appendable out, String indent) throws IOException | |
* interface to allow it to refine which of its beans can be | ||
* dumped. | ||
*/ | ||
public interface DumpableContainer extends Dumpable | ||
interface DumpableContainer extends Dumpable | ||
{ | ||
default boolean isDumpable(Object o) | ||
{ | ||
|
39 changes: 39 additions & 0 deletions
39
jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/component/DumpableMap.java
This file contains 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,39 @@ | ||
// | ||
// ======================================================================== | ||
// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others. | ||
// | ||
// This program and the accompanying materials are made available under the | ||
// terms of the Eclipse Public License v. 2.0 which is available at | ||
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 | ||
// which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
// | ||
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
// ======================================================================== | ||
// | ||
|
||
package org.eclipse.jetty.util.component; | ||
|
||
import java.io.IOException; | ||
import java.util.Comparator; | ||
import java.util.Map; | ||
|
||
public class DumpableMap implements Dumpable | ||
{ | ||
private final String _name; | ||
private final Map<?, ?> _map; | ||
|
||
public DumpableMap(String name, Map<?, ?> map) | ||
{ | ||
_name = name; | ||
_map = map; | ||
} | ||
|
||
@Override | ||
public void dump(Appendable out, String indent) throws IOException | ||
{ | ||
Object[] array = _map.entrySet().stream() | ||
.sorted(Map.Entry.comparingByKey(Comparator.comparing(String::valueOf))) | ||
.map(e -> Dumpable.named(String.valueOf(e.getKey()), e.getValue())).toArray(Object[]::new); | ||
Dumpable.dumpObjects(out, indent, _name + " size=" + array.length, array); | ||
} | ||
} |
This file contains 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 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 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 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
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.
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.
The vendor is missing, and it's important (say IBM).
I would use:
java.vendor
java.vm.name
java.vm.version
.For example, IBM's does not have any
java.runtime.*
properties (at least according to their docs).Use
MiB
instead ofMB
(powers of 1024 instead of 1000).I would just print the UTC time, not the local one.
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 like having UTC and local time... it is OK for you who only lives an hour or 2 off UTC, but for those of us that struggle with bigger differences, it can be nice to have them both listed :)
Having said that, my laptop still thinks it is in Italy??!?!?