Skip to content

Commit

Permalink
platform pagesize (#936)
Browse files Browse the repository at this point in the history
  • Loading branch information
frostbyte73 authored Jan 6, 2025
1 parent 409558f commit 83e359f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
6 changes: 1 addition & 5 deletions utils/hwstats/cpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"github.com/frostbyte73/core"
"github.com/prometheus/procfs"
"go.uber.org/atomic"
"golang.org/x/sys/unix"

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

func (c *CPUStats) monitorProcesses() {
numCPU := c.platform.numCPU()
pageSize := unix.Getpagesize()
if pageSize == 0 {
pageSize = 4096
}
pageSize := getPageSize()

fs, err := procfs.NewFS(procfs.DefaultMountPoint)
if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions utils/hwstats/cpu_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"runtime"

"github.com/prometheus/procfs"
"golang.org/x/sys/unix"
)

func newPlatformCPUMonitor() (platformCPUMonitor, error) {
Expand All @@ -29,3 +30,7 @@ func newPlatformCPUMonitor() (platformCPUMonitor, error) {
func getHostCPUCount(fs procfs.FS) (float64, error) {
return float64(runtime.NumCPU()), nil
}

func getPageSize() int {
return unix.Getpagesize()
}
5 changes: 5 additions & 0 deletions utils/hwstats/cpu_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"time"

"github.com/prometheus/procfs"
"golang.org/x/sys/unix"

"github.com/livekit/protocol/logger"
)
Expand Down Expand Up @@ -270,3 +271,7 @@ func getHostCPUCount(fs procfs.FS) (float64, error) {
}
return float64(len(cpuInfo)), nil
}

func getPageSize() int {
return unix.Getpagesize()
}
4 changes: 4 additions & 0 deletions utils/hwstats/cpu_null.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,7 @@ func newPlatformCPUMonitor() (platformCPUMonitor, error) {
func getHostCPUCount(fs procfs.FS) (float64, error) {
return float64(runtime.NumCPU()), nil
}

func getPageSize() int {
return 4096
}

0 comments on commit 83e359f

Please sign in to comment.