Last active
September 22, 2019 06:48
-
-
Save onemouth/b7b0a40de9092a21cb8fa854c8e8d089 to your computer and use it in GitHub Desktop.
get mcount from go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"C" | |
"fmt" | |
"runtime" | |
"runtime/debug" | |
"time" | |
"os/exec" | |
_ "unsafe" | |
) | |
//go:linkname mcount runtime.mcount | |
func mcount() int32 | |
func getGOMAXPROCS() int { | |
return runtime.GOMAXPROCS(0) | |
} | |
func main() { | |
//runtime.GOMAXPROCS(20) | |
fmt.Printf("GOMAXPROCS is %d\n", getGOMAXPROCS()) | |
debug.SetMaxThreads(50) | |
go func() { | |
for { | |
cnt := mcount() | |
fmt.Println(cnt) | |
time.Sleep(time.Second) | |
} | |
}() | |
for i := 0; i < 100; i++ { | |
go func() { | |
cmd := exec.Command("sleep", "600") | |
if err := cmd.Run(); err != nil { | |
fmt.Println(err) | |
} | |
}() | |
time.Sleep(time.Second) | |
} | |
c := make(chan int) | |
<-c | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment