Skip to content

Commit

Permalink
[JENKINS-22791] cache is no longer used
Browse files Browse the repository at this point in the history
  • Loading branch information
escoem committed Oct 22, 2017
1 parent f1b0bf6 commit 42fae57
Showing 1 changed file with 24 additions and 41 deletions.
Expand Up @@ -35,11 +35,10 @@
@Extension
@Restricted(NoExternalUse.class)
public class HeapUsageHistogram extends Component {
private static final int OFFSET = 3;
private static final int MAX = 200 + OFFSET;
// first 200 classes so 203 lines required because of the header
private static final int MAX = 203;

private static final Logger logger = Logger.getLogger(HeapUsageHistogram.class.getName());
private final WeakHashMap<Node, String> heapHistoCache = new WeakHashMap<Node, String>();

@NonNull
@Override
Expand All @@ -66,50 +65,34 @@ public void writeTo(OutputStream os) throws IOException {
}

private String getLiveHistogram(Node node) throws IOException {
return AsyncResultCache.get(node,
heapHistoCache,
new GetLiveHeapHistogram(),
"heap histogram",
"N/A: No connection to node, or no cache.");
}

private static final class GetLiveHeapHistogram implements Callable<String, RuntimeException> {
public String call() {
final String raw = getRawLiveHistogram();
final String[] lines = raw.split("\n");
final int limit = MAX <= lines.length ? MAX : lines.length;
final String raw = getRawLiveHistogram();
final String[] lines = raw.split("\n");
final int limit = MAX <= lines.length ? MAX : lines.length;

final StringBuilder bos = new StringBuilder();
final StringBuilder bos = new StringBuilder();

bos.append("Master Heap Histogram");
for (int i=0; i<limit; i++) {
bos.append(lines[i]).append('\n');
}

return bos.toString();
bos.append("Master Heap Histogram");
for (int i=0; i<limit; i++) {
bos.append(lines[i]).append('\n');
}

/** {@inheritDoc} */
@Override
public void checkRoles(RoleChecker checker) throws SecurityException {
// TODO: do we have to verify some role?
}
return bos.toString();
}

private String getRawLiveHistogram() {
String result;
try {
ObjectName objName = new ObjectName("com.sun.management:type=DiagnosticCommand");
MBeanServer platform = ManagementFactory.getPlatformMBeanServer();
if (platform == null) {
return "N/A";
}
result = (String) platform.invoke(objName, "gcClassHistogram", new Object[] {null}, new String[]{String[].class.getName()});
private String getRawLiveHistogram() {
String result;
try {
ObjectName objName = new ObjectName("com.sun.management:type=DiagnosticCommand");
MBeanServer platform = ManagementFactory.getPlatformMBeanServer();
if (platform == null) {
return "N/A";
}
catch (InstanceNotFoundException | ReflectionException | MBeanException | MalformedObjectNameException e) {
logger.log(Level.WARNING,"Could not record heap live histogram.", e);
result = "N/A";
}
return result;
result = (String) platform.invoke(objName, "gcClassHistogram", new Object[] {null}, new String[]{String[].class.getName()});
}
catch (InstanceNotFoundException | ReflectionException | MBeanException | MalformedObjectNameException e) {
logger.log(Level.WARNING,"Could not record heap live histogram.", e);
result = "N/A";
}
return result;
}
}

0 comments on commit 42fae57

Please sign in to comment.