Skip to content

Commit

Permalink
libct/cg/fs2/hugetlb: use fscommon.GetValueByKey
Browse files Browse the repository at this point in the history
This makes the code simpler and more future-proof, in case
any more values will appear in hugetlb.*.events.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
  • Loading branch information
kolyshkin committed Feb 19, 2021
1 parent cdf1723 commit 089d7b4
Showing 1 changed file with 1 addition and 6 deletions.
7 changes: 1 addition & 6 deletions libcontainer/cgroups/fs2/hugetlb.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package fs2

import (
"strconv"
"strings"

"github.com/pkg/errors"

Expand Down Expand Up @@ -45,14 +44,10 @@ func statHugeTlb(dirPath string, stats *cgroups.Stats) error {
hugetlbStats.Usage = value

fileName := "hugetlb." + pagesize + ".events"
contents, err := fscommon.ReadFile(dirPath, fileName)
value, err = fscommon.GetValueByKey(dirPath, fileName, "max")
if err != nil {
return errors.Wrap(err, "failed to read stats")
}
_, value, err = fscommon.ParseKeyValue(strings.TrimSuffix(contents, "\n"))
if err != nil {
return errors.Wrap(err, "failed to parse "+fileName)
}
hugetlbStats.Failcnt = value

stats.HugetlbStats[pagesize] = hugetlbStats
Expand Down

0 comments on commit 089d7b4

Please sign in to comment.