Skip to content
Snippets Groups Projects
Unverified Commit fb60fb39 authored by capossele's avatar capossele
Browse files

:construction: WIP

parent afb05103
No related branches found
No related tags found
No related merge requests found
......@@ -43,14 +43,10 @@ func configure(_ *node.Plugin) {
analysisOutboundBytes.Add(amountBytes)
}))
metrics.Events().CPUUsage.Attach(events.NewClosure(func(cpuPercent float64) {
cpuLock.Lock()
defer cpuLock.Unlock()
_cpuUsage = cpuPercent
cpuUsage.Store(cpuPercent)
}))
metrics.Events().MemUsage.Attach(events.NewClosure(func(memAllocBytes uint64) {
memUsageLock.Lock()
defer memUsageLock.Unlock()
_memUsageBytes = memAllocBytes
memUsageBytes.Store(memAllocBytes)
}))
metrics.Events().Synced.Attach(events.NewClosure(func(synced bool) {
syncLock.Lock()
......
......@@ -5,22 +5,18 @@ import (
"time"
"github.com/iotaledger/goshimmer/packages/metrics"
"github.com/iotaledger/hive.go/syncutils"
"github.com/shirou/gopsutil/cpu"
"go.uber.org/atomic"
)
var (
_cpuUsage float64
cpuLock syncutils.RWMutex
_memUsageBytes uint64
memUsageLock syncutils.RWMutex
cpuUsage atomic.Float64
memUsageBytes atomic.Uint64
)
// CpuUsage returns the current cpu usage
func CpuUsage() float64 {
cpuLock.RLock()
defer cpuLock.RUnlock()
return _cpuUsage
return cpuUsage.Load()
}
func measureCPUUsage() {
......@@ -42,7 +38,5 @@ func measureMemUsage() {
// MemUsage returns the current memory allocated as bytes
func MemUsage() uint64 {
memUsageLock.RLock()
defer memUsageLock.RUnlock()
return _memUsageBytes
return memUsageBytes.Load()
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment