This repository has been archived by the owner on Aug 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 449
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch to custom process info retrieval
* Switch from gopsutil to using 'ps' for process info retrieval. * Much faster now since we are getting all info in a batch. * Should hopefully fix the issue on OSX where process info retrieval was taking too long. * CPU percentage reporting should also be imporoved, since it is more realtime.
- Loading branch information
Showing
2 changed files
with
55 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package psutil | ||
|
||
import ( | ||
// "fmt" | ||
"os/exec" | ||
"strconv" | ||
"strings" | ||
) | ||
|
||
// Process represents each process. | ||
type Process struct { | ||
PID int | ||
Command string | ||
CPU float64 | ||
Mem float64 | ||
} | ||
|
||
func Processes() []Process { | ||
output, _ := exec.Command("ps", "-acxo", "pid,comm,pcpu,pmem").Output() | ||
strOutput := strings.TrimSpace(string(output)) | ||
processes := []Process{} | ||
for _, line := range strings.Split(strOutput, "\n")[1:] { | ||
split := strings.Fields(line) | ||
// fmt.Println(split) | ||
pid, _ := strconv.Atoi(split[0]) | ||
cpu, _ := strconv.ParseFloat(split[2], 64) | ||
mem, _ := strconv.ParseFloat(split[3], 64) | ||
process := Process{ | ||
PID: pid, | ||
Command: split[1], | ||
CPU: cpu, | ||
Mem: mem, | ||
} | ||
processes = append(processes, process) | ||
} | ||
return processes | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters