Skip to content

Commit

Permalink
fix: don't include SystemDriven on ios
Browse files Browse the repository at this point in the history
  • Loading branch information
richard-ramos committed Apr 1, 2022
1 parent 60d0a53 commit 9800419
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 40 deletions.
40 changes: 0 additions & 40 deletions watchdog.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"sync"
"time"

"github.com/elastic/gosigar"
"github.com/raulk/clock"
)

Expand Down Expand Up @@ -103,7 +102,6 @@ var (
// See: https://github.com/golang/go/issues/19812
// See: https://github.com/prometheus/client_golang/issues/403
memstatsFn = runtime.ReadMemStats
sysmemFn = (*gosigar.Mem).Get
)

type notifeeEntry struct {
Expand Down Expand Up @@ -248,44 +246,6 @@ func HeapDriven(limit uint64, minGOGC int, policyCtor PolicyCtor) (err error, st
return nil, stop
}

// SystemDriven starts a singleton system-driven watchdog.
//
// The system-driven watchdog keeps a threshold, above which GC will be forced.
// The watchdog polls the system utilization at the specified frequency. When
// the actual utilization exceeds the threshold, a GC is forced.
//
// This threshold is calculated by querying the policy every time that GC runs,
// either triggered by the runtime, or forced by us.
func SystemDriven(limit uint64, frequency time.Duration, policyCtor PolicyCtor) (err error, stopFn func()) {
if limit == 0 {
var sysmem gosigar.Mem
if err := sysmemFn(&sysmem); err != nil {
return fmt.Errorf("failed to get system memory stats: %w", err), nil
}
limit = sysmem.Total
}

policy, err := policyCtor(limit)
if err != nil {
return fmt.Errorf("failed to construct policy with limit %d: %w", limit, err), nil
}

if err := start(UtilizationSystem); err != nil {
return err, nil
}

_watchdog.wg.Add(1)
var sysmem gosigar.Mem
go pollingWatchdog(policy, frequency, limit, func() (uint64, error) {
if err := sysmemFn(&sysmem); err != nil {
return 0, err
}
return sysmem.ActualUsed, nil
})

return nil, stop
}

// pollingWatchdog starts a polling watchdog with the provided policy, using
// the supplied polling frequency. On every tick, it calls usageFn and, if the
// usage is greater or equal to the threshold at the time, it forces GC.
Expand Down
53 changes: 53 additions & 0 deletions watchdog_systemdriven.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//go:build !ios
// +build !ios

package watchdog

import (
"fmt"
"time"

"github.com/elastic/gosigar"
)

var (
sysmemFn = (*gosigar.Mem).Get
)

// SystemDriven starts a singleton system-driven watchdog.
//
// The system-driven watchdog keeps a threshold, above which GC will be forced.
// The watchdog polls the system utilization at the specified frequency. When
// the actual utilization exceeds the threshold, a GC is forced.
//
// This threshold is calculated by querying the policy every time that GC runs,
// either triggered by the runtime, or forced by us.
func SystemDriven(limit uint64, frequency time.Duration, policyCtor PolicyCtor) (err error, stopFn func()) {
if limit == 0 {
var sysmem gosigar.Mem
if err := sysmemFn(&sysmem); err != nil {
return fmt.Errorf("failed to get system memory stats: %w", err), nil
}
limit = sysmem.Total
}

policy, err := policyCtor(limit)
if err != nil {
return fmt.Errorf("failed to construct policy with limit %d: %w", limit, err), nil
}

if err := start(UtilizationSystem); err != nil {
return err, nil
}

_watchdog.wg.Add(1)
var sysmem gosigar.Mem
go pollingWatchdog(policy, frequency, limit, func() (uint64, error) {
if err := sysmemFn(&sysmem); err != nil {
return 0, err
}
return sysmem.ActualUsed, nil
})

return nil, stop
}

0 comments on commit 9800419

Please sign in to comment.