main.go 439 B

12345678910111213141516171819202122232425262728293031
  1. package main
  2. import (
  3. "fmt"
  4. "runtime"
  5. "time"
  6. "github.com/tal-tech/go-zero/core/stat"
  7. )
  8. func main() {
  9. fmt.Println(runtime.NumCPU())
  10. for i := 0; i < runtime.NumCPU()+10; i++ {
  11. go func() {
  12. for {
  13. select {
  14. default:
  15. time.Sleep(time.Microsecond)
  16. }
  17. }
  18. }()
  19. }
  20. ticker := time.NewTicker(time.Second * 5)
  21. defer ticker.Stop()
  22. for range ticker.C {
  23. percent := stat.CpuUsage()
  24. fmt.Println("cpu:", percent)
  25. }
  26. }