首先是在systemtap脚本中定义能够抓取golang堆栈的功能函数:
```function print_time_now() {
ms = gettimeofday_us()
sec = gettimeofday_s()
printf(“%s %d\(us\)\n”,ctime(sec),ms-sec*1000000 )
}
function print_x8664_gostack(){
goBaseName = “runtime.go exit”
rip = u_register(“rip”)
rbp_itr = u_register(“rbp”)
funcName = usymname(rip)
fileLine = usymline(rip)
printf(“%p: %s\n”,rip,funcName)
while(funcName != goBaseName && rbp_itr !=0){
funcName = usymname(user_long(rbp_itr+8))
fileLine = usymline(user_long(rbp_itr+8))
printf(“%p: %s \n”,user_long(rbp_itr+8),funcName)
rbp_itr = user_long(rbp_itr)
}
printf(“……….……..\n”)
}
function dumpProccessInfo(){
printf(“pid:%d, tid:%d, pid name:%s, ppid:%d, ppid name:%s, func:%s, cmd:%s \n”,pid(),tid(),pid2execname(pid()),ppid(), pid2execname(ppid()), ppfunc(), cmdline_str())
)
}```
/*实际使用上述函数的例子*/
’’’
网友评论