Skip to content

Commit

Permalink
Merge pull request linuxkerneltravel#319 from WYuei/develop
Browse files Browse the repository at this point in the history
cilium_ebpf_probe
  • Loading branch information
LinkinPF authored Aug 24, 2022
2 parents 3e6d954 + 00df66e commit 2b0b961
Show file tree
Hide file tree
Showing 10 changed files with 277 additions and 96 deletions.
37 changes: 37 additions & 0 deletions eBPF_Supermarket/cilium_ebpf_probe/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,45 @@ httpserver 1/1 Running 0 3h46m
want (unsafe.Pointer, _Ctype_int, *_Ctype_char, *_Ctype_struct_bpf_insn, _Ctype_int, *_Ctype_char, _Ctype_uint, _Ctype_int, *_Ctype_char, _Ctype_uint, *_Ctype_char, _Ctype_int)

```
为了进行可视化展示,需要通过以下流程对prometheus组件进行部署。

**1.Docker启动普罗米修斯**

```bash
$ docker run --name prometheus -v /etc/localtime:/etc/localtime -d -p 9090:9090 prom/prometheus:latest
```

这里默认 Prometheus 开放 9090 端口,我们使用最新版官方镜像,当前最新版本为 v2.11.1,启动完成后,浏览器访问 http://IP:9090 即可看到默认 UI 页面。

**2.Docker启动pushgateway**

```bash
$ docker run --name pushgateway -v /etc/localtime:/etc/localtime -d -p 9091:9091 prom/pushgateway
```

**3.将pushgateway和prometheus进行关联**

Prometheus 默认配置文件 prometheus.yml 在[容器](https://cloud.tencent.com/product/tke?from=10680)内路径为 /etc/prometheus/prometheus.yml添加prometheus.yml配置如下

```bash
...
- job_name: 'pushgateway'
honor_labels: true
static_configs:
- targets: ['10.10.103.122:9091'] #pushgateway的端口
labels:
instance: pushgateway
```

完成后重启prometheus`docker restart prometheus`

**4.Docker启动Grafana**

```bash
$ docker run -d -p 3000:3000 --name grafana -v /etc/localtime:/etc/localtime grafana/grafana-enterprise:8.1.3
```

接下来打开 http://IP:3000 即可查看Grafana界面。并将对应的传送API接口修改,即可成功运行本探针程序。

---

Expand Down
41 changes: 25 additions & 16 deletions eBPF_Supermarket/cilium_ebpf_probe/cluster_utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func GetAllProcessFromContainer(containerStatus v1.ContainerStatus, nodeContaine
}

// GetAllPodProcess get all processes from a pod
func GetAllPodProcess(clientset *kubernetes.Clientset, nodeName string, namespace string, podName string, cs []v1.ContainerStatus) (map[v1.ContainerStatus][]*process.Process, error) {
func GetAllPodProcess(clientset *kubernetes.Clientset, nodeName string, namespace string, podName string, cs []v1.ContainerStatus, img string) (map[v1.ContainerStatus][]*process.Process, error) {
// 1. Get all containers
containerStatuses := cs

Expand All @@ -132,19 +132,24 @@ func GetAllPodProcess(clientset *kubernetes.Clientset, nodeName string, namespac
}

// 2. traverse containerStatuses and get processes

for _, containerStatus := range containerStatuses {
processes, err := GetAllProcessFromContainer(containerStatus, nodeContainerRuntime)
if err != nil {
return nil, err

if containerStatus.Image == img {
processes, err := GetAllProcessFromContainer(containerStatus, nodeContainerRuntime)
fmt.Println("get specific docker of image ", img)
if err != nil {
return nil, err
}
res[containerStatus] = processes
}
res[containerStatus] = processes
}

return res, nil
}

//GetPodELFPath get the path of the elf path to attach uprobe on
func GetPodELFPath(clientset *kubernetes.Clientset, nodeName string, namespace string, podName string, cs []v1.ContainerStatus) (map[v1.ContainerStatus]string, error) {
func GetPodELFPath(clientset *kubernetes.Clientset, nodeName string, namespace string, podName string, cs []v1.ContainerStatus, img string) (map[v1.ContainerStatus]string, error) {
// 1. Get all containers

containerStatuses := cs
Expand All @@ -156,18 +161,22 @@ func GetPodELFPath(clientset *kubernetes.Clientset, nodeName string, namespace s

// 2. traverse containerStatuses and get processes
for _, containerStatus := range containerStatuses {
containerID := containerStatus.ContainerID
if strings.Contains(containerID, nodeContainerRuntime+"://") {
containerID = strings.Replace(containerID, nodeContainerRuntime+"://", "", -1)
} else { // double check
return nil, fmt.Errorf("unsupported ContainerID '%s'\n", containerID)
if containerStatus.Image == img {
fmt.Println("get specific docker of image ", img)
containerID := containerStatus.ContainerID
if strings.Contains(containerID, nodeContainerRuntime+"://") {
containerID = strings.Replace(containerID, nodeContainerRuntime+"://", "", -1)
} else { // double check
return nil, fmt.Errorf("unsupported ContainerID '%s'\n", containerID)
}

path, err := findELFPath(containerID, nodeContainerRuntime)
if err != nil {
return nil, err
}
res[containerStatus] = path
}

path, err := findELFPath(containerID, nodeContainerRuntime)
if err != nil {
return nil, err
}
res[containerStatus] = path
}
return res, nil
}
11 changes: 9 additions & 2 deletions eBPF_Supermarket/cilium_ebpf_probe/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ require (
github.com/moby/term v0.0.0-20210619224110-3f7ff695adc6 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
Expand All @@ -57,14 +58,20 @@ require (
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.10.0 // indirect
github.com/prometheus/procfs v0.1.3 // indirect
github.com/richardlehane/mscfb v1.0.4 // indirect
github.com/richardlehane/msoleps v1.0.3 // indirect
github.com/sirupsen/logrus v1.9.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/tklauser/go-sysconf v0.3.10 // indirect
github.com/tklauser/numcpus v0.4.0 // indirect
github.com/xuri/efp v0.0.0-20220603152613-6918739fd470 // indirect
github.com/xuri/excelize/v2 v2.6.1 // indirect
github.com/xuri/nfp v0.0.0-20220409054826-5e722a1d9e22 // indirect
github.com/yusufpapurcu/wmi v1.2.2 // indirect
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd // indirect
golang.org/x/crypto v0.0.0-20220817201139-bc19a97f63c8 // indirect
golang.org/x/net v0.0.0-20220812174116-3211cb980234 // indirect
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 // indirect
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10 // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect
Expand Down
21 changes: 21 additions & 0 deletions eBPF_Supermarket/cilium_ebpf_probe/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,8 @@ github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lN
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw=
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8=
github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A=
github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc=
github.com/mozilla/tls-observatory v0.0.0-20200317151703-4fa42e1c2dee/go.mod h1:SrKMQvPiws7F7iqYp8/TX+IhxCYhzr6N/1yb8cwHsGk=
Expand Down Expand Up @@ -513,6 +515,11 @@ github.com/quasilyte/go-ruleguard v0.2.0/go.mod h1:2RT/tf0Ce0UDj5y243iWKosQogJd8
github.com/quasilyte/regex/syntax v0.0.0-20200407221936-30656e2c4a95/go.mod h1:rlzQ04UMyJXu/aOvhd8qT+hvDrFpiwqp8MRXDY9szc0=
github.com/rakyll/statik v0.1.6/go.mod h1:OEi9wJV/fMUAGx1eNjq75DKDsJVuEv1U0oYdX6GX8Zs=
github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
github.com/richardlehane/mscfb v1.0.4 h1:WULscsljNPConisD5hR0+OyZjwK46Pfyr6mPu5ZawpM=
github.com/richardlehane/mscfb v1.0.4/go.mod h1:YzVpcZg9czvAuhk9T+a3avCpcFPMUWm7gK3DypaEsUk=
github.com/richardlehane/msoleps v1.0.1/go.mod h1:BWev5JBpU9Ko2WAgmZEuiz4/u3ZYTKbjLycmwiWUfWg=
github.com/richardlehane/msoleps v1.0.3 h1:aznSZzrwYRl3rLKRT3gUk9am7T/mLNSnJINvN0AQoVM=
github.com/richardlehane/msoleps v1.0.3/go.mod h1:BWev5JBpU9Ko2WAgmZEuiz4/u3ZYTKbjLycmwiWUfWg=
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
Expand Down Expand Up @@ -590,6 +597,12 @@ github.com/valyala/quicktemplate v1.6.2/go.mod h1:mtEJpQtUiBV0SHhMX6RtiJtqxncgrf
github.com/valyala/tcplisten v0.0.0-20161114210144-ceec8f93295a/go.mod h1:v3UYOV9WzVtRmSR+PDvWpU/qWl4Wa5LApYYX4ZtKbio=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
github.com/xuri/efp v0.0.0-20220603152613-6918739fd470 h1:6932x8ltq1w4utjmfMPVj09jdMlkY0aiA6+Skbtl3/c=
github.com/xuri/efp v0.0.0-20220603152613-6918739fd470/go.mod h1:ybY/Jr0T0GTCnYjKqmdwxyxn2BQf2RcQIIvex5QldPI=
github.com/xuri/excelize/v2 v2.6.1 h1:ICBdtw803rmhLN3zfvyEGH3cwSmZv+kde7LhTDT659k=
github.com/xuri/excelize/v2 v2.6.1/go.mod h1:tL+0m6DNwSXj/sILHbQTYsLi9IF4TW59H2EF3Yrx1AU=
github.com/xuri/nfp v0.0.0-20220409054826-5e722a1d9e22 h1:OAmKAfT06//esDdpi/DZ8Qsdt4+M5+ltca05dA5bG2M=
github.com/xuri/nfp v0.0.0-20220409054826-5e722a1d9e22/go.mod h1:WwHg+CVyzlv/TX9xqBFXEZAuxOPxn2k1GNHwG41IIUQ=
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
Expand Down Expand Up @@ -624,6 +637,8 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8U
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20220214200702-86341886e292/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.0.0-20220817201139-bc19a97f63c8 h1:GIAS/yBem/gq2MUqgNIzUHW7cJMmx3TGZOrnyYaNQ6c=
golang.org/x/crypto v0.0.0-20220817201139-bc19a97f63c8/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
Expand All @@ -636,6 +651,7 @@ golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EH
golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU=
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.0.0-20220413100746-70e8d0d3baa9/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
Expand Down Expand Up @@ -707,6 +723,8 @@ golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96b
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd h1:O7DYs+zxREGLKzKoMQrtrEacpb0ZVXA5rIwylE2Xchk=
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/net v0.0.0-20220812174116-3211cb980234 h1:RDqmgfe7SvlMWoqC3xwQ2blLO3fcWcxMa3eBLRdRW7E=
golang.org/x/net v0.0.0-20220812174116-3211cb980234/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
Expand Down Expand Up @@ -801,6 +819,8 @@ golang.org/x/sys v0.0.0-20220209214540-3681064d5158/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10 h1:WIoqL4EROvwiPdUtaip4VcDdpZ4kha7wBWZrbVKCIZg=
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 h1:JGgROgKl9N8DuW20oFS5gxc+lE67/N3FcwmBPMe7ArY=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
Expand Down Expand Up @@ -1045,6 +1065,7 @@ gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gotest.tools/v3 v3.0.2/go.mod h1:3SzNCllyD9/Y+b5r9JIKQ474KzkZyqLqEfYqMsX94Bk=
Expand Down
2 changes: 1 addition & 1 deletion eBPF_Supermarket/cilium_ebpf_probe/grpc_server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

"google.golang.org/grpc"

pb "cilium_ebpf_probe/proto/greetpb"
pb "lmp/eBPF_Supermarket/cilium_ebpf_probe/proto/greetpb"
)

type server struct{}
Expand Down
114 changes: 62 additions & 52 deletions eBPF_Supermarket/cilium_ebpf_probe/http2_tracing/bpf_program.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ struct go_grpc_http2_header_event_t {
};
struct write_header_t{
struct go_grpc_http2_header_event_t event[2];
int32_t sid;
int64_t ns;
};
struct operator_header_t{
struct go_grpc_http2_header_event_t event[8];
int32_t sid;
int8_t w;
int64_t ns;
};
BPF_PERCPU_ARRAY(write_header_heap,struct write_header_t,1);
Expand Down Expand Up @@ -50,82 +53,89 @@ static void copy_header_field(struct header_field_t* dst, const void* header_fie
bpf_probe_read(dst->msg, dst->size, str.ptr);
}
// Copies and submits content of an array of hpack.HeaderField to perf buffer.
static void submit_headers(struct pt_regs* ctx, void* fields_ptr, int64_t fields_len,int64_t typenum) {
// Size of the golang hpack.HeaderField struct.
const size_t header_field_size = 40;
if (typenum==1){//write_header
int zero=0;
struct write_header_t *e=write_header_heap.lookup(&zero);
if (e==NULL){
bpf_trace_printk("return");
return;}
int64_t keyZero=0;
u64 *tsp = timecount.lookup(&keyZero);
if (tsp!=0){ //if is the second bigger time
e->ns=(int64_t)(bpf_ktime_get_ns());
timecount.delete(&keyZero);
static void submit_headers_for_writeheader(struct pt_regs* ctx, void* fields_ptr, int64_t fields_len,int32_t streamid){
const size_t header_field_size = 40;
int zero=0;
bpf_trace_printk("write streamID %d ",streamid);
struct write_header_t *e=write_header_heap.lookup(&zero);
if (e==NULL){
bpf_trace_printk("return");
return;}
int64_t keyZero=0;
u64 *tsp = timecount.lookup(&keyZero);
if (tsp!=0){ //if is the second bigger time
e->ns=(int64_t)(bpf_ktime_get_ns());
timecount.delete(&keyZero);
}
else{ //if the first smaller time
u64 ts = bpf_ktime_get_ns();
timecount.update(&keyZero,&ts);
e->ns=0;
}
e->sid=streamid;
for (size_t i = 0; i < 2; i++) {
if (i >= fields_len) {
continue;
}
else{ //if the first smaller time
u64 ts = bpf_ktime_get_ns();
timecount.update(&keyZero,&ts);
e->ns=0;
const void* header_field_ptr = fields_ptr + i * header_field_size;
copy_header_field(&(e->event[i].name), header_field_ptr);
copy_header_field(&(e->event[i].value), header_field_ptr + 16);
}
write_header_events.perf_submit(ctx, e, sizeof(*e));
}
static void submit_headers_for_operatorheader(struct pt_regs* ctx, void* fields_ptr, int64_t fields_len,int32_t streamid,int8_t weight){
const size_t header_field_size = 40;
for (size_t i = 0; i < 2; i++) {
if (i >= fields_len) {
continue;
}
const void* header_field_ptr = fields_ptr + i * header_field_size;
copy_header_field(&(e->event[i].name), header_field_ptr);
copy_header_field(&(e->event[i].value), header_field_ptr + 16);
}
write_header_events.perf_submit(ctx, e, sizeof(*e));
}
else{
int zero=0;
struct operator_header_t *e=operator_header_heap.lookup(&zero);
if (e==NULL){
bpf_trace_printk("return");
return;}
e->ns=bpf_ktime_get_ns();
for (size_t i = 0; i < 8; i++) {
if (i >= fields_len) {
continue;
}
const void* header_field_ptr = fields_ptr + i * header_field_size;
copy_header_field(&(e->event[i].name), header_field_ptr);
copy_header_field(&(e->event[i].value), header_field_ptr + 16);
bpf_trace_printk("streamID %d weight %d",streamid,weight);
int zero=0;
struct operator_header_t *e=operator_header_heap.lookup(&zero);
if (e==NULL){
bpf_trace_printk("return");
return;}
e->sid=streamid;
e->w=weight;
e->ns=bpf_ktime_get_ns();
for (size_t i = 0; i < 8; i++) {
if (i >= fields_len) {
continue;
}
operator_header_events.perf_submit(ctx, e, sizeof(*e));
const void* header_field_ptr = fields_ptr + i * header_field_size;
copy_header_field(&(e->event[i].name), header_field_ptr);
copy_header_field(&(e->event[i].value), header_field_ptr + 16);
}
operator_header_events.perf_submit(ctx, e, sizeof(*e));
}
// Signature:2 + 2 func (l *loopyWriter) writeHeader(streamID uint32, endStream bool, hf []hpack.HeaderField, onWrite func())
int probe_loopy_writer_write_header(struct pt_regs* ctx) {
void* ptr=(void*)ctx->di;
int64_t fields_len;
fields_len=ctx->si;
submit_headers(ctx, ptr, fields_len,1);
submit_headers_for_writeheader(ctx, ptr, fields_len,ctx->bx);
return 0;
}
// Signature: 8 func (t *http2Server) operateHeaders(frame *http2.MetaHeadersFrame, handle func(*Stream),
// traceCtx func(context.Context, string) context.Context)
int probe_http2_server_operate_headers(struct pt_regs* ctx) {
int probe_http2_server_operate_headers(struct pt_regs* ctx) {
void* frame_ptr=(void*)ctx->bx;
void* fields_ptr;
bpf_probe_read(&fields_ptr, sizeof(void*), frame_ptr + 8);
int64_t fields_len;
bpf_probe_read(&fields_len, sizeof(int64_t), frame_ptr + 8 + 8);
submit_headers(ctx, fields_ptr, fields_len,2);
void* headersframe_ptr;
bpf_probe_read(&headersframe_ptr,sizeof(void*),frame_ptr);
int32_t streamid;
bpf_probe_read(&streamid,sizeof(int32_t),headersframe_ptr+8);
int8_t weight;
bpf_probe_read(&weight,sizeof(int8_t),headersframe_ptr+17);
submit_headers_for_operatorheader(ctx, fields_ptr, fields_len,streamid,weight);
return 0;
}
`
Loading

0 comments on commit 2b0b961

Please sign in to comment.