Kaynağa Gözat

Fixed #TASK_QT-11100 适配arm和国产化操作系统,目前把问题代码注释后,euspace能正常运行,但功能正常与否未验证。

root 1 yıl önce
ebeveyn
işleme
388beb867b

+ 3 - 2
Makefile2

@@ -17,12 +17,13 @@ build:
 	CGO_ENABLED=1 go build -buildvcs=false -o euspace
 c:
 	#docker exec -it 9d928d96d4d0 sh -c 'cd /opt/github/euspace/ebpftracer && sh build.sh${PARAMS}'
-	docker exec -it 62d0676aa0b7 sh -c 'cd /opt/github/euspace/ebpftracer && sh build_linux.sh${PARAMS}'
+	docker exec -it 91025e30b341 sh -c 'cd /data/rock/code/euspace/ebpftracer && sh build_linux.sh${PARAMS}'
 c-build: c
 
 go-build:
 	#ssh [email protected] 'export https_proxy=http://10.0.22.50:4780 && source ~/.g/env && cd /opt/github/euspace && make -f Makefile2 build'
-	docker exec -it 62d0676aa0b7 bash -c 'cd /opt/github/euspace && source ~/.g/env && make -f Makefile2 build'
+	# docker exec -it 91025e30b341 bash -c 'cd /data/rock/code/euspace && source ~/.g/env && make -f Makefile2 build'
+	docker exec -it 91025e30b341 bash -c 'cd /data/rock/code/euspace && source /etc/profile && make -f Makefile2 build'
 go: go-build run
 
 run:

+ 4 - 4
ebpftracer/build_linux.sh

@@ -38,19 +38,19 @@ echo "debug: $debug"
 	-fno-color-diagnostics \
 	-fno-unwind-tables \
 	-fno-stack-protector \
-	-fno-asynchronous-unwind-tables -g -O2 -emit-llvm -D__KERNEL_FROM=512 -D__TARGET_ARCH_x86 -D__x86_64__  $debug -o ebpf.ll -c ./ebpf/ebpf.c && /usr/bin/llc -march=bpf -filetype=obj -mcpu=v2 -o ebpf.elf ebpf.ll
+	-fno-asynchronous-unwind-tables -g -O2 -emit-llvm -D__KERNEL_FROM=416 -D__TARGET_ARCH_arm64 -D__aarch64__  -D__AARCH64EB__ $debug -o ebpf.ll -c ./ebpf/ebpf.c && /usr/bin/llc -march=bpf -filetype=obj -mcpu=v2 -o ebpf.elf ebpf.ll
 
-/usr/bin/llvm-strip -g ebpf.elf  && mv ebpf.elf ebpf512x86.o
+/usr/bin/llvm-strip -g ebpf.elf  && mv ebpf.elf ebpf416arm64.o
 
 echo -en '// generated - do not edit\npackage ebpftracer\n\nvar ebpfProg = map[string][]struct {\n' > ebpf.go \
 	&& echo -en '\tv string\n' >> ebpf.go \
 	&& echo -en '\tp []byte\n' >> ebpf.go \
 	&& echo -en '}{\n' >> ebpf.go \
 	&& echo -en '\t"amd64": {\n' >> ebpf.go \
-	&& echo -en '\t\t{"v5.12", []byte("' >> ebpf.go && hexdump -v -e '"\\\x" 1/1 "%02x"' ebpf512x86.o >> ebpf.go && echo '")},' >> ebpf.go \
+	&& echo -en '\t\t{"v4.16", []byte("' >> ebpf.go && hexdump -v -e '"\\\x" 1/1 "%02x"' ebpf416arm64.o >> ebpf.go && echo '")},' >> ebpf.go \
 	&& echo -en '\t},\n'>> ebpf.go \
 	&& echo -en '\t"arm64": {\n' >> ebpf.go \
-	&& echo -en '\t\t{"v5.12", []byte("' >> ebpf.go && hexdump -v -e '"\\\x" 1/1 "%02x"' ebpf512x86.o >> ebpf.go && echo '")},' >> ebpf.go \
+	&& echo -en '\t\t{"v4.16", []byte("' >> ebpf.go && hexdump -v -e '"\\\x" 1/1 "%02x"' ebpf416arm64.o >> ebpf.go && echo '")},' >> ebpf.go \
 	&& echo -en '\t},\n'>> ebpf.go \
 	&& echo -en '}\n'>> ebpf.go
 if [ $? -ne 0 ]; then

+ 2 - 2
ebpftracer/ebpf/common/load_const.h

@@ -12,9 +12,9 @@ static __always_inline __u64 load_kernel_version()
     return var;
 }
 
-static __always_inline __u32 load_filter_pid()
+static __always_inline __u64 load_filter_pid()
 {
-    __u32 var = 0;
+    __u64 var = 0;
     LOAD_CONSTANT("filter_pid", var);
     return var;
 }

+ 4 - 7
ebpftracer/ebpf/include/bpf_base.h

@@ -124,17 +124,13 @@ struct pt_regs {
 		};
 	};
 	__u64 orig_x0;
-#ifdef __AARCH64EB__
-	__u32 unused2;
-	__s32 syscallno;
-#else
 	__s32 syscallno;
 	__u32 unused2;
-#endif
-
 	__u64 orig_addr_limit;
-	__u64 unused;		// maintain 16 byte alignment
+	__u64 pmr_save;
 	__u64 stackframe[2];
+	__u64 lockdep_hardirqs;
+	__u64 exit_rcu;
 };
 
 #define PT_REGS_PARM1(x) ((x)->regs[0])
@@ -142,6 +138,7 @@ struct pt_regs {
 #define PT_REGS_PARM3(x) ((x)->regs[2])
 #define PT_REGS_PARM4(x) ((x)->regs[3])
 #define PT_REGS_PARM5(x) ((x)->regs[4])
+#define PT_REGS_PARM6(x) ((x)->regs[5])
 #define PT_REGS_RET(x) ((x)->regs[30])
 #define PT_REGS_FP(x) ((x)->regs[29])	/* Works only with CONFIG_FRAME_POINTER */
 #define PT_REGS_RC(x) ((x)->regs[0])

+ 10 - 1
ebpftracer/ebpf/include/socket_trace_common.h

@@ -71,6 +71,7 @@ struct trace_conf_t {
 	__u64 go_tracing_timeout;
 	__u64 io_event_collect_mode;
 	__u64 io_event_minimal_duration;
+	__u64 total_cpus;
 
 	unsigned char host_id[APM_HOST_ID_SIZE];
 	unsigned char app_id[APM_APP_ID_SIZE];
@@ -190,7 +191,15 @@ struct ebpf_proc_info {
 	__u64 start_addr;
 	__u64 end_addr;
 	unsigned char instance_id[APM_INSTANCE_ID_SIZE];
-
+	__u64 method_ptr_pos;
+	__u64 url_ptr_pos;
+	__u64 path_ptr_pos;
+	__u64 status_code_pos;
+	__u64 request_host_pos;
+	__u64 request_proto_pos;
+	__u64 ctx_ptr_pos;
+	__u64 headers_ptr_pos;
+	__u64 buckets_ptr_pos;
 } __attribute__((packed));
 
 enum {

+ 1 - 0
ebpftracer/ebpf/l7/gotls.c

@@ -8,6 +8,7 @@
 #define PT_GO_REGS_PARM2(x) ((x)->rbx)
 
 #elif defined(__TARGET_ARCH_arm64)
+#define PT_REGS_ARM64 const volatile struct user_pt_regs
 #define GO_PARAM1(x) (((PT_REGS_ARM64 *)(x))->regs[0])
 #define GO_PARAM2(x) (((PT_REGS_ARM64 *)(x))->regs[1])
 #define GO_PARAM3(x) (((PT_REGS_ARM64 *)(x))->regs[2])

+ 229 - 17
ebpftracer/ebpf/l7/l7.c

@@ -241,6 +241,218 @@ __u64 read_iovec(char *l7_iovec, __u64 iovlen, __u64 ret, char *buf) {
     return offset;
 }
 
+static inline __attribute__((__always_inline__))
+int rock_trace_enter_write(void *ctx, char *buf, __u64 size, __u64 iovlen) {
+    __u64 id = bpf_get_current_pid_tgid();
+    __u32 zero = 0;
+    __u32 pid, tid;
+    __u32 http_status;
+    struct trace_event_raw_sys_enter_rw__stub* tctx = (struct trace_event_raw_sys_enter_rw__stub*)ctx;
+    __u64 fd = tctx->fd;
+
+    pid = id >> 32;
+    tid =  (__u32)id;
+    if (load_filter_pid() != 0 && pid != load_filter_pid()) {
+        return 0;
+    }
+    char* payload = buf;
+    if (iovlen) {
+        payload = bpf_map_lookup_elem(&iovec_buf_heap, &zero);
+        if (!payload) {
+            return 0;
+        }
+        size = read_iovec(buf, iovlen, 0, payload);
+    }
+    if (!size) {
+        return 0;
+    }
+
+    struct l7_request *req = bpf_map_lookup_elem(&l7_request_heap, &zero);
+    if (!req) {
+        return 0;
+    }
+    req->protocol = PROTOCOL_UNKNOWN;
+    req->partial = 0;
+    req->request_id = 0;
+    req->ns = 0;
+    req->payload_size = size;
+    struct l7_request_key k = {};
+    k.pid = id >> 32;
+    k.fd = fd;
+    k.is_tls = 0;
+    k.stream_id = -1;
+
+//    cw_bpf_debug("enter-payload:%s|type:%s|FD:%d\n",payload,"type",k.fd);
+
+    if (is_http_response(payload, &http_status))
+    {
+//        __u64 trace_id = get_apm_trace_id(pid, fd);
+        __u64 trace_id = get_fd_trace_id(pid, fd);
+        cw_bpf_debug("[Trace End in l7][Response][HTTP] pid:%d,fd:%d,trace_id:%llu", tid, fd, trace_id);
+        // 清除trace信息
+        cw_clear_trace(pid, tid, fd);
+        // 发送事件到用户空间 start
+        struct l7_event *e = bpf_map_lookup_elem(&l7_event_heap, &zero);
+        if (!e) {
+            return 0;
+        }
+        struct l7_request *req = bpf_map_lookup_elem(&active_l7_requests, &k);
+        if (!req)
+        {
+//            cw_bpf_debug("[Response][HTTP]:no req-----------");
+//            cw_bpf_debug("[Response][HTTP]:pid:%d|tid:%d",k.pid,k.fd);
+//            cw_bpf_debug("[Response][HTTP]:is_tls:%d|tid:%d",k.is_tls,k.stream_id);
+            return 0;
+        }
+
+        e->duration = bpf_ktime_get_ns() - req->ns;
+//        cw_bpf_debug("[Response][HTTP]:duration->ns:%d\n",e->duration);
+        e->protocol = PROTOCOL_TRACE;
+        e->status = http_status;
+        e->pid = k.pid;
+        e->fd = k.fd;
+        // e->connection_timestamp = get_connection_timestamp(k.pid, k.fd);
+        e->trace_start = 0;
+        e->trace_end = 1;
+        e->trace_id = trace_id;
+        e->payload_size = size;
+        COPY_PAYLOAD(e->payload, size, payload);
+		// psc
+	    struct apm_span_context *cw_psc = cw_get_parent_tracking_span();
+	    if(cw_psc){
+		    cw_copy_byte_arrays(cw_psc->trace_id, e->trace_id_from, APM_TRACE_ID_SIZE);
+		    cw_copy_byte_arrays(cw_psc->assumed_app_id, e->called_id, APM_ASSUMED_APP_ID_SIZE);
+		    cw_copy_byte_arrays(cw_psc->instance_id, e->instance_id_from, APM_INSTANCE_ID_SIZE);
+		    cw_copy_byte_arrays(cw_psc->app_id, e->app_id_from, APM_APP_ID_SIZE);
+		    cw_copy_byte_arrays(cw_psc->span_id, e->span_id_from, APM_SPAN_ID_SIZE);
+//		    for (int i = 0; i < APM_TRACE_ID_SIZE; i++) {
+//			    bpf_printk("trace_enter_write - trace_id = %02x", e->trace_id_from[i]);
+//		    }
+	    }
+        bpf_map_delete_elem(&active_l7_requests, &k);
+        bpf_perf_event_output(ctx, &l7_events, BPF_F_CURRENT_CPU, e, sizeof(*e));
+        // 发送事件到用户空间 end
+//        __u64 k_version = load_filter_pid();
+//        cw_bpf_debug("filter_pid:%d", k_version);
+//
+//        struct test_t *ttt = bpf_map_lookup_elem(&test_heap, &zero);
+//        if (!ttt) {
+//            return 0;
+//        }
+
+//        struct member_fields_offset *off = bpf_map_lookup_elem(&__members_offset, &zero);
+//        if (!off) {
+//            return 0;
+//        }
+
+//        cw_bpf_debug("off->task__files_offset:%x", off->task__files_offset);
+//        cw_bpf_debug("e->test_id1111:%d", ttt->test_id);
+        cw_bpf_debug("HTTP_END");
+        return 0;
+    }
+
+    if (is_http_request(payload)) {
+	    cw_bpf_debug("");
+	    cw_bpf_debug("-----[Kernel Enter][HTTP]:pid:[%d]|CURRENT-GOID:[%llu]|FD:[%d]", tid, get_current_goroutine(), k.fd);
+
+	    req->protocol = PROTOCOL_HTTP;
+//        struct apm_trace_key_t trace_key = {0};
+//        trace_key = get_apm_trace_key(120 * NS_PER_SEC, true);
+//        cw_bpf_debug("[Enter] [HTTP]:goid:%llu",trace_key.goid);
+
+
+    } else if (is_postgres_query(payload, size, &req->request_type)) {
+        if (req->request_type == POSTGRES_FRAME_CLOSE) {
+            struct l7_event *e = bpf_map_lookup_elem(&l7_event_heap, &zero);
+            if (!e) {
+                return 0;
+            }
+            e->protocol = PROTOCOL_POSTGRES;
+            e->method = METHOD_STATEMENT_CLOSE;
+            e->payload_size = size;
+            COPY_PAYLOAD(e->payload, size, payload);
+            send_event(ctx, e, k.pid, k.fd);
+            return 0;
+        }
+        req->protocol = PROTOCOL_POSTGRES;
+    } else if (is_redis_query(payload, size)) {
+        cw_bpf_debug("[Enter][Redis]:TGID:%d|type:%s|FD:%d\n",k.pid,"type",k.fd);
+        req->protocol = PROTOCOL_REDIS;
+    } else if (is_memcached_query(payload, size)) {
+        req->protocol = PROTOCOL_MEMCACHED;
+    } else if (is_mysql_query(payload, size, &req->request_type)) {
+        cw_bpf_debug("[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) {
+                return 0;
+            }
+            e->protocol = PROTOCOL_MYSQL;
+            e->method = METHOD_STATEMENT_CLOSE;
+            e->payload_size = size;
+            COPY_PAYLOAD(e->payload, size, payload);
+	        cw_bpf_debug("[Enter][Mysql][Send]:thread_id:%d\n",tid);
+            send_event(ctx, e, k.pid, k.fd);
+            return 0;
+        }
+        req->protocol = PROTOCOL_MYSQL;
+    } else if (is_mongo_query(payload, size)) {
+        req->protocol = PROTOCOL_MONGO;
+    } else if (is_rabbitmq_produce(payload, size)) {
+        struct l7_event *e = bpf_map_lookup_elem(&l7_event_heap, &zero);
+        if (!e) {
+            return 0;
+        }
+        e->protocol = PROTOCOL_RABBITMQ;
+        e->method = METHOD_PRODUCE;
+        send_event(ctx, e, k.pid, k.fd);
+        return 0;
+    } else if (nats_method(payload, size) == METHOD_PRODUCE) {
+        struct l7_event *e = bpf_map_lookup_elem(&l7_event_heap, &zero);
+        if (!e) {
+            return 0;
+        }
+        e->protocol = PROTOCOL_NATS;
+        e->method = METHOD_PRODUCE;
+        send_event(ctx, e, k.pid, k.fd);
+        return 0;
+    } else if (is_cassandra_request(payload, size, &k.stream_id)) {
+        req->protocol = PROTOCOL_CASSANDRA;
+    } else if (is_kafka_request(payload, size, &req->request_id)) {
+        req->protocol = PROTOCOL_KAFKA;
+        struct l7_request *prev_req = bpf_map_lookup_elem(&active_l7_requests, &k);
+        if (prev_req && prev_req->protocol == PROTOCOL_KAFKA) {
+            req->ns = prev_req->ns;
+        }
+    } else if (looks_like_http2_frame(payload, size, METHOD_HTTP2_CLIENT_FRAMES)) {
+        struct l7_event *e = bpf_map_lookup_elem(&l7_event_heap, &zero);
+        if (!e) {
+            return 0;
+        }
+        e->protocol = PROTOCOL_HTTP2;
+        e->method = METHOD_HTTP2_CLIENT_FRAMES;
+        e->duration = bpf_ktime_get_ns();
+        e->payload_size = size;
+        COPY_PAYLOAD(e->payload, size, payload);
+        send_event(ctx, e, k.pid, k.fd);
+        return 0;
+    } else if (is_dubbo2_request(payload, size)) {
+        req->protocol = PROTOCOL_DUBBO2;
+    } else if (is_dns_request(payload, size, &k.stream_id)) {
+        req->protocol = PROTOCOL_DNS;
+    }
+
+    if (req->protocol == PROTOCOL_UNKNOWN) {
+        return 0;
+    }
+    if (req->ns == 0) {
+        req->ns = bpf_ktime_get_ns();
+    }
+    COPY_PAYLOAD(req->payload, size, payload);
+    bpf_map_update_elem(&active_l7_requests, &k, req, BPF_NOEXIST);
+    return 0;
+}
+
 static inline __attribute__((__always_inline__))
 int trace_enter_write(void *ctx, __u64 fd, __u16 is_tls, char *buf, __u64 size, __u64 iovlen) {
     __u64 id = bpf_get_current_pid_tgid();
@@ -754,23 +966,23 @@ int sys_enter_sendmsg(struct trace_event_raw_sys_enter_rw__stub* ctx) {
 //	__u32 msg_len;
 //};
 
-SEC("tracepoint/syscalls/sys_enter_sendmmsg")
-int sys_enter_sendmmsg(struct trace_event_raw_sys_enter_rw__stub* ctx) {
-    __u64 offset = 0;
-    #pragma unroll
-    for (int i = 0; i <= 1; i++) {
-        if (i >= ctx->size) {
-            break;
-        }
-        struct mmsghdr h = {};
-        if (bpf_probe_read(&h , sizeof(h), (void *)(ctx->buf + offset))) {
-            return 0;
-        }
-        offset += sizeof(h);
-        trace_enter_write(ctx, ctx->fd, 0, (char*)h.msg_hdr.msg_iov, 0, h.msg_hdr.msg_iovlen);
-    }
-    return 0;
-}
+// SEC("tracepoint/syscalls/sys_enter_sendmmsg")
+// int sys_enter_sendmmsg(struct trace_event_raw_sys_enter_rw__stub* ctx) {
+//     __u64 offset = 0;
+//     #pragma unroll
+//     for (int i = 0; i <= 1; i++) {
+//         if (i >= ctx->size) {
+//             break;
+//         }
+//         struct mmsghdr h = {};
+//         if (bpf_probe_read(&h , sizeof(h), (void *)(ctx->buf + offset))) {
+//             return 0;
+//         }
+//         offset += sizeof(h);
+//         rock_trace_enter_write(ctx, (char*)h.msg_hdr.msg_iov, 0, h.msg_hdr.msg_iovlen);
+//     }
+//     return 0;
+// }
 
 SEC("tracepoint/syscalls/sys_enter_sendto")
 int sys_enter_sendto(struct trace_event_raw_sys_enter_rw__stub* ctx) {

+ 1 - 1
ebpftracer/ebpf/l7/rabbitmq.c

@@ -19,7 +19,7 @@ int rabbitmq_method_is(char *buf, __u64 buf_size, __u16 expected_method) {
         return 0;
     }
 
-    __u32 size = 0;
+    __u64 size = 0;
     bpf_read(buf+3, size);
     size = bpf_htonl(size);
     if (7 + size + 1 > buf_size) {

+ 8 - 0
ebpftracer/ebpf/uprobe_base_bpf.c

@@ -372,7 +372,15 @@ static __inline bool is_register_based_call(struct ebpf_proc_info *info)
 _Pragma("error \"Must specify a BPF target arch\"");
 #endif
 }
+// #define GOROUTINE(x) ((x)->r14)
+#if defined(__TARGET_ARCH_x86)
 #define GOROUTINE(x) ((x)->r14)
+#define PT_GO_REGS_PARM1(x) ((x)->rax)
+#define PT_GO_REGS_PARM2(x) ((x)->rbx)
+#elif defined(__TARGET_ARCH_arm64)
+#define PT_REGS_ARM64 const volatile struct user_pt_regs
+#define GOROUTINE(x) (((PT_REGS_ARM64 *)(x))->regs[28])
+#endif
 
 SEC("uprobe/runtime.execute")
 int runtime_execute(struct pt_regs *ctx)

+ 15 - 5
ebpftracer/ebpf/utrace/go/include/alloc.h

@@ -22,9 +22,9 @@
 #define MIN_BUFFER_SIZE 1
 
 // Injected in init
-volatile const u64 total_cpus;
-volatile const u64 start_addr;
-volatile const u64 end_addr;
+// volatile const u64 total_cpus;
+// volatile const u64 start_addr;
+// volatile const u64 end_addr;
 
 struct
 {
@@ -37,7 +37,12 @@ struct
 
 static __always_inline u64 get_area_start(u64 start_addr,u64 end_addr)
 {
-    s64 partition_size = (end_addr - start_addr) / total_cpus;
+    u32 k0 = 0;
+	struct trace_conf_t *trace_conf = trace_conf_map__lookup(&k0);
+	if (!trace_conf) {
+        return 0;
+	}
+    s64 partition_size = (end_addr - start_addr) / trace_conf->total_cpus;
     u32 current_cpu = bpf_get_smp_processor_id();
     s32 start_index = 0;
     u64 *start = (u64 *)bpf_map_lookup_elem(&alloc_map, &start_index);
@@ -55,7 +60,12 @@ static __always_inline u64 get_area_start(u64 start_addr,u64 end_addr)
 
 static __always_inline u64 get_area_end(u64 start,u64 start_addr,u64 end_addr)
 {
-    s64 partition_size = (end_addr - start_addr) / total_cpus;
+    u32 k0 = 0;
+	struct trace_conf_t *trace_conf = trace_conf_map__lookup(&k0);
+	if (!trace_conf) {
+        return 0;
+	}
+    s64 partition_size = (end_addr - start_addr) / trace_conf->total_cpus;
     s32 end_index = 1;
     u64 *end = (u64 *)bpf_map_lookup_elem(&alloc_map, &end_index);
     if (end == NULL || *end == 0)

+ 27 - 4
ebpftracer/ebpf/utrace/go/include/arguments.h

@@ -21,7 +21,7 @@
 #include <stdbool.h>
 
 // Injected in init
-volatile const bool is_registers_abi;
+// volatile const bool is_registers_abi;
 
 static __always_inline void *get_argument_by_reg(struct pt_regs *ctx, int index) {
 	switch (index) {
@@ -55,7 +55,15 @@ static __always_inline void *get_argument_by_stack(struct pt_regs *ctx, int inde
 }
 
 static __always_inline void *get_argument(struct pt_regs *ctx, int index) {
-	if (is_registers_abi) {
+	__u64 pid_tgid = bpf_get_current_pid_tgid();
+	__u32 tgid = pid_tgid >> 32;
+
+	struct ebpf_proc_info *info = bpf_map_lookup_elem(&proc_info_map, &tgid);
+	if (!info) {
+		return 0;
+	}
+
+	if (is_register_based_call(info)) {
 		return get_argument_by_reg(ctx, index);
 	}
 
@@ -69,7 +77,15 @@ static __always_inline void *get_argument(struct pt_regs *ctx, int index) {
 // For Go < 1.17: consistent key is the address of context.Context.
 // For Go >= 1.17: consistent key is the goroutine address.
 static __always_inline void *get_consistent_key(struct pt_regs *ctx, void *contextContext) {
-	if (is_registers_abi) {
+	__u64 pid_tgid = bpf_get_current_pid_tgid();
+	__u32 tgid = pid_tgid >> 32;
+
+	struct ebpf_proc_info *info = bpf_map_lookup_elem(&proc_info_map, &tgid);
+	if (!info) {
+		return 0;
+	}
+
+	if (is_register_based_call(info)) {
 		return (void *) GOROUTINE(ctx);
 	}
 
@@ -77,7 +93,14 @@ static __always_inline void *get_consistent_key(struct pt_regs *ctx, void *conte
 }
 
 static __always_inline bool is_register_abi() {
-	return is_registers_abi;
+	__u64 pid_tgid = bpf_get_current_pid_tgid();
+	__u32 tgid = pid_tgid >> 32;
+
+	struct ebpf_proc_info *info = bpf_map_lookup_elem(&proc_info_map, &tgid);
+	if (!info) {
+		return 0;
+	}
+	return is_register_based_call(info);
 }
 
 #endif

+ 9 - 0
ebpftracer/ebpf/utrace/go/include/go_common.h

@@ -149,3 +149,12 @@ typedef __u32 __wsum;
 //#endif
 //
 //#endif /* __VMLINUX_H__ */
+
+// 定义一个大小为 65536 字节的 Map
+#define GO_MAX_BUFFER_SIZE 1024
+struct {
+	__uint(type, BPF_MAP_TYPE_ARRAY);
+	__type(key, int); // 键类型为int
+	__uint(value_size, GO_MAX_BUFFER_SIZE); // 数组的每个值的大小
+	__uint(max_entries, 2); // 最大条目数为2
+} go_large_array_map SEC(".maps");

+ 15 - 15
ebpftracer/ebpf/utrace/go/include/otel_types.h

@@ -19,17 +19,17 @@
 #include "go_common.h"
 
 // Injected in init
-volatile const u64 attr_type_invalid;
+// volatile const u64 attr_type_invalid;
 
-volatile const u64 attr_type_bool;
-volatile const u64 attr_type_int64;
-volatile const u64 attr_type_float64;
-volatile const u64 attr_type_string;
+// volatile const u64 attr_type_bool;
+// volatile const u64 attr_type_int64;
+// volatile const u64 attr_type_float64;
+// volatile const u64 attr_type_string;
 
-volatile const u64 attr_type_boolslice;
-volatile const u64 attr_type_int64slice;
-volatile const u64 attr_type_float64slice;
-volatile const u64 attr_type_stringslice;
+// volatile const u64 attr_type_boolslice;
+// volatile const u64 attr_type_int64slice;
+// volatile const u64 attr_type_float64slice;
+// volatile const u64 attr_type_stringslice;
 
 /* Defintions should mimic structs defined in go.opentelemetry.io/otel/attribute */
 
@@ -66,21 +66,21 @@ static __always_inline bool set_attr_value(otel_attirbute_t *attr, go_otel_attr_
 {
 	u64 vtype = go_attr_value->vtype;
 
-	if (vtype == attr_type_invalid) {
+	if (vtype == 0) {
 		bpf_printk("Invalid attribute value type\n");
 		return false;
 	}
 
 	// Constant size values
-	if (vtype == attr_type_bool ||
-		vtype == attr_type_int64 ||
-		vtype == attr_type_float64) {
+	if (vtype == 0 ||
+		vtype == 0 ||
+		vtype == 0) {
 		bpf_probe_read(attr->value, sizeof(s64), &go_attr_value->numeric);
 		return true;
 	}
 
 	// String values
-	if (vtype == attr_type_string) {
+	if (vtype == 0) {
 		if (go_attr_value->string.len >= OTEL_ATTRIBUTE_VALUE_MAX_LEN) {
 			bpf_printk("Aattribute string value is too long\n");
 			return false;
@@ -116,7 +116,7 @@ static __always_inline void convert_go_otel_attributes(void *attrs_buf, u64 slic
 		// Read the value struct
 		bpf_probe_read(&go_attr_value, sizeof(go_otel_attr_value_t), &go_attr[go_attr_index].value);
 
-		if (go_attr_value.vtype == attr_type_invalid) {
+		if (go_attr_value.vtype == 0) {
 			continue;
 		}
 

+ 73 - 31
ebpftracer/ebpf/utrace/go/net/client.probe.bpf.c

@@ -51,15 +51,15 @@ struct
 //} events SEC(".maps");
 
 // Injected in init
-volatile const u64 method_ptr_pos;
-volatile const u64 url_ptr_pos;
-volatile const u64 path_ptr_pos;
-volatile const u64 headers_ptr_pos;
-volatile const u64 ctx_ptr_pos;
-volatile const u64 buckets_ptr_pos;
-volatile const u64 status_code_pos;
-volatile const u64 request_host_pos;
-volatile const u64 request_proto_pos;
+// volatile const u64 method_ptr_pos;
+// volatile const u64 url_ptr_pos;
+// volatile const u64 path_ptr_pos;
+// volatile const u64 headers_ptr_pos;
+// volatile const u64 ctx_ptr_pos;
+// volatile const u64 buckets_ptr_pos;
+// volatile const u64 status_code_pos;
+// volatile const u64 request_host_pos;
+// volatile const u64 request_proto_pos;
 
 static __always_inline long inject_header(void* headers_ptr, struct span_context* propagated_ctx) {
     // Read the key-value count - this field must be the first one in the hmap struct as documented in src/runtime/map.go
@@ -83,8 +83,16 @@ static __always_inline long inject_header(void* headers_ptr, struct span_context
     if (!bucket_map_value) {
         return -1;
     }
+    __u64 pid_tgid = bpf_get_current_pid_tgid();
+	__u32 tgid = pid_tgid >> 32;
+	struct ebpf_proc_info *proc_info =
+			bpf_map_lookup_elem(&proc_info_map, &tgid);
+    if(!proc_info)
+    {
+        return -1;
+    }
 
-    void *buckets_ptr_ptr = (void*) (headers_ptr + buckets_ptr_pos);
+    void *buckets_ptr_ptr = (void*) (headers_ptr + proc_info->buckets_ptr_pos);
     void *bucket_ptr = 0; // The actual pointer to the buckets
 
     if (curr_keyvalue_count == 0) {
@@ -185,7 +193,16 @@ static __always_inline long cw_inject_header(void* headers_ptr, struct apm_span_
         return -1;
     }
 
-    void *buckets_ptr_ptr = (void*) (headers_ptr + buckets_ptr_pos);
+    __u64 pid_tgid = bpf_get_current_pid_tgid();
+	__u32 tgid = pid_tgid >> 32;
+	struct ebpf_proc_info *proc_info =
+			bpf_map_lookup_elem(&proc_info_map, &tgid);
+    if(!proc_info)
+    {
+        return -1;
+    }
+
+    void *buckets_ptr_ptr = (void*) (headers_ptr + proc_info->buckets_ptr_pos);
     void *bucket_ptr = 0; // The actual pointer to the buckets
 
     if (curr_keyvalue_count == 0) {
@@ -286,8 +303,16 @@ static __always_inline long cw_inject_header2(void* headers_ptr, struct apm_span
     if (!bucket_map_value) {
         return -1;
     }
+    __u64 pid_tgid = bpf_get_current_pid_tgid();
+	__u32 tgid = pid_tgid >> 32;
+	struct ebpf_proc_info *proc_info =
+			bpf_map_lookup_elem(&proc_info_map, &tgid);
+    if(!proc_info)
+    {
+        return -1;
+    }
 
-    void *buckets_ptr_ptr = (void*) (headers_ptr + buckets_ptr_pos);
+    void *buckets_ptr_ptr = (void*) (headers_ptr + proc_info->buckets_ptr_pos);
     void *bucket_ptr = 0; // The actual pointer to the buckets
 
     if (curr_keyvalue_count == 0) {
@@ -374,8 +399,17 @@ int uprobe_Transport_roundTrip(struct pt_regs *ctx) {
     u64 request_pos = 2;
     void *req_ptr = get_argument(ctx, request_pos);
 
+    __u64 pid_tgid = bpf_get_current_pid_tgid();
+	__u32 tgid = pid_tgid >> 32;
+	struct ebpf_proc_info *proc_info =
+			bpf_map_lookup_elem(&proc_info_map, &tgid);
+    if(!proc_info)
+    {
+        return 0;
+    }
+
     // Get parent if exists
-    void *context_ptr_val = get_Go_context(ctx, 2, ctx_ptr_pos, false);
+    void *context_ptr_val = get_Go_context(ctx, 2, proc_info->ctx_ptr_pos, false);
     if (context_ptr_val == NULL)
     {
         return 0;
@@ -387,7 +421,7 @@ int uprobe_Transport_roundTrip(struct pt_regs *ctx) {
         cw_bpf_debug("uprobe/Transport_RoundTrip already tracked with the current context");
         return 0;
     }
-
+    // return 0;
     u32 map_id = 0;
     struct http_request_t *httpReq = bpf_map_lookup_elem(&http_client_uprobe_storage_map, &map_id);
     if (httpReq == NULL)
@@ -399,7 +433,7 @@ int uprobe_Transport_roundTrip(struct pt_regs *ctx) {
     __builtin_memset(httpReq, 0, sizeof(struct http_request_t));
     httpReq->start_time = bpf_ktime_get_ns();
 
-    struct span_context *parent_span_ctx = get_parent_span_context(context_ptr_val);
+    /*struct span_context *parent_span_ctx = get_parent_span_context(context_ptr_val);
     if (parent_span_ctx != NULL) {
         cw_bpf_debug("[Client] parent_span_ctx != NULL");
 
@@ -415,7 +449,6 @@ int uprobe_Transport_roundTrip(struct pt_regs *ctx) {
 //		    httpReq->sc = generate_span_context();
 //	    }
 
-
 	    struct apm_span_context *cw_psc = cw_get_parent_tracking_span();
 		if(cw_psc){
 //			httpReq->apm_sc = *cw_sc;
@@ -432,26 +465,25 @@ int uprobe_Transport_roundTrip(struct pt_regs *ctx) {
 //			generate_random_bytes(httpReq->sc.SpanID, SPAN_ID_SIZE);
 		}
     }
-
-    if (!get_go_string_from_user_ptr((void *)(req_ptr+method_ptr_pos), httpReq->method, sizeof(httpReq->method))) {
+    if (!get_go_string_from_user_ptr((void *)(req_ptr+proc_info->method_ptr_pos), httpReq->method, sizeof(httpReq->method))) {
         cw_bpf_debug("uprobe_Transport_roundTrip: Failed to get method from request");
         return 0;
     }
 
     // get path from Request.URL
     void *url_ptr = 0;
-    bpf_probe_read(&url_ptr, sizeof(url_ptr), (void *)(req_ptr+url_ptr_pos));
-    if (!get_go_string_from_user_ptr((void *)(url_ptr+path_ptr_pos), httpReq->path, sizeof(httpReq->path))) {
+    bpf_probe_read(&url_ptr, sizeof(url_ptr), (void *)(req_ptr+proc_info->url_ptr_pos));
+    if (!get_go_string_from_user_ptr((void *)(url_ptr+proc_info->path_ptr_pos), httpReq->path, sizeof(httpReq->path))) {
         cw_bpf_debug("uprobe_Transport_roundTrip: Failed to get path from Request.URL");
         return 0;
     }
 
     // get host from Request
-    if (!get_go_string_from_user_ptr((void *)(req_ptr+request_host_pos), httpReq->host, sizeof(httpReq->host))) {
+    if (!get_go_string_from_user_ptr((void *)(req_ptr+proc_info->request_host_pos), httpReq->host, sizeof(httpReq->host))) {
         cw_bpf_debug("uprobe_Transport_roundTrip: Failed to get host from Request");
     }
 	// TODO set request_host_pos
-	cw_bpf_debug("[Client] httpReq->host:%llu",request_host_pos);
+	cw_bpf_debug("[Client] httpReq->host:%llu",proc_info->request_host_pos);
 //	for (int i = 0; i < MAX_HOSTNAME_SIZE; ++i) {
 //		if (httpReq->host[i] == '\0') {
 //			break;
@@ -472,10 +504,10 @@ int uprobe_Transport_roundTrip(struct pt_regs *ctx) {
 		copy_byte_arrays(trace_conf->app_id, httpReq->apm_sc.app_id, APM_APP_ID_SIZE);
 	}
 
-	__u64 pid_tgid = bpf_get_current_pid_tgid();
-	__u32 tgid = pid_tgid >> 32;
-	struct ebpf_proc_info *proc_info =
-			bpf_map_lookup_elem(&proc_info_map, &tgid);
+	// __u64 pid_tgid = bpf_get_current_pid_tgid();
+	// __u32 tgid = pid_tgid >> 32;
+	// struct ebpf_proc_info *proc_info =
+	// 		bpf_map_lookup_elem(&proc_info_map, &tgid);
 	if (proc_info) {
 		for (int i = 0; i < 8; ++i) {
 //			cw_bpf_debug("[Client] instance_id:%02x", proc_info->instance_id[i]);
@@ -487,13 +519,13 @@ int uprobe_Transport_roundTrip(struct pt_regs *ctx) {
 	set_assumed_app_id_arrays(httpReq->host, httpReq->apm_sc.assumed_app_id, APM_ASSUMED_APP_ID_STRING_SIZE);
 	cw_save_current_tracking_span(&httpReq->apm_sc);
 	// get proto from Request
-    if (!get_go_string_from_user_ptr((void *)(req_ptr+request_proto_pos), httpReq->proto, sizeof(httpReq->proto))) {
+    if (!get_go_string_from_user_ptr((void *)(req_ptr+proc_info->request_proto_pos), httpReq->proto, sizeof(httpReq->proto))) {
         cw_bpf_debug("uprobe_Transport_roundTrip: Failed to get proto from Request");
     }
 
     // get headers from Request
     void *headers_ptr = 0;
-    bpf_probe_read(&headers_ptr, sizeof(headers_ptr), (void *)(req_ptr+headers_ptr_pos));
+    bpf_probe_read(&headers_ptr, sizeof(headers_ptr), (void *)(req_ptr+proc_info->headers_ptr_pos));
 //    long res = inject_header(headers_ptr, &httpReq->sc);
 //    long res = cw_inject_header(headers_ptr, &httpReq->apm_sc);
 //    if (res < 0) {
@@ -502,7 +534,7 @@ int uprobe_Transport_roundTrip(struct pt_regs *ctx) {
 	long res2 = cw_inject_header2(headers_ptr, &httpReq->apm_sc);
 	if (res2 < 0) {
 		cw_bpf_debug("uprobe_Transport_roundTrip: Failed to inject header");
-	}
+	}*/
 
     // Write event
 //    bpf_map_update_elem(&http_events, &key, httpReq, 0);
@@ -517,7 +549,17 @@ int uprobe_Transport_roundTrip_Returns(struct pt_regs *ctx) {
 	cw_bpf_debug("[Uprobe HTTP Client] start Return----------");
 	clear_current_span_context();
     u64 end_time = bpf_ktime_get_ns();
-    void *req_ctx_ptr = get_Go_context(ctx, 2, ctx_ptr_pos, false);
+
+    __u64 pid_tgid = bpf_get_current_pid_tgid();
+	__u32 tgid = pid_tgid >> 32;
+	struct ebpf_proc_info *proc_info =
+			bpf_map_lookup_elem(&proc_info_map, &tgid);
+    if(!proc_info)
+    {
+        return 0;
+    }
+
+    void *req_ctx_ptr = get_Go_context(ctx, 2, proc_info->ctx_ptr_pos, false);
     void *key = get_consistent_key(ctx, req_ctx_ptr);
 
     struct http_request_t *http_req_span = bpf_map_lookup_elem(&http_events, &key);
@@ -530,7 +572,7 @@ int uprobe_Transport_roundTrip_Returns(struct pt_regs *ctx) {
         // Getting the returned response
         void *resp_ptr = get_argument(ctx, 1);
         // Get status code from response
-        bpf_probe_read(&http_req_span->status_code, sizeof(http_req_span->status_code), (void *)(resp_ptr + status_code_pos));
+        bpf_probe_read(&http_req_span->status_code, sizeof(http_req_span->status_code), (void *)(resp_ptr + proc_info->status_code_pos));
     }
 
     http_req_span->end_time = end_time;

+ 48 - 70
ebpftracer/ebpf/utrace/go/net/server.probe.bpf.c

@@ -93,17 +93,9 @@ struct {
 } events SEC(".maps");
 
 // Injected in init
-volatile const u64 method_ptr_pos;
-volatile const u64 url_ptr_pos;
-volatile const u64 path_ptr_pos;
-volatile const u64 ctx_ptr_pos;
-volatile const u64 headers_ptr_pos;
-volatile const u64 buckets_ptr_pos;
-volatile const u64 req_ptr_pos;
-volatile const u64 status_code_pos;
-volatile const u64 remote_addr_pos;
-volatile const u64 host_pos;
-volatile const u64 proto_pos;
+// volatile const u64 ctx_ptr_pos;
+// volatile const u64 headers_ptr_pos;
+// volatile const u64 buckets_ptr_pos;
 //for (int i = 0; i < W3C_KEY_LENGTH; i++)
 //{
 //if (current_header_key[i] != "traceparent"[i]){
@@ -135,8 +127,16 @@ static __always_inline struct span_context *extract_context_from_req_headers(voi
 		return NULL;
 	}
 	u64 bucket_count = 1 << log_2_bucket_count;
+	__u64 pid_tgid = bpf_get_current_pid_tgid();
+	__u32 tgid = pid_tgid >> 32;
+	struct ebpf_proc_info *proc_info =
+			bpf_map_lookup_elem(&proc_info_map, &tgid);
+    if(!proc_info)
+    {
+        return 0;
+    }
 	void *header_buckets;
-	res = bpf_probe_read(&header_buckets, sizeof(header_buckets), (void *) (headers_ptr + buckets_ptr_pos));
+	res = bpf_probe_read(&header_buckets, sizeof(header_buckets), (void *) (headers_ptr + proc_info->buckets_ptr_pos));
 	if (res < 0) {
 		return NULL;
 	}
@@ -153,13 +153,14 @@ static __always_inline struct span_context *extract_context_from_req_headers(voi
 		if (res < 0) {
 			continue;
 		}
-		for (u32 i = 0; i < 8; i++) {
+		/*for (u32 i = 0; i < 8; i++) {
 			if (map_value->tophash[i] == 0) {
 				continue;
 			}
 			if (map_value->keys[i].len != CW_HEADER_KEY_LENGTH) {
 				continue;
 			}
+			
 			char current_header_key[CW_HEADER_KEY_LENGTH];
 			bpf_probe_read(current_header_key, sizeof(current_header_key), map_value->keys[i].str);
 			for (int i = 0; i < CW_HEADER_KEY_LENGTH; i++) {
@@ -167,12 +168,7 @@ static __always_inline struct span_context *extract_context_from_req_headers(voi
 					goto outer_loop;
 				}
 			}
-//			if (!bpf_memcmp(current_header_key, "traceparent", W3C_KEY_LENGTH) && !bpf_memcmp(current_header_key, "Traceparent", W3C_KEY_LENGTH))
-//			{
-//				cw_bpf_debug("not find it");
-//				continue;
-//			}
-//			cw_bpf_debug("find it:%s", map_value->keys[i].str);
+			
 			void *traceparent_header_value_ptr = map_value->values[i].array;
 			struct go_string_ot traceparent_header_value_go_str;
 			res = bpf_probe_read(&traceparent_header_value_go_str, sizeof(traceparent_header_value_go_str),
@@ -183,22 +179,19 @@ static __always_inline struct span_context *extract_context_from_req_headers(voi
 			if (res < 0) {
 				return NULL;
 			}
-//			if (traceparent_header_value_go_str.len != W3C_VAL_LENGTH) {
-//				continue;
-//			}
-			char traceparent_header_value[130];
+			
+			// char traceparent_header_value[130];
+			int key = 0;
+			char *traceparent_header_value;
+			traceparent_header_value = bpf_map_lookup_elem(&go_large_array_map, &key);
+
 			res = bpf_probe_read(&traceparent_header_value, sizeof(traceparent_header_value),
 			                     traceparent_header_value_go_str.str);
-			// 00-95b5ec2b81e2374a4a27ce36ab71d349-18f65a5a3ab22213-02��c�����c����@c;
-//			cw_bpf_debug("traceparent_header_value11:[%s]", traceparent_header_value);
-
-//			cw_bpf_debug("111111111111111111:[%d]", range.start[1]);
 
 
 			if (res < 0) {
 				return NULL;
 			}
-
 			struct span_context *parent_span_context = bpf_map_lookup_elem(&parent_span_context_storage_map, &map_id);
 			if (!parent_span_context) {
 				cw_bpf_debug("no parent_span_context");
@@ -217,42 +210,10 @@ static __always_inline struct span_context *extract_context_from_req_headers(voi
 			// 保存sc
 			cw_save_parent_tracking_span(cw_parent_span_context);
 
-
-//            for (int i = 0; i < TRACE_ID_SIZE; i++) {
-//                cw_bpf_debug("%02x", parent_span_context->TraceID[i]);
-//            }
-//			char val[10];
-//			char *out = val;
-//			// Write trace id
-//			bytes_to_hex_string(cw_parent_span_context->type_from, 5, out);
-//			for (int i = 0; i < 10; ++i) {
-//				cw_bpf_debug("traceid--%c",val[i]);
-//			}
-
-
-
-//
-//			for (int i = 0; i < 1; i++) {
-//				cw_bpf_debug("type_from------%02x", cw_parent_span_context->type_from[i]);
-//			}
-//
-//			char val[2];
-//			char *out = val;
-////			// Write trace id
-//			bytes_to_hex_string(cw_parent_span_context->type_from, 1, out);
-//
-//			cw_bpf_debug("type_from1--%s", out);
-
-//			for (int i = 0; i < 10; ++i) {
-//				cw_bpf_debug("traceid--%c",val[i]);
-//			}
-
-//			cw_bpf_debug("parent_span_context-TraceID2:%s", parent_span_context->TraceID);
-//			cw_bpf_debug("parent_span_context-SpanID2:%s", parent_span_context->SpanID);
 			return parent_span_context;
 			outer_loop:
 			continue;
-		}
+		}*/
 	}
 	return NULL;
 }
@@ -262,14 +223,23 @@ static __always_inline struct span_context *extract_context_from_req_headers(voi
 SEC("uprobe/HandlerFunc_ServeHTTP")
 int uprobe_HandlerFunc_ServeHTTP(struct pt_regs *ctx) {
 	cw_bpf_debug("[uprobe_HandlerFunc_ServeHTTP]");
-	void *req_ctx_ptr = get_Go_context(ctx, 4, ctx_ptr_pos, false);
+	__u64 pid_tgid = bpf_get_current_pid_tgid();
+	__u32 tgid = pid_tgid >> 32;
+	struct ebpf_proc_info *proc_info =
+			bpf_map_lookup_elem(&proc_info_map, &tgid);
+    if(!proc_info)
+    {
+        return 0;
+    }
+
+	void *req_ctx_ptr = get_Go_context(ctx, 4, proc_info->ctx_ptr_pos, false);
 	void *key = get_consistent_key(ctx, req_ctx_ptr);
 	void *httpReq_ptr = bpf_map_lookup_elem(&http_server_uprobes, &key);
 	if (httpReq_ptr != NULL) {
 		cw_bpf_debug("uprobe/HandlerFunc_ServeHTTP already tracked with the current request");
 		return 0;
 	}
-
+	
 	u32 map_id = 0;
 	struct uprobe_data_t *uprobe_data = bpf_map_lookup_elem(&http_server_uprobe_storage_map, &map_id);
 	if (uprobe_data == NULL) {
@@ -288,7 +258,7 @@ int uprobe_HandlerFunc_ServeHTTP(struct pt_regs *ctx) {
 
 	// Propagate context
 	void *req_ptr = get_argument(ctx, 4);
-	struct span_context *parent_ctx = extract_context_from_req_headers((void *) (req_ptr + headers_ptr_pos));
+	struct span_context *parent_ctx = extract_context_from_req_headers((void *) (req_ptr + proc_info->headers_ptr_pos));
 	if (parent_ctx != NULL) {
 		// found parent context in http headers
 		http_server_span->psc = *parent_ctx;
@@ -303,13 +273,12 @@ int uprobe_HandlerFunc_ServeHTTP(struct pt_regs *ctx) {
 		if (!cw_parent_span_context) {
 			return 0;
 		}
-		struct apm_span_context context = {};
-		generate_random_bytes(context.trace_id, TRACE_ID_SIZE);
-//		generate_random_bytes(context.span_id, SPAN_ID_SIZE);
+		// struct apm_span_context context = {};
+		generate_random_bytes(cw_parent_span_context->trace_id, TRACE_ID_SIZE);
+		// generate_random_bytes(context.span_id, SPAN_ID_SIZE);
 		// 保存 trace_id 到psc
-		cw_save_parent_tracking_span(&context);
+		cw_save_parent_tracking_span(cw_parent_span_context);
 	}
-
 	if (req_ctx_ptr == NULL) {
 //		cw_bpf_debug("uprobe/HandlerFunc_ServeHTTP: req_ctx_ptr is NULL");
 		return 0;
@@ -350,7 +319,16 @@ SEC("uprobe/HandlerFunc_ServeHTTP")
 int uprobe_HandlerFunc_ServeHTTP_Returns(struct pt_regs *ctx) {
 	cw_bpf_debug("[uprobe_HandlerFunc_ServeHTTP_Returns]");
 //	u64 end_time = bpf_ktime_get_ns();
-	void *req_ctx_ptr = get_Go_context(ctx, 4, ctx_ptr_pos, false);
+	__u64 pid_tgid = bpf_get_current_pid_tgid();
+	__u32 tgid = pid_tgid >> 32;
+	struct ebpf_proc_info *proc_info =
+			bpf_map_lookup_elem(&proc_info_map, &tgid);
+    if(!proc_info)
+    {
+        return 0;
+    }
+
+	void *req_ctx_ptr = get_Go_context(ctx, 4, proc_info->ctx_ptr_pos, false);
 	void *key = get_consistent_key(ctx, req_ctx_ptr);
 
 	struct uprobe_data_t *uprobe_data = bpf_map_lookup_elem(&http_server_uprobes, &key);

+ 3 - 6
ebpftracer/ebpf/utrace/java/net/client.probe.bpf.c

@@ -169,19 +169,16 @@ static __inline int insertHeader(struct sock_t *map_data,void * jbytechar_ptr,vo
 
 SEC("uprobe/Java_java_net_SocketOutputStream_socketWrite0")
 int uprobe_Java_java_net_SocketOutputStream_socketWrite0(struct pt_regs *ctx) {
-
 	// 捕获第六个参数 data_count
 	int data_count = PT_REGS_PARM6(ctx);
-
 	if (data_count < MIN_LEN) {
 		return 0;
 	}
 
 	bpf_printk("--------");
 
-
 //	void *len_from_rsp_ptr = (void *) PT_REGS_RSP(ctx) - 65640 +8 ;
-	void *len_from_rbp_ptr = (void *) (PT_REGS_RBP(ctx)) - 0x10058;
+	/*void *len_from_rbp_ptr = (void *) (PT_REGS_RBP(ctx)) - 0x10058;
 //	void *jbytearray_from_rbp_p_p_p = (void *) (PT_REGS_RBP(ctx)) - 0x10050;
 
 //	long res;
@@ -254,7 +251,7 @@ int uprobe_Java_java_net_SocketOutputStream_socketWrite0(struct pt_regs *ctx) {
 	// http协议过滤
 	if (!is_http_request2(map_data->payload, map_data->size)) {
 		return -1;
-	}
+	}*/
 //	char syscall_infer_buf[100];
 ///*实现2*/
 /*实现2
@@ -347,7 +344,7 @@ int uprobe_Java_java_net_SocketOutputStream_socketWrite0(struct pt_regs *ctx) {
 
 /*实现1*/
 
-	insertHeader(map_data,jbytechar_ptr,len_from_rbp_ptr);
+	// insertHeader(map_data,jbytechar_ptr,len_from_rbp_ptr);*/
 
 
 //	updataSocket(map_data_res,jbytechar_ptr,len_from_rbp_ptr);

+ 48 - 7
ebpftracer/ebpf/utrace/java/net/server.probe.bpf.c

@@ -38,7 +38,13 @@ struct {
 
 static __inline int is_http_header(const char *data)
 {
-	for (int i = 0; i < 512; i++)
+	int i;
+	if(data == NULL)
+	{
+		return 0;
+	}
+	#pragma unroll
+	for (i = 0; i < 200; i++)
 	{
 		if (data[i] == '\r' &&
 		    data[i + 1] == '\n' &&
@@ -54,6 +60,41 @@ static __inline int is_http_header(const char *data)
 			return i + 11;
 		}
 	}
+	// #pragma unroll
+	// for (i = 200; i < 400; i++)
+	// {
+	// 	if (data[i] == '\r' &&
+	// 	    data[i + 1] == '\n' &&
+	// 	    data[i + 2] == 'c' &&
+	// 	    data[i + 3] == 'w' &&
+	// 	    data[i + 4] == 't' &&
+	// 	    data[i + 5] == 'r' &&
+	// 	    data[i + 6] == 'a' &&
+	// 	    data[i + 7] == 'c' &&
+	// 	    data[i + 8] == 'e' &&
+	// 		data[i + 9] == ':' &&
+	// 		data[i + 10] == ' ') {
+	// 		return i + 11;
+	// 	}
+	// }
+	// #pragma unroll
+	// for (i = 400; i < 512; i++)
+	// {
+	// 	if (data[i] == '\r' &&
+	// 	    data[i + 1] == '\n' &&
+	// 	    data[i + 2] == 'c' &&
+	// 	    data[i + 3] == 'w' &&
+	// 	    data[i + 4] == 't' &&
+	// 	    data[i + 5] == 'r' &&
+	// 	    data[i + 6] == 'a' &&
+	// 	    data[i + 7] == 'c' &&
+	// 	    data[i + 8] == 'e' &&
+	// 		data[i + 9] == ':' &&
+	// 		data[i + 10] == ' ') {
+	// 		return i + 11;
+	// 	}
+	// }
+	
 	return 0;
 }
 
@@ -68,6 +109,7 @@ int uprobe_ret_Java_sun_nio_ch_FileDispatcherImpl_read0(struct pt_regs *ctx) {
 	
 	//x/s addr
 	int key = 0;
+	int offset = 0;
 	struct sock_t *map_data = bpf_map_lookup_elem(&socket_heap, &key);
 	if (!map_data) {
 		return 0;
@@ -80,8 +122,7 @@ int uprobe_ret_Java_sun_nio_ch_FileDispatcherImpl_read0(struct pt_regs *ctx) {
 
 	bpf_printk("read data is : %s\n", map_data->payload);
 
-
-	int offset = is_http_header(map_data->payload);
+	offset = is_http_header(map_data->payload);
 	bpf_printk("found the header, %d\n", offset);
 	char *data;
 	data = bpf_map_lookup_elem(&large_array_map, &key);
@@ -94,14 +135,14 @@ int uprobe_ret_Java_sun_nio_ch_FileDispatcherImpl_read0(struct pt_regs *ctx) {
 	}
 	if(offset > 0 && offset < 512 - 123)
 	{
-		__builtin_memcpy(data, &(map_data->payload[offset]), 123);
-		bpf_printk("found the data, %s\n", data);
+		// __builtin_memcpy(data, &(map_data->payload[offset]), 123);
+		// bpf_printk("found the data, %s\n", data);
 
-		cw_string_to_span_context(data, cw_parent_span_context);
+		// cw_string_to_span_context(data, cw_parent_span_context);
 	}
 	else
 	{
-		generate_random_bytes(cw_parent_span_context->trace_id, TRACE_ID_SIZE);
+		// generate_random_bytes(cw_parent_span_context->trace_id, TRACE_ID_SIZE);
 	}
 	// 保存 trace_id 到psc
 	cw_save_parent_tracking_span(cw_parent_span_context);

+ 8 - 0
ebpftracer/tls.go

@@ -217,6 +217,14 @@ func (t *Tracer) AttachGoTlsUprobes(pid uint32, insID utils.ID) []link.Link {
 			info.CryptoTLSConnItab = uint64(0)
 			info.CredentialsSyscallConnItab = uint64(0)
 			info.InstanceId = insID.HashtVal
+			info.BucketsPtrPos = uint64(16)
+			info.CtxPtrPos = uint64(232)
+			info.HeadersPtrPos = uint64(56)
+			info.RequestHostPos = uint64(128)
+			info.MethodPtrPos = uint64(0)
+			info.PathPtrPos = uint64(56)
+			info.StatusCodePos = uint64(120)
+			info.UrlPtrPos = uint64(16)
 			// 获取内存地址
 			allocDetails, err := tracer.Allocate(int(pid))
 			if err == nil && allocDetails != nil {

+ 2 - 2
ebpftracer/tracer.go

@@ -235,7 +235,7 @@ func (t *Tracer) ebpf(ch chan<- Event) error {
 		}
 	}
 	if len(prg) == 0 {
-		return fmt.Errorf("unsupported kernel version: %s", t.kernelVersion)
+		return fmt.Errorf("kv is %s, unsupported kernel version: %s", kv, t.kernelVersion)
 	}
 	_, debugFsErr := os.Stat("/sys/kernel/debug/tracing")
 	_, traceFsErr := os.Stat("/sys/kernel/tracing")
@@ -256,7 +256,7 @@ func (t *Tracer) ebpf(ch chan<- Event) error {
 	}
 	tracer.MapInit(collectionSpec, opts)
 	// TODO 多进程
-	tracer.SetConstants(collectionSpec)
+	// tracer.SetConstants(collectionSpec)
 	c, err := ebpf.NewCollectionWithOptions(collectionSpec, *opts)
 	if err != nil {
 		var verr *ebpf.VerifierError

+ 9 - 0
ebpftracer/tracer/common.go

@@ -126,6 +126,7 @@ type traceConf struct {
 	GoTracingTimeout       uint64
 	IOEventCollectMode     uint64
 	IOEventMinimalDuartion uint64
+	TotalCpus			   uint64
 	HostID                 utils.HashByte
 	APPID                  utils.HashByte
 }
@@ -160,6 +161,14 @@ type EbpfProcInfo struct {
 	StartAddr                  uint64
 	EndAddr                    uint64
 	InstanceId                 utils.HashByte
+	BucketsPtrPos			   uint64
+	CtxPtrPos				   uint64
+	HeadersPtrPos			   uint64
+	RequestHostPos			   uint64
+	MethodPtrPos			   uint64
+	PathPtrPos				   uint64
+	StatusCodePos			   uint64
+	UrlPtrPos				   uint64
 }
 
 type allowPortBitmap struct {

+ 19 - 21
ebpftracer/tracer/socket.go

@@ -153,6 +153,7 @@ func set_conf_map_default(collectionSpec *ebpf.CollectionSpec, opts *ebpf.Collec
 
 	uidBase := uint64(time.Now().UnixNano()/int64(time.Millisecond)) & 0xffffffffffffff
 	numCPU := runtime.NumCPU()
+	nCPU, _ := utils.GetCPUCount()
 	tConf := make([]any, numCPU)
 	for i := range tConf {
 		socketID := uint64(i)<<56 | uint64(uidBase)
@@ -166,6 +167,7 @@ func set_conf_map_default(collectionSpec *ebpf.CollectionSpec, opts *ebpf.Collec
 			IOEventMinimalDuartion: 1000000,
 			HostID:                 charHostID,
 			APPID:                  charAppID,
+			TotalCpus:				uint64(nCPU),
 		}
 		tConf[i] = tracerConf
 	}
@@ -326,30 +328,26 @@ func update_offsets_table(collectionSpec *ebpf.CollectionSpec, opts *ebpf.Collec
 }
 
 func SetConstants(collectionSpec *ebpf.CollectionSpec) {
-	nCPU, err := utils.GetCPUCount()
-	consts := map[string]interface{}{
+	// nCPU, err := utils.GetCPUCount()
+	// consts := map[string]interface{}{
 		// TODO go Process
-		"buckets_ptr_pos":  int64(16),
-		"ctx_ptr_pos":      int64(232),
-		"headers_ptr_pos":  int64(56),
-		"host_pos":         int64(128),
-		"request_host_pos": int64(128),
-		"is_registers_abi": true,
-		"method_ptr_pos":   int64(0),
-		"path_ptr_pos":     int64(56),
-		"proto_pos":        int64(24),
-		"remote_addr_pos":  int64(176),
-		"req_ptr_pos":      int64(8),
-		"status_code_pos":  int64(120),
-		"url_ptr_pos":      int64(16),
+		// "buckets_ptr_pos":  int64(16),
+		// "ctx_ptr_pos":      int64(232),
+		// "headers_ptr_pos":  int64(56),
+		// "request_host_pos": int64(128),
+		// "is_registers_abi": true,
+		// "method_ptr_pos":   int64(0),
+		// "path_ptr_pos":     int64(56),
+		// "status_code_pos":  int64(120),
+		// "url_ptr_pos":      int64(16),
 
 		// TODO 全局 ***
-		"total_cpus": int64(nCPU),
+		// "total_cpus": int64(nCPU),
 		//"apm_app_id":  int64(0),
 		//"apm_host_id": int64(0),
-	}
-	err = collectionSpec.RewriteConstants(consts)
-	if err != nil {
-		fmt.Println("err", err, consts)
-	}
+	// }
+	// err = collectionSpec.RewriteConstants(consts)
+	// if err != nil {
+	// 	fmt.Println("err", err, consts)
+	// }
 }

+ 4 - 4
go.mod

@@ -14,10 +14,13 @@ require (
 	github.com/docker/docker v25.0.0+incompatible
 	github.com/florianl/go-conntrack v0.3.0
 	github.com/go-kit/log v0.2.1
+	github.com/go-logr/logr v1.4.1
 	github.com/grafana/pyroscope/ebpf v0.4.1
+	github.com/hashicorp/go-version v1.6.0
 	github.com/jpillora/backoff v1.0.0
 	github.com/mdlayher/taskstats v0.0.0-20230712191918-387b3d561d14
 	github.com/opencontainers/runtime-spec v1.0.3-0.20210326190908-1c3f411f0417
+	github.com/pkg/errors v0.9.1
 	github.com/prometheus/client_golang v1.18.0
 	github.com/prometheus/client_model v0.5.0
 	github.com/prometheus/common v0.46.0
@@ -36,6 +39,7 @@ require (
 	golang.org/x/arch v0.4.0
 	golang.org/x/mod v0.16.0
 	golang.org/x/net v0.22.0
+	golang.org/x/sync v0.6.0
 	golang.org/x/sys v0.18.0
 	golang.org/x/time v0.5.0
 	gopkg.in/alecthomas/kingpin.v2 v2.2.6
@@ -77,7 +81,6 @@ require (
 	github.com/felixge/httpsnoop v1.0.4 // indirect
 	github.com/fsnotify/fsnotify v1.7.0 // indirect
 	github.com/go-logfmt/logfmt v0.6.0 // indirect
-	github.com/go-logr/logr v1.4.1 // indirect
 	github.com/go-logr/stdr v1.2.2 // indirect
 	github.com/go-ole/go-ole v1.2.6 // indirect
 	github.com/go-openapi/analysis v0.21.4 // indirect
@@ -102,7 +105,6 @@ require (
 	github.com/google/uuid v1.5.0 // indirect
 	github.com/grafana/regexp v0.0.0-20221123153739-15dc172cd2db // indirect
 	github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 // indirect
-	github.com/hashicorp/go-version v1.6.0 // indirect
 	github.com/hashicorp/golang-lru/v2 v2.0.5 // indirect
 	github.com/hashicorp/hcl v1.0.0 // indirect
 	github.com/ianlancetaylor/demangle v0.0.0-20230524184225-eabc099b10ab // indirect
@@ -138,7 +140,6 @@ require (
 	github.com/pelletier/go-toml/v2 v2.0.5 // indirect
 	github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 // indirect
 	github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect
-	github.com/pkg/errors v0.9.1 // indirect
 	github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
 	github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
 	github.com/prometheus/common/sigv4 v0.1.0 // indirect
@@ -170,7 +171,6 @@ require (
 	golang.org/x/crypto v0.21.0 // indirect
 	golang.org/x/exp v0.0.0-20240119083558-1b970713d09a // indirect
 	golang.org/x/oauth2 v0.16.0 // indirect
-	golang.org/x/sync v0.6.0 // indirect
 	golang.org/x/text v0.14.0 // indirect
 	golang.org/x/tools v0.19.0 // indirect
 	google.golang.org/appengine v1.6.8 // indirect