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