Skip to content

Commit

Permalink
feat: show jvm options in heap dump overview
Browse files Browse the repository at this point in the history
  • Loading branch information
D-D-H committed Aug 31, 2024
1 parent ce5a9a3 commit 97e72c0
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/********************************************************************************
* Copyright (c) 2021, 2023 Contributors to the Eclipse Foundation
* Copyright (c) 2021, 2024 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand Down Expand Up @@ -754,8 +754,6 @@ public BigObject(String label, int objectId, double value, String description) {
@Data
class Details {

public String jvmInfo;

public int identifierSize;

public long creationDate;
Expand All @@ -770,21 +768,20 @@ class Details {

public long usedHeapSize;

public boolean generationInfoAvailable;
public List<String> jvmOptions;

public Details(String jvmInfo, int identifierSize, long creationDate, int numberOfObjects,
public Details(int identifierSize, long creationDate, int numberOfObjects,
int numberOfGCRoots,
int numberOfClasses, int numberOfClassLoaders, long usedHeapSize,
boolean generationInfoAvailable) {
this.jvmInfo = jvmInfo;
List<String> jvmOptions) {
this.identifierSize = identifierSize;
this.creationDate = creationDate;
this.numberOfObjects = numberOfObjects;
this.numberOfGCRoots = numberOfGCRoots;
this.numberOfClasses = numberOfClasses;
this.numberOfClassLoaders = numberOfClassLoaders;
this.usedHeapSize = usedHeapSize;
this.generationInfoAvailable = generationInfoAvailable;
this.jvmOptions = jvmOptions;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,18 @@
import java.lang.ref.SoftReference;
import java.net.URL;
import java.nio.file.Path;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -194,6 +205,14 @@ private static Map<IClass, Set<String>> convert(AnalysisContext context,
}
}

private static <V> V $(RV<V> rv, V def) {
try {
return rv.run();
} catch (Throwable t) {
return def;
}
}

private static void $(R e) {
$(() -> {
e.run();
Expand All @@ -210,15 +229,38 @@ public void dispose() {
public Overview.Details getDetails() {
return $(() -> {
SnapshotInfo snapshotInfo = context.snapshot.getSnapshotInfo();
return new Overview.Details(snapshotInfo.getJvmInfo(), snapshotInfo.getIdentifierSize(),
snapshotInfo.getCreationDate().getTime(), snapshotInfo.getNumberOfObjects(),
snapshotInfo.getNumberOfGCRoots(), snapshotInfo.getNumberOfClasses(),
snapshotInfo.getNumberOfClassLoaders(), snapshotInfo.getUsedHeapSize(),
false);
return new Overview.Details(snapshotInfo.getIdentifierSize(),
snapshotInfo.getCreationDate().getTime(),
snapshotInfo.getNumberOfObjects(),
snapshotInfo.getNumberOfGCRoots(),
snapshotInfo.getNumberOfClasses(),
snapshotInfo.getNumberOfClassLoaders(),
snapshotInfo.getUsedHeapSize(),
getJVMOptions());
}
);
}

private List<String> getJVMOptions() {
return $(() -> {
List<String> result = new ArrayList<>();
IResult oqlResult = getOQLResult(context, "select v.vmArgs.list.a.@objectId from sun.management.VMManagementImpl v");
if (oqlResult instanceof IResultTable t && t.getRowCount() == 1) {
Object row = t.getRow(0);
Integer id = (Integer) t.getColumnValue(row, 0);
IObjectArray array = (IObjectArray) context.snapshot.getObject(id);
long[] refs = array.getReferenceArray();
for (long address : refs) {
if (address != 0) {
IObject object = context.snapshot.getObject(context.snapshot.mapAddressToId(address));
result.add(object.getClassSpecificName());
}
}
}
return result;
}, Collections.emptyList());
}

private <Res extends IResult> Res queryByCommand(AnalysisContext context,
String command) throws SnapshotException {
return queryByCommand(context, command, null, NoOpProgressListener);
Expand Down
28 changes: 15 additions & 13 deletions frontend/src/components/heapdump/Overview.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!--
Copyright (c) 2023 Contributors to the Eclipse Foundation
Copyright (c) 2023, 2024 Contributors to the Eclipse Foundation

See the NOTICE file(s) distributed with this work for additional
information regarding copyright ownership.
Expand All @@ -11,17 +11,17 @@
SPDX-License-Identifier: EPL-2.0
-->
<script setup lang="ts">
import { useAnalysisApiRequester } from '@/composables/analysis-api-requester';
import { hdt } from '@/components/heapdump/utils';
import { prettyCount, prettySize, prettyDate } from '@/support/utils';
import { a2rgb, PIE_COLORS, REMAINDER_COLOR } from '@/components/heapdump/color-helper';
import { ArcElement, Chart, Title, Tooltip } from 'chart.js';
import { Doughnut } from 'vue-chartjs';
import { useSelectedObject } from '@/composables/heapdump/selected-object';
import { currentLocale } from '@/i18n/i18n';
import { isDark } from '@/composables/theme';
import {useAnalysisApiRequester} from '@/composables/analysis-api-requester';
import {hdt} from '@/components/heapdump/utils';
import {prettyCount, prettyDate, prettySize} from '@/support/utils';
import {a2rgb, PIE_COLORS, REMAINDER_COLOR} from '@/components/heapdump/color-helper';
import {ArcElement, Chart, Title, Tooltip} from 'chart.js';
import {Doughnut} from 'vue-chartjs';
import {useSelectedObject} from '@/composables/heapdump/selected-object';
import {currentLocale} from '@/i18n/i18n';
import {isDark} from '@/composables/theme';
import CommonContextMenu from '@/components/common/CommonContextMenu.vue';
import { commonMenu as menu } from '@/components/heapdump/menu';
import {commonMenu as menu} from '@/components/heapdump/menu';

const { request } = useAnalysisApiRequester();

Expand All @@ -40,7 +40,8 @@ request('details').then((data) => {
'numberOfClassLoaders',
'numberOfGCRoots',
'creationDate',
'identifierSize'
'identifierSize',
'jvmOptions'
];
let formatters = [
prettySize,
Expand All @@ -49,7 +50,8 @@ request('details').then((data) => {
prettyCount,
prettyCount,
prettyDate,
(i) => (i === 8 ? '64 bit' : '32 bit')
(i) => (i === 8 ? '64 bit' : '32 bit'),
(options) => (options.length > 0 ? options.join(' ') : 'N/A')
];
for (let i = 0; i < keys.length; i++) {
information.value.push({
Expand Down
1 change: 1 addition & 0 deletions frontend/src/i18n/heapdump/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export default {
numberOfGCRoots: 'GC Root Count',
creationDate: 'Creation Date',
identifierSize: 'OS Bit',
jvmOptions: 'JVM Options',

biggestObjectsChartTitle: 'Biggest Objects (by Retained Size)'
},
Expand Down
1 change: 1 addition & 0 deletions frontend/src/i18n/heapdump/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export default {
numberOfGCRoots: 'GC 根对象数量',
creationDate: '创建时间',
identifierSize: '系统位数',
jvmOptions: 'JVM 选项',

biggestObjectsChartTitle: '大对象(按对象的支配内存大小计算)'
},
Expand Down

0 comments on commit 97e72c0

Please sign in to comment.