Skip to content

Commit 0de49ad

Browse files
committed
bonsai
1 parent 16485e0 commit 0de49ad

File tree

2 files changed

+43
-42
lines changed

2 files changed

+43
-42
lines changed

grouper/cgroup/cgroup.go

Lines changed: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ var DefaultSubsystems = []string{
3838
type Cgroup struct {
3939
fsPath string
4040
subsystems []string
41-
nRe *regexp.Regexp
42-
eRe *regexp.Regexp
41+
nRe *regexp.Regexp // normalize regexp
42+
eRe *regexp.Regexp // exclude regexp
4343
}
4444

4545
func (c *Cgroup) Name() string {
@@ -106,48 +106,49 @@ func (c *Cgroup) Collect(gprocs *grouped_proc.GroupedProcs, enabled map[metric.M
106106
cPath = matches[1]
107107
}
108108
}
109-
if cPath != "" {
110-
f, err := os.Open(filepath.Clean(filepath.Join(path, "cgroup.procs")))
111-
if err != nil {
109+
if cPath == "" {
110+
return nil
111+
}
112+
f, err := os.Open(filepath.Clean(filepath.Join(path, "cgroup.procs")))
113+
if err != nil {
114+
_ = f.Close()
115+
return nil
116+
}
117+
var (
118+
gproc *grouped_proc.GroupedProc
119+
ok bool
120+
)
121+
gproc, ok = gprocs.Load(cPath)
122+
if !ok {
123+
gproc = grouped_proc.NewGroupedProc(enabled)
124+
gprocs.Store(cPath, gproc)
125+
}
126+
gproc.Exists = true
127+
reader := bufio.NewReaderSize(f, 1028)
128+
for {
129+
line, _, err := reader.ReadLine()
130+
if err == io.EOF {
131+
break
132+
} else if err != nil {
112133
_ = f.Close()
113-
return nil
134+
return err
114135
}
115-
var (
116-
gproc *grouped_proc.GroupedProc
117-
ok bool
118-
)
119-
gproc, ok = gprocs.Load(cPath)
120-
if !ok {
121-
gproc = grouped_proc.NewGroupedProc(enabled)
122-
gprocs.Store(cPath, gproc)
136+
pid, err := strconv.Atoi(string(line))
137+
if err != nil {
138+
_ = f.Close()
139+
return err
123140
}
124-
gproc.Exists = true
125-
reader := bufio.NewReaderSize(f, 1028)
126-
for {
127-
line, _, err := reader.ReadLine()
128-
if err == io.EOF {
129-
break
130-
} else if err != nil {
131-
_ = f.Close()
132-
return err
133-
}
134-
pid, err := strconv.Atoi(string(line))
135-
if err != nil {
136-
_ = f.Close()
137-
return err
138-
}
139-
err = sem.Acquire(ctx, gproc.RequiredWeight)
140-
if err != nil {
141-
_ = f.Close()
142-
return err
143-
}
144-
wg.Add(1)
145-
go func(wg *sync.WaitGroup, pid int, gproc *grouped_proc.GroupedProc) {
146-
_ = gproc.AppendProcAndCollect(pid)
147-
sem.Release(gproc.RequiredWeight)
148-
wg.Done()
149-
}(wg, pid, gproc)
141+
err = sem.Acquire(ctx, gproc.RequiredWeight)
142+
if err != nil {
143+
_ = f.Close()
144+
return err
150145
}
146+
wg.Add(1)
147+
go func(wg *sync.WaitGroup, pid int, gproc *grouped_proc.GroupedProc) {
148+
_ = gproc.AppendProcAndCollect(pid)
149+
sem.Release(gproc.RequiredWeight)
150+
wg.Done()
151+
}(wg, pid, gproc)
151152
}
152153
return nil
153154
})

grouper/proc_status_name/proc_status_name.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import (
1414
)
1515

1616
type ProcStatusName struct {
17-
nRe *regexp.Regexp
18-
eRe *regexp.Regexp
17+
nRe *regexp.Regexp // normalize regexp
18+
eRe *regexp.Regexp // exclude regexp
1919
procMountPoint string
2020
}
2121

0 commit comments

Comments
 (0)