2014-04-20 18:34:28 +00:00
|
|
|
package fs
|
|
|
|
|
|
|
|
import (
|
2014-04-20 19:02:39 +00:00
|
|
|
"errors"
|
2014-04-20 18:34:28 +00:00
|
|
|
"fmt"
|
2014-04-24 22:59:37 +00:00
|
|
|
"io/ioutil"
|
|
|
|
"path/filepath"
|
2014-04-20 18:34:28 +00:00
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2014-04-21 01:18:17 +00:00
|
|
|
var (
|
|
|
|
ErrNotSupportStat = errors.New("stats are not supported for subsystem")
|
|
|
|
ErrNotValidFormat = errors.New("line is not a valid key value format")
|
|
|
|
)
|
2014-04-20 19:02:39 +00:00
|
|
|
|
2014-04-20 18:34:28 +00:00
|
|
|
// Parses a cgroup param and returns as name, value
|
|
|
|
// i.e. "io_service_bytes 1234" will return as io_service_bytes, 1234
|
2014-05-28 00:01:08 +00:00
|
|
|
func getCgroupParamKeyValue(t string) (string, uint64, error) {
|
2014-04-20 18:34:28 +00:00
|
|
|
parts := strings.Fields(t)
|
|
|
|
switch len(parts) {
|
|
|
|
case 2:
|
2014-05-28 00:01:08 +00:00
|
|
|
value, err := strconv.ParseUint(parts[1], 10, 64)
|
2014-04-20 18:34:28 +00:00
|
|
|
if err != nil {
|
2014-06-02 06:56:15 +00:00
|
|
|
return "", 0, fmt.Errorf("Unable to convert param value to uint64: %s", err)
|
2014-04-20 18:34:28 +00:00
|
|
|
}
|
2014-04-20 19:02:39 +00:00
|
|
|
return parts[0], value, nil
|
2014-04-20 18:34:28 +00:00
|
|
|
default:
|
2014-05-22 20:50:51 +00:00
|
|
|
return "", 0, ErrNotValidFormat
|
2014-04-20 18:34:28 +00:00
|
|
|
}
|
|
|
|
}
|
2014-04-24 22:59:37 +00:00
|
|
|
|
2014-05-22 20:50:51 +00:00
|
|
|
// Gets a single int64 value from the specified cgroup file.
|
2014-05-28 00:01:08 +00:00
|
|
|
func getCgroupParamInt(cgroupPath, cgroupFile string) (uint64, error) {
|
2014-04-24 22:59:37 +00:00
|
|
|
contents, err := ioutil.ReadFile(filepath.Join(cgroupPath, cgroupFile))
|
|
|
|
if err != nil {
|
2014-05-28 00:01:08 +00:00
|
|
|
return 0, err
|
2014-04-24 22:59:37 +00:00
|
|
|
}
|
2014-05-28 00:01:08 +00:00
|
|
|
return strconv.ParseUint(strings.TrimSpace(string(contents)), 10, 64)
|
2014-04-24 22:59:37 +00:00
|
|
|
}
|