1 Star 1 Fork 3

menuiis/gkit

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
thread_trigger.go 971 Bytes
一键复制 编辑 原始数据 按行查看 历史
menuis 提交于 2024-04-22 10:18 +08:00 . init
package main
/*
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
void output(char *str) {
sleep(10000);
printf("%s\n", str);
}
*/
import "C"
import (
"fmt"
"net/http"
"time"
"unsafe"
"gitee.com/menciis/gkit/watching"
_ "net/http/pprof"
)
func init() {
go func() {
w := watching.NewWatching(
watching.WithCollectInterval("2s"),
watching.WithCoolDown("5s"),
watching.WithDumpPath("/tmp"),
watching.WithTextDump(),
watching.WithThreadDump(10, 25, 100),
)
w.EnableThreadDump().Start()
time.Sleep(time.Hour)
}()
}
func leak(wr http.ResponseWriter, req *http.Request) {
go func() {
for i := 0; i < 1000; i++ {
go func() {
str := "hello cgo"
// change to char*
cstr := C.CString(str)
C.output(cstr)
C.free(unsafe.Pointer(cstr))
}()
}
}()
}
func main() {
http.HandleFunc("/leak", leak)
err := http.ListenAndServe(":10003", nil)
if err != nil {
fmt.Println(err)
return
}
select {}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/menciis/gkit.git
git@gitee.com:menciis/gkit.git
menciis
gkit
gkit
d3f65ed26d21

搜索帮助