Skip to content

Commit

Permalink
Total Processes in MiscStat Corrected
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
eric1234 committed Mar 21, 2024
1 parent 6100124 commit cded180
Showing 1 changed file with 1 addition and 9 deletions.
10 changes: 1 addition & 9 deletions load/load_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func MiscWithContext(ctx context.Context) (*MiscStat, error) {

}

procsTotal, err := getProcsTotal(ctx)
procsTotal, err := common.NumProcsWithContext(ctx)
if err != nil {
return ret, err
}
Expand All @@ -116,14 +116,6 @@ func MiscWithContext(ctx context.Context) (*MiscStat, error) {
return ret, nil
}

func getProcsTotal(ctx context.Context) (int64, error) {
values, err := readLoadAvgFromFile(ctx)
if err != nil {
return 0, err
}
return strconv.ParseInt(strings.Split(values[3], "/")[1], 10, 64)
}

func readLoadAvgFromFile(ctx context.Context) ([]string, error) {
loadavgFilename := common.HostProcWithContext(ctx, "loadavg")
line, err := os.ReadFile(loadavgFilename)
Expand Down

0 comments on commit cded180

Please sign in to comment.