You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
go-zero/example/stat/main.go

35 lines
437 B
Go

4 years ago
package main
import (
"fmt"
"runtime"
"time"
"zero/core/stat"
)
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()
for {
select {
case <-ticker.C:
percent := stat.CpuUsage()
fmt.Println("cpu:", percent)
}
}
}