ran gofmt

This commit is contained in:
Nicholas Orlowsky 2023-03-31 00:52:14 -05:00
parent 221e85f6f2
commit 3ae35a045d
No known key found for this signature in database
GPG key ID: 58832FD3AC16C706

View file

@ -43,16 +43,16 @@ func NumCPU() int {
return cpus
}
cgroupVersion := getCgroupVersion();
cpuQuota := -1;
cpuPeriod := -1;
cgroupVersion := getCgroupVersion()
cpuQuota := -1
cpuPeriod := -1
if cgroupVersion == 1 {
if cgroupVersion == 1 {
cpuQuota := readCgroupFileToInt64(cgroupPath, "cpu.cfs_quota_us")
cpuPeriod := readCgroupFileToInt64(cgroupPath, "cpu.cfs_period_us")
} else if cgroupVersion == 2 {
cpuQuota, cpuPeriod := readCgroup2FileToInt64Tuple(cgroupPath, "cpu.max")
}
}
if cpuQuota == -1 || cpuPeriod == -1 {
return cpus
@ -64,9 +64,9 @@ func NumCPU() int {
func getCgroupVersion() int64 {
// /sys/fs/cgroup/cgroup.controllers will not exist with cgroupsv1
if _, err := os.Stat("/sys/fs/cgroup/cgroup.controllers"); err == nil {
return 2;
return 2
} else {
return 1;
return 1
}
}
@ -74,36 +74,36 @@ func readCgroup2FileToInt64Tuple(cgroupPath, cgroupFile string) (int64, int64) {
contents, err := os.ReadFile(filepath.Join(cgroupPath, cgroupFile))
if err != nil {
return -1, -1;
return -1, -1
}
// file contents looks like: $MAX $PERIOD
// $MAX can have value "max" indicating no limit
// it is possible for $PERIOD to be unset
values := strings.Fields(string(contents));
values := strings.Fields(string(contents))
if values[0] == "max" {
return -1, -1;
return -1, -1
}
cpuQuota, err := strconv.ParseInt(values[0], 10, 64);
cpuQuota, err := strconv.ParseInt(values[0], 10, 64)
if err != nil {
return -1, -1;
if err != nil {
return -1, -1
}
if len(values) == 1 {
return cpuQuota, 1;
return cpuQuota, 1
}
cpuPeriod, err := strconv.ParseInt(values[1], 10, 64);
cpuPeriod, err := strconv.ParseInt(values[1], 10, 64)
if err != nil {
return -1, -1;
return -1, -1
}
return cpuQuota, cpuPeriod;
return cpuQuota, cpuPeriod
}
func readCgroupFileToInt64(cgroupPath, cgroupFile string) int64 {