Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ func GetRamUsage() {

// GetTopProcesses print out the top 5 process that are consuming most RAM
func GetTopProcesses() {
strOutput := ""

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there was no need to use an accumulator

processes, err := process.Processes()
if err != nil {
StandardPrinter(ErrorRedColor, "Could not retrieve running process list.")
Expand Down Expand Up @@ -86,15 +85,20 @@ func GetTopProcesses() {
return memoryPercentOfIthProcess > memoryPercentOfJthProcess
})

ResultPrinter("Top 5 processes by memory usage: \n", "")
for i := 0; i < 5; i++ {
memoryPercentOfIthProcess, err := processes[i].MemoryPercent()
if err != nil {
StandardPrinter(ErrorRedColor, "Process memory usage access denied.") //More descriptive error
panic(err)
}
strOutput += fmt.Sprintf("PID: %5d, memory %%: %2.1f\n", processes[i].Pid, memoryPercentOfIthProcess)
fmt.Printf("\t%d. %s %5d, %s %2.1f%%\n",
i+1,
fmt.Sprintf(BoldWhite, "PID:"),
processes[i].Pid,
fmt.Sprintf(BoldWhite, "memory:"),
memoryPercentOfIthProcess)
}
ResultPrinter("Top 5 processes by memory usage: \n", strOutput)
}

func GetDiskUsage() {
Expand Down