|
|
@@ -37,6 +37,7 @@
|
|
|
return 0; \
|
|
|
} \
|
|
|
})
|
|
|
+#define NS_PER_SEC 1000000000ULL
|
|
|
|
|
|
#define IOVEC_BUF_SIZE MAX_PAYLOAD_SIZE * 2 // must be double of MAX_PAYLOAD_SIZE
|
|
|
#define MAX_IOVEC_SIZE 32
|
|
|
@@ -55,7 +56,7 @@
|
|
|
#include "dubbo2.c"
|
|
|
#include "apm_trace.c"
|
|
|
|
|
|
-__u32 filterPid = 88028;
|
|
|
+__u32 filterPid = 8153;
|
|
|
|
|
|
struct l7_event {
|
|
|
__u64 fd;
|
|
|
@@ -254,17 +255,19 @@ int trace_enter_write(void *ctx, __u64 fd, __u16 is_tls, char *buf, __u64 size,
|
|
|
k.is_tls = is_tls;
|
|
|
k.stream_id = -1;
|
|
|
|
|
|
- bpf_printk("enter-payload:%s|type:%s|FD:%d\n",payload,"type",k.fd);
|
|
|
+// bpf_printk("enter-payload:%s|type:%s|FD:%d\n",payload,"type",k.fd);
|
|
|
|
|
|
if (is_http_response(payload, &http_status))
|
|
|
{
|
|
|
- bpf_printk("[Response][HTTP]:TGID:%d|type:%s|FD:%d\n", k.pid, "type", k.fd);
|
|
|
- struct trace_key_t trace_key = get_trace_key(pid, tid);
|
|
|
- __u64 trace_id = get_trace_id(pid, tid);
|
|
|
- bpf_printk("trace_id:%llu", trace_id);
|
|
|
+// __u64 goid = get_rw_goid(120 * NS_PER_SEC, 1);
|
|
|
+// bpf_printk("[Response][HTTP]:thread_id:%d|goid:%d|FD:%d\n", tid, goid, k.fd);
|
|
|
+// struct trace_key_t trace_key = get_trace_key(pid, tid);
|
|
|
+// struct fd_trace_key_t fd_trace_key = get_fd_trace_key(pid, fd);
|
|
|
+ __u64 trace_id = get_fd_trace_id(pid, fd);
|
|
|
+// bpf_printk("trace_id:%llu", trace_id);
|
|
|
+ bpf_printk("[Response][HTTP] pid:%d,fd:%d,traceid:%llu", pid, fd, trace_id);
|
|
|
// 清除trace信息
|
|
|
- bpf_map_delete_elem(&trace_info_heap, &trace_key);
|
|
|
-
|
|
|
+ clear_trace(pid, tid, fd);
|
|
|
// 发送事件到用户空间 start
|
|
|
struct l7_event *e = bpf_map_lookup_elem(&l7_event_heap, &zero);
|
|
|
if (!e) {
|
|
|
@@ -273,15 +276,14 @@ int trace_enter_write(void *ctx, __u64 fd, __u16 is_tls, char *buf, __u64 size,
|
|
|
struct l7_request *req = bpf_map_lookup_elem(&active_l7_requests, &k);
|
|
|
if (!req)
|
|
|
{
|
|
|
- bpf_printk("[Response][HTTP]:no req-----------");
|
|
|
- bpf_printk("[Response][HTTP]:pid:%d|tid:%d",k.pid,k.fd);
|
|
|
- bpf_printk("[Response][HTTP]:is_tls:%d|tid:%d",k.is_tls,k.stream_id);
|
|
|
+// bpf_printk("[Response][HTTP]:no req-----------");
|
|
|
+// bpf_printk("[Response][HTTP]:pid:%d|tid:%d",k.pid,k.fd);
|
|
|
+// bpf_printk("[Response][HTTP]:is_tls:%d|tid:%d",k.is_tls,k.stream_id);
|
|
|
return 0;
|
|
|
}
|
|
|
- bpf_printk("[Response][HTTP]:req->ns:%d\n",req->ns);
|
|
|
|
|
|
e->duration = bpf_ktime_get_ns() - req->ns;
|
|
|
- bpf_printk("[Response][HTTP]:duration->ns:%d\n",e->duration);
|
|
|
+// bpf_printk("[Response][HTTP]:duration->ns:%d\n",e->duration);
|
|
|
e->protocol = PROTOCOL_TRACE;
|
|
|
e->status = http_status;
|
|
|
e->pid = k.pid;
|
|
|
@@ -290,7 +292,6 @@ int trace_enter_write(void *ctx, __u64 fd, __u16 is_tls, char *buf, __u64 size,
|
|
|
e->trace_start = 0;
|
|
|
e->trace_end = 1;
|
|
|
e->trace_id = trace_id;
|
|
|
- bpf_printk("[Response][HTTP]:status:%d",e->status);
|
|
|
e->payload_size = size;
|
|
|
COPY_PAYLOAD(e->payload, size, payload);
|
|
|
bpf_map_delete_elem(&active_l7_requests, &k);
|
|
|
@@ -323,7 +324,7 @@ int trace_enter_write(void *ctx, __u64 fd, __u16 is_tls, char *buf, __u64 size,
|
|
|
} else if (is_memcached_query(payload, size)) {
|
|
|
req->protocol = PROTOCOL_MEMCACHED;
|
|
|
} else if (is_mysql_query(payload, size, &req->request_type)) {
|
|
|
- bpf_printk("[Enter][Mysql]:TGID:%d|type:%s|FD:%d\n",k.pid,"type",k.fd);
|
|
|
+ bpf_printk("[Enter][Mysql]:thread_id:%d\n",tid);
|
|
|
if (req->request_type == MYSQL_COM_STMT_CLOSE) {
|
|
|
struct l7_event *e = bpf_map_lookup_elem(&l7_event_heap, &zero);
|
|
|
if (!e) {
|
|
|
@@ -480,8 +481,13 @@ int trace_exit_read(void *ctx, __u64 id, __u32 pid, __u16 is_tls, long int ret)
|
|
|
bpf_map_update_elem(&active_l7_requests, &k, req, BPF_NOEXIST);
|
|
|
}
|
|
|
|
|
|
- bpf_printk("[Receive][HTTP]:TGID:%d|type:%s|FD:%d\n",k.pid,"type",k.fd);
|
|
|
- bpf_printk("[Receive][HTTP] payload1:%s|type:%s\n",payload,"type");
|
|
|
+ bpf_printk("[Receive][HTTP]:thread_id:%d\n",tid);
|
|
|
+// bpf_printk("[Receive][HTTP] payload1:%s|type:%s\n",payload,"type");
|
|
|
+// __u64 goid = 0;
|
|
|
+// goid = get_rw_goid(120 * NS_PER_SEC, 1);
|
|
|
+// bpf_printk("[Receive][HTTP] goid:%llu\n",goid);
|
|
|
+// __u64 goid = get_rw_goid(120 * NS_PER_SEC, 1);
|
|
|
+// bpf_printk("[Receive][HTTP]:thread_id:%d|goid:%d|FD:%d\n", tid, goid, k.fd);
|
|
|
|
|
|
struct trace_key_t trace_key = {};
|
|
|
struct trace_info_t trace_info = {};
|
|
|
@@ -496,6 +502,14 @@ int trace_exit_read(void *ctx, __u64 id, __u32 pid, __u16 is_tls, long int ret)
|
|
|
e->payload_size = ret;
|
|
|
COPY_PAYLOAD(e->payload, ret, payload);
|
|
|
|
|
|
+ // http trace
|
|
|
+ struct fd_trace_key_t fd_trace_key = {};
|
|
|
+ fd_trace_key.tgid = pid;
|
|
|
+ fd_trace_key.fd = k.fd;
|
|
|
+ bpf_map_update_elem(&fd_trace_info_heap, &fd_trace_key, &trace_info, BPF_NOEXIST);
|
|
|
+ bpf_printk("[Receive][HTTP] pid:%d,fd:%d,traceid:%llu", fd_trace_key.tgid, fd_trace_key.fd,
|
|
|
+ trace_info.trace_id);
|
|
|
+
|
|
|
// 入口方法缓存 bpf_map_update_elem(map, key, value, options)
|
|
|
bpf_map_update_elem(&trace_info_heap, &trace_key, &trace_info, BPF_NOEXIST);
|
|
|
bpf_perf_event_output(ctx, &l7_events, BPF_F_CURRENT_CPU, e, sizeof(*e));
|
|
|
@@ -544,7 +558,7 @@ int trace_exit_read(void *ctx, __u64 id, __u32 pid, __u16 is_tls, long int ret)
|
|
|
|
|
|
bpf_map_delete_elem(&active_l7_requests, &k);
|
|
|
if (e->protocol == PROTOCOL_HTTP) {
|
|
|
- bpf_printk("[Response][HTTP]:TGID:%d|type:%s|FD:%d\n",k.pid,"type",k.fd);
|
|
|
+ bpf_printk("[Response][HTTP]:thread_id:%d\n",tid);
|
|
|
response = is_http_response(payload, &e->status);
|
|
|
} else if (e->protocol == PROTOCOL_POSTGRES) {
|
|
|
response = is_postgres_response(payload, ret, &e->status);
|
|
|
@@ -560,9 +574,9 @@ int trace_exit_read(void *ctx, __u64 id, __u32 pid, __u16 is_tls, long int ret)
|
|
|
} else if (e->protocol == PROTOCOL_MEMCACHED) {
|
|
|
response = is_memcached_response(payload, ret, &e->status);
|
|
|
} else if (e->protocol == PROTOCOL_MYSQL) {
|
|
|
- bpf_printk("[Response][Mysql]:TGID:%d|type:%s|FD:%d\n",k.pid,"type",k.fd);
|
|
|
+ bpf_printk("[Response][Mysql]:thread_id:%d\n",tid);
|
|
|
__u64 trace_id = get_trace_id(pid, tid);
|
|
|
- bpf_printk("[Mysql] trace_id:%llu", trace_id);
|
|
|
+// bpf_printk("[Mysql] trace_id:%llu", trace_id);
|
|
|
e->trace_id = trace_id;
|
|
|
response = is_mysql_response(payload, ret, req->request_type, &e->statement_id, &e->status);
|
|
|
if (req->request_type == MYSQL_COM_STMT_PREPARE) {
|