procstat performance enhancement (#7686)
up to 40/120x better performance on FullPattern/Pattern functions
This commit is contained in:
parent
94fa7067ad
commit
0e6566a20f
|
|
@ -64,7 +64,7 @@ func (pg *NativeFinder) FullPattern(pattern string) ([]PID, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return pids, err
|
return pids, err
|
||||||
}
|
}
|
||||||
procs, err := process.Processes()
|
procs, err := pg.FastProcessList()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return pids, err
|
return pids, err
|
||||||
}
|
}
|
||||||
|
|
@ -81,3 +81,16 @@ func (pg *NativeFinder) FullPattern(pattern string) ([]PID, error) {
|
||||||
}
|
}
|
||||||
return pids, err
|
return pids, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (pg *NativeFinder) FastProcessList() ([]*process.Process, error) {
|
||||||
|
pids, err := process.Pids()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
result := make([]*process.Process, len(pids))
|
||||||
|
for i, pid := range pids {
|
||||||
|
result[i] = &process.Process{Pid: pid}
|
||||||
|
}
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,6 @@ package procstat
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"regexp"
|
"regexp"
|
||||||
|
|
||||||
"github.com/shirou/gopsutil/process"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
//Pattern matches on the process name
|
//Pattern matches on the process name
|
||||||
|
|
@ -15,7 +13,7 @@ func (pg *NativeFinder) Pattern(pattern string) ([]PID, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return pids, err
|
return pids, err
|
||||||
}
|
}
|
||||||
procs, err := process.Processes()
|
procs, err := pg.FastProcessList()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return pids, err
|
return pids, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,6 @@ package procstat
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"regexp"
|
"regexp"
|
||||||
|
|
||||||
"github.com/shirou/gopsutil/process"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Pattern matches on the process name
|
// Pattern matches on the process name
|
||||||
|
|
@ -13,7 +11,7 @@ func (pg *NativeFinder) Pattern(pattern string) ([]PID, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return pids, err
|
return pids, err
|
||||||
}
|
}
|
||||||
procs, err := process.Processes()
|
procs, err := pg.FastProcessList()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return pids, err
|
return pids, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue