文章内容基本上是 https://blog.pixielabs.ai/ebpf-function-tracing/post/ 内容的复刻,对细节进行了补充以及错误修正。这里不再介绍ebpf的概念,网上应该能搜到很多相关的资料,最后使用的ebpf前端工具是bcc:
https://github.com/iovisor/bcc
golang程序实现与分析
先用golang实现一个简单的HTTP Server,代码如下:
package main
import (
"fmt"
"math/rand"
"net/http"
)
//go:noinline
func computeE(iterations int64) float64 {
out := float64(iterations) + 1.2
return out
}
func main() {
http.HandleFunc("/e", func(w http.ResponseWriter, r *http.Request) {
// Parse iters argument from get request, use default if not available.
// ... removed for brevity ...
aa := rand.Intn(5)
arg := int64(aa)
w.Write([]byte(fmt.Sprintf("e = %0.4f\n", computeE(arg))))
})
http.ListenAndServe("0.0.0.0:5555", nil)
// Start server...
}
&nbs