Skip to content

Commit cded180

Browse files
committed
Total Processes in MiscStat Corrected
The `ProcsTotal` in the `MiscStat` structure was very inaccurate. It was reading a value which is the total number of kernel scheduling entities. This includes both processes and threads significantly overcounting. This instead uses an existing method already in common to count the number of processes via the /proc filesystem where any directory is a number. This should still be a single syscall to read that directory entry. This fixes #1606.
1 parent 6100124 commit cded180

File tree

1 file changed

+1
-9
lines changed

1 file changed

+1
-9
lines changed

load/load_linux.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func MiscWithContext(ctx context.Context) (*MiscStat, error) {
107107

108108
}
109109

110-
procsTotal, err := getProcsTotal(ctx)
110+
procsTotal, err := common.NumProcsWithContext(ctx)
111111
if err != nil {
112112
return ret, err
113113
}
@@ -116,14 +116,6 @@ func MiscWithContext(ctx context.Context) (*MiscStat, error) {
116116
return ret, nil
117117
}
118118

119-
func getProcsTotal(ctx context.Context) (int64, error) {
120-
values, err := readLoadAvgFromFile(ctx)
121-
if err != nil {
122-
return 0, err
123-
}
124-
return strconv.ParseInt(strings.Split(values[3], "/")[1], 10, 64)
125-
}
126-
127119
func readLoadAvgFromFile(ctx context.Context) ([]string, error) {
128120
loadavgFilename := common.HostProcWithContext(ctx, "loadavg")
129121
line, err := os.ReadFile(loadavgFilename)

0 commit comments

Comments
 (0)