Skip to content

Commit

Permalink
feat: add a new tab for env variables in heapdump (#291)
Browse files Browse the repository at this point in the history
  • Loading branch information
gDreamcatcher authored Jul 12, 2024
1 parent 5299fc2 commit 98bb26a
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 16 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 @@ -34,6 +34,8 @@ public interface HeapDumpAnalyzer {

Map<String, String> getSystemProperties();

Map<String, String> getEnvVariables();

List<Overview.BigObject> getBiggestObjects();

@ApiMeta(aliases = "object")
Expand Down
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 @@ -72,17 +72,7 @@
import java.lang.ref.SoftReference;
import java.net.URL;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
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.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -271,6 +261,27 @@ public Map<String, String> getSystemProperties() {
});
}

@Override
public Map<String, String> getEnvVariables() {
return $(() -> {
Map<String, String> env = new HashMap<>();
Collection<IClass> classes = context.snapshot.getClassesByName("java.lang.ProcessEnvironment", true);
if(classes == null || classes.isEmpty()){
return env;
}
IClass systemClass = classes.iterator().next();
IObject iObject = (IObject) systemClass.resolveValue("theEnvironment");
IResultTable result = (IResultTable) SnapshotQuery.lookup("hash_entries", context.snapshot)
.setArgument("objects", iObject).execute(new ProgressListenerImpl(NoOpProgressListener));
int rowCount = result.getRowCount();
for(int i = 0; i< rowCount; i++){
Object row = result.getRow(i);
env.put((String) result.getColumnValue(row, 1), (String) result.getColumnValue(row, 2));
}
return env;
});
}

@Override
public JavaObject getObjectInfo(int objectId) {
return $(() -> {
Expand Down
85 changes: 85 additions & 0 deletions frontend/src/components/heapdump/EnvVariables.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<!--
Copyright (c) 2024 Contributors to the Eclipse Foundation
See the NOTICE file(s) distributed with this work for additional
information regarding copyright ownership.
This program and the accompanying materials are made available under the
terms of the Eclipse Public License 2.0 which is available at
http://www.eclipse.org/legal/epl-2.0
SPDX-License-Identifier: EPL-2.0
-->
<script setup lang="ts">
import CommonTable from '@/components/heapdump/CommonTable.vue';
import { Search } from '@element-plus/icons-vue';
import { hdt } from '@/components/heapdump/utils';
import { t } from '@/i18n/i18n';
const search = ref('');
const tableProps = ref({
columns: [
{
label: () => hdt('column.key'),
width: '40%',
property: 'key'
},
{
label: () => hdt('column.value'),
width: '60%',
property: 'value'
}
],
apis: [
{
api: 'envVariables',
respMapper: (d) => {
let result = [];
for (let key in d) {
result.push({
key,
value: d[key]
});
}
return result;
},
paged: false
}
],
showOverflowTooltip: false,
dataFilter: (d) =>
!search.value ||
d.key.toLowerCase().includes(search.value.toLowerCase()) ||
d.value.toLowerCase().includes(search.value.toLowerCase())
});
</script>
<template>
<div style="height: 100%; position: relative">
<div
style="
position: absolute;
right: 10px;
z-index: 10;
height: 32px;
flex-shrink: 0;
margin-bottom: 8px;
overflow: hidden;
display: flex;
align-items: center;
"
>
<el-input
v-model="search"
size="small"
style="width: 180px"
:placeholder="t('common.search')"
:suffix-icon="Search as any"
/>
</div>
<CommonTable ref="table" v-bind="tableProps" />
</div>
</template>
4 changes: 3 additions & 1 deletion frontend/src/components/heapdump/HeapDump.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import DominatorTree from '@/components/heapdump/DominatorTree.vue';
import Histogram from '@/components/heapdump/Histogram.vue';
import Threads from '@/components/heapdump/Threads.vue';
import SystemProperties from '@/components/heapdump/SystemProperties.vue';
import EnvVariables from '@/components/heapdump/EnvVariables.vue';
import Query from '@/components/heapdump/Query.vue';
import GCRoots from '@/components/heapdump/GCRoots.vue';
import UnreachableObjects from '@/components/heapdump/UnreachableObjects.vue';
Expand Down Expand Up @@ -56,7 +57,8 @@ const tabs = {
DirectByteBuffers,
DuplicateClasses,
UnreachableObjects,
SystemProperties
SystemProperties,
EnvVariables
};
const width = useDebouncedRef(window.innerWidth);
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/i18n/heapdump/en.ts
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 Down Expand Up @@ -40,6 +40,7 @@ export default {
threads: 'Threads',
unreachableObjects: 'Unreachable Objects',
systemProperties: 'System Properties',
envVariables: 'Environment Variables',
directByteBuffers: 'Direct Byte Buffers',
classLoaders: 'Class Loaders',
duplicateClasses: 'Duplicated Classes',
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/i18n/heapdump/zh.ts
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 Down Expand Up @@ -40,6 +40,7 @@ export default {
threads: '线程',
unreachableObjects: '不可达对象',
systemProperties: '系统属性',
envVariables: '环境变量',
directByteBuffers: '堆外内存',
classLoaders: '类加载器',
duplicateClasses: '重复类',
Expand Down

0 comments on commit 98bb26a

Please sign in to comment.