LingxinMeng hace 1 año
padre
commit
43847c5278
Se han modificado 1 ficheros con 14 adiciones y 5 borrados
  1. 14 5
      common/util/u_resource.go

+ 14 - 5
common/util/u_resource.go

@@ -43,18 +43,15 @@ func GetTop10CpuAndMem() ([]ProcessInfo, []ProcessInfo) {
 	sortedPidsMem := make([]int32, 0, len(cpuPercent))
 	for pid := range cpuPercent {
 		sortedPidsCpu = append(sortedPidsCpu, pid)
-		sortedPidsMem = append(sortedPidsMem, pid)
 	}
+
 	sort.Slice(sortedPidsCpu, func(i, j int) bool {
 		return cpuPercent[sortedPidsCpu[i]] > cpuPercent[sortedPidsCpu[j]]
 	})
-	sort.Slice(sortedPidsMem, func(i, j int) bool {
-		return memPercent[sortedPidsCpu[i]] > memPercent[sortedPidsCpu[j]]
-	})
 
 	// 输出前10个CPU占用率最高的进程名称
 	var top10Cpu []ProcessInfo
-	var top10Mem []ProcessInfo
+
 	for i, pid := range sortedPidsCpu {
 		if i >= 10 {
 			break
@@ -71,6 +68,18 @@ func GetTop10CpuAndMem() ([]ProcessInfo, []ProcessInfo) {
 			MemUsage: memPercent[pid],
 		})
 	}
+
+	// --------------------- 内存
+	var top10Mem []ProcessInfo
+
+	for pid := range memPercent {
+		sortedPidsMem = append(sortedPidsMem, pid)
+	}
+
+	sort.Slice(sortedPidsMem, func(i, j int) bool {
+		return memPercent[sortedPidsMem[i]] > memPercent[sortedPidsMem[j]]
+	})
+
 	for i, pid := range sortedPidsMem {
 		if i >= 10 {
 			break