2024-07-18 06:47:41 +00:00
|
|
|
package land
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"sync/atomic"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
type PerformanceAnalyzer struct {
|
|
|
|
tickCount int64
|
|
|
|
drawCount int64
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *PerformanceAnalyzer) Tick() {
|
|
|
|
atomic.AddInt64(&p.tickCount, 1)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *PerformanceAnalyzer) Draw() {
|
|
|
|
atomic.AddInt64(&p.drawCount, 1)
|
|
|
|
}
|
|
|
|
|
2024-07-18 09:21:25 +00:00
|
|
|
func (p *PerformanceAnalyzer) RunResetter(duration time.Duration) {
|
2024-07-18 06:47:41 +00:00
|
|
|
ticker := time.NewTicker(duration)
|
|
|
|
defer ticker.Stop()
|
|
|
|
for {
|
|
|
|
<-ticker.C
|
|
|
|
log.Printf("TPS: %d FPS: %d\n", atomic.LoadInt64(&p.tickCount), atomic.LoadInt64(&p.drawCount))
|
|
|
|
atomic.StoreInt64(&p.tickCount, 0)
|
|
|
|
atomic.StoreInt64(&p.drawCount, 0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *PerformanceAnalyzer) GetTPS() int64 {
|
|
|
|
return atomic.LoadInt64(&p.tickCount)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *PerformanceAnalyzer) GetFPS() int64 {
|
|
|
|
return atomic.LoadInt64(&p.drawCount)
|
|
|
|
}
|