main.go 460 B

12345678910111213141516171819202122232425262728293031323334
  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 {
  23. select {
  24. case <-ticker.C:
  25. percent := stat.CpuUsage()
  26. fmt.Println("cpu:", percent)
  27. }
  28. }
  29. }