go-zero/example/stat/main.go

32 lines
439 B
Go
Raw Normal View History

2020-07-26 17:09:05 +08:00
package main
import (
"fmt"
"runtime"
"time"
2020-08-08 16:40:10 +08:00
"github.com/tal-tech/go-zero/core/stat"
2020-07-26 17:09:05 +08:00
)
func main() {
fmt.Println(runtime.NumCPU())
for i := 0; i < runtime.NumCPU()+10; i++ {
go func() {
for {
select {
default:
time.Sleep(time.Microsecond)
}
}
}()
}
ticker := time.NewTicker(time.Second * 5)
defer ticker.Stop()
2020-10-16 10:50:43 +08:00
for range ticker.C {
percent := stat.CpuUsage()
fmt.Println("cpu:", percent)
2020-07-26 17:09:05 +08:00
}
}