CN-815: 前端内存占用分析

This commit is contained in:
刘洪洪
2022-11-29 17:21:01 +08:00
parent 2cf206de5a
commit e89fc78aca
12 changed files with 83 additions and 11 deletions

View File

@@ -109,7 +109,7 @@ export default {
// } // }
// } // }
timeFilter: { timeFilter: {
handler (n) { handler () {
if (this.$route.path === '/panel/networkAppPerformance' && (this.queryCondition || this.networkOverviewBeforeTab)) { if (this.$route.path === '/panel/networkAppPerformance' && (this.queryCondition || this.networkOverviewBeforeTab)) {
this.scoreCalculation() this.scoreCalculation()
} }
@@ -120,7 +120,7 @@ export default {
// this.panelName = this.$store.getters.getPanelName // this.panelName = this.$store.getters.getPanelName
const pName = this.$route.query.panelName ? this.$t(this.$route.query.panelName) : '' const pName = this.$route.query.panelName ? this.$t(this.$route.query.panelName) : ''
const curTabProp = this.$route.query.dimensionType ? this.$route.query.dimensionType : null const curTabProp = this.$route.query.dimensionType ? this.$route.query.dimensionType : null
if(this.$route.params.typeName === fromRoute.dnsServiceInsights) { if (this.$route.params.typeName === fromRoute.dnsServiceInsights) {
this.dnsQtypeMapData = await getDnsMapData('dnsQtype') this.dnsQtypeMapData = await getDnsMapData('dnsQtype')
this.dnsRcodeMapData = await getDnsMapData('dnsRcode') this.dnsRcodeMapData = await getDnsMapData('dnsRcode')
this.$store.commit('setDnsQtypeMapData', this.dnsQtypeMapData) this.$store.commit('setDnsQtypeMapData', this.dnsQtypeMapData)
@@ -200,7 +200,7 @@ export default {
this.scoreCalculation() this.scoreCalculation()
} }
}, },
setup (props, ctx) { setup (props) {
// todo 目前在panel页面测试后续会挪到router里 // todo 目前在panel页面测试后续会挪到router里
const store = useStore() const store = useStore()
const cancelList = store.state.panel.httpCancel const cancelList = store.state.panel.httpCancel
@@ -359,7 +359,7 @@ export default {
} else { } else {
condition = this.queryCondition condition = this.queryCondition
} }
let type = this.dimensionType || this.networkOverviewBeforeTab const type = this.dimensionType || this.networkOverviewBeforeTab
const params = { const params = {
startTime: getSecond(this.timeFilter.startTime), startTime: getSecond(this.timeFilter.startTime),
endTime: getSecond(this.timeFilter.endTime), endTime: getSecond(this.timeFilter.endTime),
@@ -428,6 +428,10 @@ export default {
routerObj.query = query routerObj.query = query
} }
} }
this.emitter.off('reloadChartList')
this.$store = null
this.emitter = null
} }
} }
</script> </script>

View File

@@ -154,7 +154,7 @@ export default {
}, },
watch: { watch: {
timeFilter: { timeFilter: {
handler (n) { handler () {
this.init() this.init()
} }
} }
@@ -167,7 +167,8 @@ export default {
init () { init () {
this.toggleLoading(true) this.toggleLoading(true)
// 链路基本信息 // 链路基本信息
let linkInfo = localStorage.getItem(storageKey.linkInfo) let linkInfo = null
linkInfo = localStorage.getItem(storageKey.linkInfo)
linkInfo = JSON.parse(linkInfo) linkInfo = JSON.parse(linkInfo)
const params = { const params = {
startTime: getSecond(this.timeFilter.startTime), startTime: getSecond(this.timeFilter.startTime),
@@ -383,6 +384,9 @@ export default {
return newValue return newValue
} }
},
beforeUnmount () {
this.unitConvert = null
} }
} }
</script> </script>

View File

@@ -220,7 +220,7 @@ export default {
this.nextGridData = nextGridData this.nextGridData = nextGridData
} }
} else { } else {
this.isNextNoData = true this.isNextNoData = false
this.isNextShowError = true this.isNextShowError = true
this.nextErrorMsg = res[1].message this.nextErrorMsg = res[1].message
} }

View File

@@ -428,6 +428,9 @@ export default {
} }
}, },
mounted () { mounted () {
this.myChart = null
this.myChart2 = null
this.chartOption = null
this.timer = setTimeout(() => { this.timer = setTimeout(() => {
this.linkTrafficSankeyDataRequest(this.tab) this.linkTrafficSankeyDataRequest(this.tab)
}, 100) }, 100)
@@ -436,6 +439,19 @@ export default {
beforeUnmount () { beforeUnmount () {
clearTimeout(this.timer) clearTimeout(this.timer)
window.removeEventListener('resize', this.resize) window.removeEventListener('resize', this.resize)
if (this.myChart) {
this.myChart.dispose()
// 避免不能生效
this.myChart = null
}
if (this.myChart2) {
this.myChart2.dispose()
this.myChart2 = null
}
this.chartOption = null
this.cnLinkInfo = null
this.unitConvert = null
} }
} }
</script> </script>

View File

@@ -737,6 +737,8 @@ export default {
window.removeEventListener('resize', this.resize) window.removeEventListener('resize', this.resize)
clearTimeout(this.timerScroll) clearTimeout(this.timerScroll)
clearTimeout(this.timerSearch) clearTimeout(this.timerSearch)
this.myChart = null
this.unitConvert = null
} }
} }
</script> </script>

View File

@@ -388,7 +388,11 @@ export default {
// 此处为验证是否因dom未销毁导致图表出错后续可能会改 // 此处为验证是否因dom未销毁导致图表出错后续可能会改
let dom = null let dom = null
dom = document.getElementById('overviewLineChart') dom = document.getElementById('overviewLineChart')
this.myChart = null // this.myChart = null
if (this.myChart) {
this.myChart.dispose()
this.myChart = null
}
this.myChart = echarts.init(dom) this.myChart = echarts.init(dom)
this.chartOption = stackedLineChartOption this.chartOption = stackedLineChartOption
const chartOption = this.chartOption.series[0] const chartOption = this.chartOption.series[0]
@@ -673,6 +677,8 @@ export default {
mounted () { mounted () {
// todo 初始化鼠标事件,开启右键返回 // todo 初始化鼠标事件,开启右键返回
// this.domInit() // this.domInit()
this.myChart = null
this.chartOption = null
this.timer = setTimeout(() => { this.timer = setTimeout(() => {
if (this.lineTab) { if (this.lineTab) {
const data = this.mpackets.find(t => t.class === this.lineTab) const data = this.mpackets.find(t => t.class === this.lineTab)
@@ -688,6 +694,15 @@ export default {
beforeUnmount () { beforeUnmount () {
clearTimeout(this.timer) clearTimeout(this.timer)
window.removeEventListener('resize', this.resize) window.removeEventListener('resize', this.resize)
let myChart = echarts.getInstanceByDom(document.getElementById('overviewLineChart'))
if (myChart) {
echarts.dispose(myChart)
}
this.myChart = null
// 检测时发现该方法占用较大内存,且未被释放
this.unitConvert = null
myChart = null
} }
} }
</script> </script>

View File

@@ -193,6 +193,8 @@ export default {
beforeUnmount () { beforeUnmount () {
clearTimeout(this.timer) clearTimeout(this.timer)
window.removeEventListener('resize', this.resize) window.removeEventListener('resize', this.resize)
this.myChart = null
this.myChart2 = null
} }
} }
</script> </script>

View File

@@ -1770,6 +1770,13 @@ export default {
}, },
async mounted () { async mounted () {
console.log('mounted start...') console.log('mounted start...')
this.list = null
this.tabList = null
this.allList = null
this.drillDownTableConfigs = null
this.curTable = null
this.commonColumnList = null
this.userId = localStorage.getItem(storageKey.userId) this.userId = localStorage.getItem(storageKey.userId)
this.drillDownTableConfigs = await combinDrilldownTableWithUserConfig() this.drillDownTableConfigs = await combinDrilldownTableWithUserConfig()
this.tableType = this.$route.params ? this.$route.params.typeName : 'networkOverview' this.tableType = this.$route.params ? this.$route.params.typeName : 'networkOverview'
@@ -1854,6 +1861,18 @@ export default {
}, },
setup (props) { setup (props) {
}, },
beforeUnmount () {
// 以下元素,检测到内存并未释放
this.list = null
this.tabList = null
this.allList = null
this.drillDownTableConfigs = null
this.curTable = null
this.commonColumnList = null
this.networkTable = null
this.tableData = null
this.tableDataBackup = null
},
unmounted () { unmounted () {
this.isNoData = false this.isNoData = false
} }

View File

@@ -154,6 +154,8 @@ export default {
beforeUnmount () { beforeUnmount () {
clearTimeout(this.timer) clearTimeout(this.timer)
window.removeEventListener('resize', this.resize) window.removeEventListener('resize', this.resize)
this.myChart = null
this.chartOption = null
} }
} }
</script> </script>

View File

@@ -331,6 +331,7 @@ export default {
beforeUnmount () { beforeUnmount () {
clearTimeout(this.timer) clearTimeout(this.timer)
window.removeEventListener('resize', this.resize) window.removeEventListener('resize', this.resize)
this.myChart = null
} }
} }
</script> </script>

View File

@@ -50,7 +50,9 @@ export default {
npmNetworkLastCycleData: [], npmNetworkLastCycleData: [],
npmNetworkData: [], npmNetworkData: [],
side: '', side: '',
chartData: {} chartData: {},
timer1: null,
timer2: null
} }
}, },
watch: { watch: {
@@ -179,7 +181,7 @@ export default {
if (timer) { if (timer) {
clearTimeout(timer) clearTimeout(timer)
} }
timer = setTimeout(() => { this.timer1 = setTimeout(() => {
this.npmNetworkQuantity(this.npmNetworkCycleData, this.npmNetworkLastCycleData, 0) this.npmNetworkQuantity(this.npmNetworkCycleData, this.npmNetworkLastCycleData, 0)
}, 300) }, 300)
}).catch((e) => { }).catch((e) => {
@@ -188,7 +190,7 @@ export default {
clearTimeout(timer) clearTimeout(timer)
} }
this.npmNetworkLastCycleData = [e] this.npmNetworkLastCycleData = [e]
timer = setTimeout(() => { this.timer2 = setTimeout(() => {
this.npmNetworkQuantity(this.npmNetworkCycleData, this.npmNetworkLastCycleData, 0) this.npmNetworkQuantity(this.npmNetworkCycleData, this.npmNetworkLastCycleData, 0)
}, 300) }, 300)
}).finally(() => { }).finally(() => {
@@ -276,6 +278,10 @@ export default {
this.chartData = _.cloneDeep(this.chart) this.chartData = _.cloneDeep(this.chart)
} }
this.npmNetworkCycleQuery() this.npmNetworkCycleQuery()
},
beforeUnmount () {
clearTimeout(this.timer1)
clearTimeout(this.timer2)
} }
} }
</script> </script>

View File

@@ -666,6 +666,7 @@ export default {
beforeUnmount () { beforeUnmount () {
clearTimeout(this.timer) clearTimeout(this.timer)
window.removeEventListener('resize', this.resize) window.removeEventListener('resize', this.resize)
this.myChart = null
} }
} }
</script> </script>