Skip to content

Commit 83e359f

Browse files
authored
platform pagesize (#936)
1 parent 409558f commit 83e359f

File tree

4 files changed

+15
-5
lines changed

4 files changed

+15
-5
lines changed

utils/hwstats/cpu.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"github.com/frostbyte73/core"
2121
"github.com/prometheus/procfs"
2222
"go.uber.org/atomic"
23-
"golang.org/x/sys/unix"
2423

2524
"github.com/livekit/protocol/logger"
2625
)
@@ -129,10 +128,7 @@ func (c *CPUStats) monitorCPULoad() {
129128

130129
func (c *CPUStats) monitorProcesses() {
131130
numCPU := c.platform.numCPU()
132-
pageSize := unix.Getpagesize()
133-
if pageSize == 0 {
134-
pageSize = 4096
135-
}
131+
pageSize := getPageSize()
136132

137133
fs, err := procfs.NewFS(procfs.DefaultMountPoint)
138134
if err != nil {

utils/hwstats/cpu_darwin.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"runtime"
2121

2222
"github.com/prometheus/procfs"
23+
"golang.org/x/sys/unix"
2324
)
2425

2526
func newPlatformCPUMonitor() (platformCPUMonitor, error) {
@@ -29,3 +30,7 @@ func newPlatformCPUMonitor() (platformCPUMonitor, error) {
2930
func getHostCPUCount(fs procfs.FS) (float64, error) {
3031
return float64(runtime.NumCPU()), nil
3132
}
33+
34+
func getPageSize() int {
35+
return unix.Getpagesize()
36+
}

utils/hwstats/cpu_linux.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"time"
2727

2828
"github.com/prometheus/procfs"
29+
"golang.org/x/sys/unix"
2930

3031
"github.com/livekit/protocol/logger"
3132
)
@@ -270,3 +271,7 @@ func getHostCPUCount(fs procfs.FS) (float64, error) {
270271
}
271272
return float64(len(cpuInfo)), nil
272273
}
274+
275+
func getPageSize() int {
276+
return unix.Getpagesize()
277+
}

utils/hwstats/cpu_null.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,7 @@ func newPlatformCPUMonitor() (platformCPUMonitor, error) {
4242
func getHostCPUCount(fs procfs.FS) (float64, error) {
4343
return float64(runtime.NumCPU()), nil
4444
}
45+
46+
func getPageSize() int {
47+
return 4096
48+
}

0 commit comments

Comments
 (0)