Prechádzať zdrojové kódy

Fixed #TASK_GK-2944 压测-去除多余打印

Carl 1 rok pred
rodič
commit
df5550ee39

+ 4 - 1
Makefile2

@@ -29,4 +29,7 @@ run:
 	ssh [email protected] 'cd /opt/github/euspace && TRACES_ENDPOINT=http://10.0.12.192:18080/docp/api/v2/data/receive ${FILTER} ./euspace --listen="0.0.0.0:8123"'
 send_run:
 	ssh [email protected] 'cd /opt/github/euspace && SEND=1 TRACES_ENDPOINT=http://10.0.12.192:18080/docp/api/v2/data/receive ${FILTER} ./euspace --listen="0.0.0.0:8123"'
-all: c go run
+all: c go
+
+only-build: c go-build
+	scp -P36000 ./euspace [email protected]:/root/carl

+ 1 - 1
containers/container_apm.go

@@ -83,7 +83,7 @@ func (c *Container) onL7RequestApm(pid uint32, fd uint64, timestamp uint64, r *l
 		return nil
 	}
 	conn := c.connectionsByPidFd[PidFd{Pid: pid, Fd: fd}]
-	fmt.Println("l7.connectionsByPidFd", conn, pid, fd)
+	//fmt.Println("l7.connectionsByPidFd", conn, pid, fd)
 
 	if conn == nil {
 		return nil

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

@@ -10,8 +10,8 @@
 #ifdef _DEBUG_MODE
 #define cw_bpf_debug(fmt, ...)                                 \
 ({                                                             \
-                               \
-  \
+    char ____fmt[] = fmt;                                      \
+    bpf_trace_printk(____fmt, sizeof(____fmt), ##__VA_ARGS__); \
 })
 #define debug(fmt, ...)                                        \
 ({                                                             \

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

@@ -389,6 +389,7 @@ int trace_enter_write(void *ctx, __u64 fd, __u16 is_tls, char *buf, __u64 size,
             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;
         }

+ 507 - 507
ebpftracer/ebpf/socket_trace.c

@@ -1376,488 +1376,488 @@ static __inline void process_syscall_data_vecs(struct pt_regs* ctx, __u64 id,
 /***********************************************************
  * BPF syscall probe/tracepoint function entry-points
  ***********************************************************/
-TPPROG(sys_enter_write) (struct syscall_comm_enter_ctx *ctx) {
-	__u64 id = bpf_get_current_pid_tgid();
-	int fd = (int)ctx->fd;
-	char *buf = (char *)ctx->buf;
-
-	struct data_args_t write_args = {};
-	write_args.source_fn = SYSCALL_FUNC_WRITE;
-	write_args.fd = fd;
-	write_args.buf = buf;
-	write_args.enter_ts = bpf_ktime_get_ns();
-	active_write_args_map__update(&id, &write_args);
-
-	return 0;
-}
-
-// /sys/kernel/debug/tracing/events/syscalls/sys_exit_write/format
-TPPROG(sys_exit_write) (struct syscall_comm_exit_ctx *ctx) {
-	__u64 id = bpf_get_current_pid_tgid();
-	ssize_t bytes_count = ctx->ret;
-	// Unstash arguments, and process syscall.
-	struct data_args_t* write_args = active_write_args_map__lookup(&id);
-	// Don't process FD 0-2 to avoid STDIN, STDOUT, STDERR.
-	if (write_args != NULL && write_args->fd > 2) {
-		write_args->bytes_count = bytes_count;
-		process_syscall_data((struct pt_regs *)ctx, id, T_EGRESS, write_args, bytes_count);
-	}
-
-	active_write_args_map__delete(&id);
-	return 0;
-}
-
-// ssize_t read(int fd, void *buf, size_t count);
-TPPROG(sys_enter_read) (struct syscall_comm_enter_ctx *ctx) {
-	__u64 id = bpf_get_current_pid_tgid();
-	int fd = (int)ctx->fd;
-	char *buf = (char *)ctx->buf;
-	// Stash arguments.
-	struct data_args_t read_args = {};
-	read_args.source_fn = SYSCALL_FUNC_READ;
-	read_args.fd = fd;
-	read_args.buf = buf;
-	read_args.enter_ts = bpf_ktime_get_ns();
-	read_args.tcp_seq = get_tcp_read_seq_from_fd(fd);
-	active_read_args_map__update(&id, &read_args);
-
-	return 0;
-}
-
-// /sys/kernel/debug/tracing/events/syscalls/sys_exit_read/format
-TPPROG(sys_exit_read) (struct syscall_comm_exit_ctx *ctx) {
-	__u64 id = bpf_get_current_pid_tgid();
-	ssize_t bytes_count = ctx->ret;
-	// Unstash arguments, and process syscall.
-	struct data_args_t* read_args = active_read_args_map__lookup(&id);
-	// Don't process FD 0-2 to avoid STDIN, STDOUT, STDERR.
-	if (read_args != NULL && read_args->fd > 2) {
-		read_args->bytes_count = bytes_count;
-		process_syscall_data((struct pt_regs *)ctx, id, T_INGRESS, read_args, bytes_count);
-	}
-
-	active_read_args_map__delete(&id);
-	return 0;
-}
-
-// ssize_t sendto(int sockfd, const void *buf, size_t len, int flags,
-//		const struct sockaddr *dest_addr, socklen_t addrlen);
-TPPROG(sys_enter_sendto) (struct syscall_comm_enter_ctx *ctx) {
-	__u64 id = bpf_get_current_pid_tgid();
-	int sockfd = (int)ctx->fd;
-	char *buf = (char *)ctx->buf;
-	// Stash arguments.
-	struct data_args_t write_args = {};
-	write_args.source_fn = SYSCALL_FUNC_SENDTO;
-	write_args.fd = sockfd;
-	write_args.buf = buf;
-	write_args.enter_ts = bpf_ktime_get_ns();
-	active_write_args_map__update(&id, &write_args);
-
-	return 0;
-}
-
-// /sys/kernel/debug/tracing/events/syscalls/sys_exit_sendto/format
-TPPROG(sys_exit_sendto) (struct syscall_comm_exit_ctx *ctx) {
-	__u64 id = bpf_get_current_pid_tgid();
-	ssize_t bytes_count = ctx->ret;
-
-	// 潜在的问题:如果sentto() addr是由TCP连接提供的,系统调用可能会忽略它,但我们仍然会跟踪它。在实践中,TCP连接不应该使用带addr参数的sendto()。
-	// 在手册页中:
-	//     如果sendto()用于连接模式(SOCK_STREAM, SOCK_SEQPACKET)套接字,参数
-	//     dest_addr和addrlen会被忽略(如果不是,可能会返回EISCONN错误空和0)
-	//
-	// Unstash arguments, and process syscall.
-	struct data_args_t* write_args = active_write_args_map__lookup(&id);
-	if (write_args != NULL) {
-		write_args->bytes_count = bytes_count;
-		process_syscall_data((struct pt_regs*)ctx, id, T_EGRESS, write_args, bytes_count);
-		active_write_args_map__delete(&id);
-	}
-
-	return 0;
-}
-
-// ssize_t recvfrom(int sockfd, void *buf, size_t len, int flags,
-//		  struct sockaddr *src_addr, socklen_t *addrlen);
-TPPROG(sys_enter_recvfrom) (struct syscall_comm_enter_ctx *ctx) {
-	// If flags contains MSG_PEEK, it is returned directly.
-	// ref : https://linux.die.net/man/2/recvfrom
-	if (ctx->flags & MSG_PEEK)
-		return 0;
-	__u64 id = bpf_get_current_pid_tgid();
-	int sockfd = (int)ctx->fd;
-	char *buf = (char *)ctx->buf;
-	// Stash arguments.
-	struct data_args_t read_args = {};
-	read_args.source_fn = SYSCALL_FUNC_RECVFROM;
-	read_args.fd = sockfd;
-	read_args.buf = buf;
-	read_args.enter_ts = bpf_ktime_get_ns();
-	read_args.tcp_seq = get_tcp_read_seq_from_fd(sockfd);
-	active_read_args_map__update(&id, &read_args);
-
-	return 0;
-}
-
-// /sys/kernel/debug/tracing/events/syscalls/sys_exit_recvfrom/format
-TPPROG(sys_exit_recvfrom) (struct syscall_comm_exit_ctx *ctx) {
-	__u64 id = bpf_get_current_pid_tgid();
-	ssize_t bytes_count = ctx->ret;
-
-	// Unstash arguments, and process syscall.
-	struct data_args_t* read_args = active_read_args_map__lookup(&id);
-	if (read_args != NULL) {
-		read_args->bytes_count = bytes_count;
-		process_syscall_data((struct pt_regs *)ctx, id, T_INGRESS, read_args, bytes_count);
-		active_read_args_map__delete(&id);
-	}
-
-	return 0;
-}
-
-// ssize_t sendmsg(int sockfd, const struct msghdr *msg, int flags);
-KPROG(__sys_sendmsg) (struct pt_regs* ctx) {
-	__u64 id = bpf_get_current_pid_tgid();
-	int sockfd = (int)PT_REGS_PARM1(ctx);
-	struct user_msghdr *msghdr_ptr = (struct user_msghdr *)PT_REGS_PARM2(ctx);
-
-	if (msghdr_ptr != NULL) {
-		// Stash arguments.
-		struct user_msghdr *msghdr, __msghdr;
-		bpf_probe_read(&__msghdr, sizeof(__msghdr), msghdr_ptr);
-		msghdr = &__msghdr;
-		// Stash arguments.
-		struct data_args_t write_args = {};
-		write_args.source_fn = SYSCALL_FUNC_SENDMSG;
-		write_args.fd = sockfd;
-		write_args.iov = msghdr->msg_iov;
-		write_args.iovlen = msghdr->msg_iovlen;
-		write_args.enter_ts = bpf_ktime_get_ns();
-		active_write_args_map__update(&id, &write_args);
-	}
-
-	return 0;
-}
-
-// /sys/kernel/debug/tracing/events/syscalls/sys_exit_sendmsg/format
-TPPROG(sys_exit_sendmsg) (struct syscall_comm_exit_ctx *ctx) {
-	__u64 id = bpf_get_current_pid_tgid();
-	ssize_t bytes_count = ctx->ret;
-	// Unstash arguments, and process syscall.
-	struct data_args_t* write_args = active_write_args_map__lookup(&id);
-	if (write_args != NULL) {
-		write_args->bytes_count = bytes_count;
-		process_syscall_data_vecs((struct pt_regs *)ctx, id, T_EGRESS, write_args, bytes_count);
-		active_write_args_map__delete(&id);
-	}
-
-	return 0;
-}
-
-// int sendmmsg(int sockfd, struct mmsghdr *msgvec, unsigned int vlen,
-//              int flags);
-KPROG(__sys_sendmmsg)(struct pt_regs* ctx) {
-	__u64 id = bpf_get_current_pid_tgid();
-	int sockfd = (int)PT_REGS_PARM1(ctx);
-	struct mmsghdr *msgvec_ptr = (struct mmsghdr *)PT_REGS_PARM2(ctx);
-	unsigned int vlen = (unsigned int)PT_REGS_PARM3(ctx);
-
-	if (msgvec_ptr != NULL && vlen >= 1) {
-		struct mmsghdr *msgvec, __msgvec;
-		bpf_probe_read(&__msgvec, sizeof(__msgvec), msgvec_ptr);
-		msgvec = &__msgvec;
-		// Stash arguments.
-		struct data_args_t write_args = {};
-		write_args.source_fn = SYSCALL_FUNC_SENDMMSG;
-		write_args.fd = sockfd;
-		write_args.iov = msgvec[0].msg_hdr.msg_iov;
-		write_args.iovlen = msgvec[0].msg_hdr.msg_iovlen;
-		write_args.msg_len = (void *)msgvec_ptr + offsetof(typeof(struct mmsghdr), msg_len); //&msgvec[0].msg_len;
-		write_args.enter_ts = bpf_ktime_get_ns();
-		active_write_args_map__update(&id, &write_args);
-	}
-
-	return 0;
-}
-
-// /sys/kernel/debug/tracing/events/syscalls/sys_exit_sendmmsg/format
-TPPROG(sys_exit_sendmmsg) (struct syscall_comm_exit_ctx *ctx) {
-	__u64 id = bpf_get_current_pid_tgid();
-
-	int num_msgs = ctx->ret;
-
-	// Unstash arguments, and process syscall.
-	struct data_args_t* write_args = active_write_args_map__lookup(&id);
-	if (write_args != NULL && num_msgs > 0) {
-		ssize_t bytes_count;
-		bpf_probe_read(&bytes_count, sizeof(write_args->msg_len), write_args->msg_len);
-		process_syscall_data_vecs((struct pt_regs *)ctx, id, T_EGRESS, write_args, bytes_count);
-	}
-	active_write_args_map__delete(&id);
-
-	return 0;
-}
-
-// BSD recvmsg interface
-// long __sys_recvmsg(int fd, struct user_msghdr __user *msg, unsigned int flags,
-//		   bool forbid_cmsg_compat)
-// ssize_t recvmsg(int sockfd, struct msghdr *msg, int flags);
-KPROG(__sys_recvmsg) (struct pt_regs* ctx) {
-	int flags = (int) PT_REGS_PARM3(ctx);
-	if (flags & MSG_PEEK)
-		return 0;
-
-	__u64 id = bpf_get_current_pid_tgid();
-	struct user_msghdr __msg, *msghdr = (struct user_msghdr *)PT_REGS_PARM2(ctx);
-	int sockfd = (int) PT_REGS_PARM1(ctx);
-
-	if (msghdr != NULL) {
-		bpf_probe_read(&__msg, sizeof(__msg), (void *)msghdr);
-		msghdr = &__msg;
-		// Stash arguments.
-		struct data_args_t read_args = {};
-		read_args.source_fn = SYSCALL_FUNC_RECVMSG;
-		read_args.fd = sockfd;
-		read_args.iov = msghdr->msg_iov;
-		read_args.iovlen = msghdr->msg_iovlen;
-		read_args.enter_ts = bpf_ktime_get_ns();
-		read_args.tcp_seq = get_tcp_read_seq_from_fd(sockfd);
-		active_read_args_map__update(&id, &read_args);
-	}
-
-	return 0;
-}
-
-// /sys/kernel/debug/tracing/events/syscalls/sys_exit_recvmsg/format
-TPPROG(sys_exit_recvmsg) (struct syscall_comm_exit_ctx *ctx) {
-	__u64 id = bpf_get_current_pid_tgid();
-	ssize_t bytes_count = ctx->ret;
-	// Unstash arguments, and process syscall.
-	struct data_args_t* read_args = active_read_args_map__lookup(&id);
-	if (read_args != NULL) {
-		read_args->bytes_count = bytes_count;
-		process_syscall_data_vecs((struct pt_regs *)ctx, id, T_INGRESS, read_args, bytes_count);
-		active_read_args_map__delete(&id);
-	}
-
-	return 0;
-}
-
-// int __sys_recvmmsg(int fd, struct mmsghdr __user *mmsg, unsigned int vlen,
-//		   unsigned int flags, struct timespec *timeout)
-KPROG(__sys_recvmmsg) (struct pt_regs* ctx) {
-	int flags = (int) PT_REGS_PARM4(ctx);
-	if (flags & MSG_PEEK)
-		return 0;
-
-	__u64 id = bpf_get_current_pid_tgid();
-	int sockfd = (int)PT_REGS_PARM1(ctx);
-	struct mmsghdr *msgvec = (struct mmsghdr *)PT_REGS_PARM2(ctx);
-	unsigned int vlen = (unsigned int)PT_REGS_PARM3(ctx);
-	
-	if (msgvec != NULL && vlen >= 1) {
-		int offset;
-		// Stash arguments.
-		struct data_args_t read_args = {};
-		read_args.source_fn = SYSCALL_FUNC_RECVMMSG;
-		read_args.fd = sockfd;
-		read_args.enter_ts = bpf_ktime_get_ns();
-
-		offset = offsetof(typeof(struct mmsghdr), msg_hdr) +
-				offsetof(typeof(struct user_msghdr), msg_iov);
-
-		bpf_probe_read(&read_args.iov, sizeof(read_args.iov), (void *)msgvec + offset);
-
-		offset = offsetof(typeof(struct mmsghdr), msg_hdr) +
-				offsetof(typeof(struct user_msghdr), msg_iovlen);
-
-		bpf_probe_read(&read_args.iovlen, sizeof(read_args.iovlen), (void *)msgvec + offset);
-
-		read_args.msg_len = (void *)msgvec + offsetof(typeof(struct mmsghdr), msg_len);
-		read_args.tcp_seq = get_tcp_read_seq_from_fd(sockfd);
-		active_read_args_map__update(&id, &read_args);
-	}
-	
-	return 0;
-}
-
-// /sys/kernel/debug/tracing/events/syscalls/sys_exit_recvmmsg/format
-TPPROG(sys_exit_recvmmsg) (struct syscall_comm_exit_ctx *ctx) {
-	__u64 id = bpf_get_current_pid_tgid();
-	int num_msgs = ctx->ret;
-	// Unstash arguments, and process syscall.
-	struct data_args_t* read_args = active_read_args_map__lookup(&id);
-	if (read_args != NULL && num_msgs > 0) {
-		ssize_t bytes_count;
-		bpf_probe_read(&bytes_count, sizeof(read_args->msg_len), read_args->msg_len);
-		process_syscall_data_vecs((struct pt_regs *)ctx, id, T_INGRESS, read_args, bytes_count);
-	}
-	active_read_args_map__delete(&id);
-
-	return 0;
-}
-
-//static ssize_t do_writev(unsigned long fd, const struct iovec __user *vec,
-//			 unsigned long vlen, rwf_t flags)
-// ssize_t writev(int fd, const struct iovec *iov, int iovcnt);
-KPROG(do_writev) (struct pt_regs* ctx) {
-	__u64 id = bpf_get_current_pid_tgid();
-	int fd = (int)PT_REGS_PARM1(ctx);
-	struct iovec *iov = (struct iovec *)PT_REGS_PARM2(ctx);
-	int iovlen = (int)PT_REGS_PARM3(ctx);
-
-	// Stash arguments.
-	struct data_args_t write_args = {};
-	write_args.source_fn = SYSCALL_FUNC_WRITEV;
-	write_args.fd = fd;
-	write_args.iov = iov;
-	write_args.iovlen = iovlen;
-	write_args.enter_ts = bpf_ktime_get_ns();
-	active_write_args_map__update(&id, &write_args);
-	return 0;
-}
-
-// /sys/kernel/debug/tracing/events/syscalls/sys_exit_writev/format
-TPPROG(sys_exit_writev) (struct syscall_comm_exit_ctx *ctx) {
-	__u64 id = bpf_get_current_pid_tgid();
-	ssize_t bytes_count = ctx->ret;
-
-	// Unstash arguments, and process syscall.
-	struct data_args_t* write_args = active_write_args_map__lookup(&id);
-	if (write_args != NULL) {
-		write_args->bytes_count = bytes_count;
-		process_syscall_data_vecs((struct pt_regs *)ctx, id, T_EGRESS, write_args, bytes_count);
-	}
-
-	active_write_args_map__delete(&id);
-	return 0;
-}
-
-// ssize_t readv(int fd, const struct iovec *iov, int iovcnt);
-KPROG(do_readv) (struct pt_regs* ctx) {
-	__u64 id = bpf_get_current_pid_tgid();
-	int fd = (int)PT_REGS_PARM1(ctx);
-	struct iovec *iov = (struct iovec *)PT_REGS_PARM2(ctx);
-	int iovlen = (int)PT_REGS_PARM3(ctx);
-
-	// Stash arguments.
-	struct data_args_t read_args = {};
-	read_args.source_fn = SYSCALL_FUNC_READV;
-	read_args.fd = fd;
-	read_args.iov = iov;
-	read_args.iovlen = iovlen;
-	read_args.enter_ts = bpf_ktime_get_ns();
-	read_args.tcp_seq = get_tcp_read_seq_from_fd(fd);
-	active_read_args_map__update(&id, &read_args);
-
-	return 0;
-}
-
-// /sys/kernel/debug/tracing/events/syscalls/sys_exit_readv/format
-TPPROG(sys_exit_readv) (struct syscall_comm_exit_ctx *ctx) {
-	__u64 id = bpf_get_current_pid_tgid();
-	ssize_t bytes_count = ctx->ret;
-	struct data_args_t* read_args = active_read_args_map__lookup(&id);
-	if (read_args != NULL) {
-		read_args->bytes_count = bytes_count;
-		process_syscall_data_vecs((struct pt_regs *)ctx, id, T_INGRESS, read_args, bytes_count);
-	}
-
-	active_read_args_map__delete(&id);
-	return 0;
-}
-
-// /sys/kernel/debug/tracing/events/syscalls/sys_enter_close/format
-// 为什么不用tcp_fin? 主要原因要考虑UDP场景。
-TPPROG(sys_enter_close) (struct syscall_comm_enter_ctx *ctx) {
-	int fd = ctx->fd;
-	//Ignore stdin, stdout and stderr
-	if (fd <= 2)
-		return 0;
-
-	__u32 k0 = 0;
-	struct member_fields_offset *offset = members_offset__lookup(&k0);
-	if (!offset)
-		return 0;
-
-	CHECK_OFFSET_READY(fd);
-
-	__u64 sock_addr = (__u64)get_socket_from_fd(fd, offset);
-	if (sock_addr) {
-		__u64 conn_key = gen_conn_key_id(bpf_get_current_pid_tgid() >> 32, (__u64)fd);
-		struct socket_info_t *socket_info_ptr = socket_info_map__lookup(&conn_key);
-		if (socket_info_ptr != NULL)
-			delete_socket_info(conn_key, socket_info_ptr);
-	}
-
-	return 0;
-}
-
-// /sys/kernel/debug/tracing/events/syscalls/sys_enter_getppid
-// 此处tracepoint用于周期性的将驻留在缓存中还未发送的数据发给用户态接收程序处理。
-TPPROG(sys_enter_getppid) (struct syscall_comm_enter_ctx *ctx) {
-	int k0 = 0;
-	struct __socket_data_buffer *v_buff = bpf_map_lookup_elem(&NAME(data_buf), &k0);
-	if (v_buff) {
-		if (v_buff->events_num > 0) {
-			struct __socket_data *v = (struct __socket_data *)&v_buff->data[0];
-			if ((bpf_ktime_get_ns() - v->timestamp * NS_PER_US) > NS_PER_SEC) {
-				__u32 buf_size = (v_buff->len +
-						  offsetof(typeof(struct __socket_data_buffer), data))
-						 & (sizeof(*v_buff) - 1);
-				if (buf_size >= sizeof(*v_buff))
-					bpf_perf_event_output(ctx, &NAME(socket_data),
-							      BPF_F_CURRENT_CPU, v_buff,
-							      sizeof(*v_buff));
-				else
-					/* 使用'buf_size + 1'代替'buf_size',来规避(Linux 4.14.x)长度检查 */
-					bpf_perf_event_output(ctx, &NAME(socket_data),
-							      BPF_F_CURRENT_CPU, v_buff,
-							      buf_size + 1);
-
-				v_buff->events_num = 0;
-				v_buff->len = 0;				
-			}
-		}
-	}
-
-	return 0;
-}
-
-// /sys/kernel/debug/tracing/events/syscalls/sys_exit_socket/format
-TPPROG(sys_exit_socket) (struct syscall_comm_exit_ctx *ctx) {
-	__u64 id = bpf_get_current_pid_tgid();
-	__u64 fd = (__u64)ctx->ret;
-	char comm[TASK_COMM_LEN];
-	bpf_get_current_comm(comm, sizeof(comm));
-
-	// 试用于nginx负载均衡场景
-	if (!(comm[0] == 'n' && comm[1] == 'g' && comm[2] == 'i' &&
-	      comm[3] == 'n' && comm[4] == 'x' && comm[5] == '\0'))
-		return 0;
-
-	// nginx is not a go process, disable go tracking
-	struct trace_key_t key = get_trace_key(0, true);
-	struct trace_info_t *trace = trace_map__lookup(&key);
-	if (trace && trace->peer_fd != 0 && trace->peer_fd != (__u32)fd) {
-		struct socket_info_t sk_info = { 0 };
-		sk_info.peer_fd = trace->peer_fd;
-		sk_info.trace_id = trace->thread_trace_id;	
-		__u64 conn_key = gen_conn_key_id(id >> 32, fd);
-		int ret = socket_info_map__update(&conn_key, &sk_info);
-		__u32 k0 = 0;
-		struct trace_stats *trace_stats = trace_stats_map__lookup(&k0);
-		if (trace_stats == NULL)
-			return 0;
-		if (ret == 0) {
-			__sync_fetch_and_add(&trace_stats->
-					     socket_map_count, 1);
-		}
-	}
-
-	return 0;
-}
+//TPPROG(sys_enter_write) (struct syscall_comm_enter_ctx *ctx) {
+//	__u64 id = bpf_get_current_pid_tgid();
+//	int fd = (int)ctx->fd;
+//	char *buf = (char *)ctx->buf;
+//
+//	struct data_args_t write_args = {};
+//	write_args.source_fn = SYSCALL_FUNC_WRITE;
+//	write_args.fd = fd;
+//	write_args.buf = buf;
+//	write_args.enter_ts = bpf_ktime_get_ns();
+//	active_write_args_map__update(&id, &write_args);
+//
+//	return 0;
+//}
+//
+//// /sys/kernel/debug/tracing/events/syscalls/sys_exit_write/format
+//TPPROG(sys_exit_write) (struct syscall_comm_exit_ctx *ctx) {
+//	__u64 id = bpf_get_current_pid_tgid();
+//	ssize_t bytes_count = ctx->ret;
+//	// Unstash arguments, and process syscall.
+//	struct data_args_t* write_args = active_write_args_map__lookup(&id);
+//	// Don't process FD 0-2 to avoid STDIN, STDOUT, STDERR.
+//	if (write_args != NULL && write_args->fd > 2) {
+//		write_args->bytes_count = bytes_count;
+//		process_syscall_data((struct pt_regs *)ctx, id, T_EGRESS, write_args, bytes_count);
+//	}
+//
+//	active_write_args_map__delete(&id);
+//	return 0;
+//}
+//
+//// ssize_t read(int fd, void *buf, size_t count);
+//TPPROG(sys_enter_read) (struct syscall_comm_enter_ctx *ctx) {
+//	__u64 id = bpf_get_current_pid_tgid();
+//	int fd = (int)ctx->fd;
+//	char *buf = (char *)ctx->buf;
+//	// Stash arguments.
+//	struct data_args_t read_args = {};
+//	read_args.source_fn = SYSCALL_FUNC_READ;
+//	read_args.fd = fd;
+//	read_args.buf = buf;
+//	read_args.enter_ts = bpf_ktime_get_ns();
+//	read_args.tcp_seq = get_tcp_read_seq_from_fd(fd);
+//	active_read_args_map__update(&id, &read_args);
+//
+//	return 0;
+//}
+//
+//// /sys/kernel/debug/tracing/events/syscalls/sys_exit_read/format
+//TPPROG(sys_exit_read) (struct syscall_comm_exit_ctx *ctx) {
+//	__u64 id = bpf_get_current_pid_tgid();
+//	ssize_t bytes_count = ctx->ret;
+//	// Unstash arguments, and process syscall.
+//	struct data_args_t* read_args = active_read_args_map__lookup(&id);
+//	// Don't process FD 0-2 to avoid STDIN, STDOUT, STDERR.
+//	if (read_args != NULL && read_args->fd > 2) {
+//		read_args->bytes_count = bytes_count;
+//		process_syscall_data((struct pt_regs *)ctx, id, T_INGRESS, read_args, bytes_count);
+//	}
+//
+//	active_read_args_map__delete(&id);
+//	return 0;
+//}
+//
+//// ssize_t sendto(int sockfd, const void *buf, size_t len, int flags,
+////		const struct sockaddr *dest_addr, socklen_t addrlen);
+//TPPROG(sys_enter_sendto) (struct syscall_comm_enter_ctx *ctx) {
+//	__u64 id = bpf_get_current_pid_tgid();
+//	int sockfd = (int)ctx->fd;
+//	char *buf = (char *)ctx->buf;
+//	// Stash arguments.
+//	struct data_args_t write_args = {};
+//	write_args.source_fn = SYSCALL_FUNC_SENDTO;
+//	write_args.fd = sockfd;
+//	write_args.buf = buf;
+//	write_args.enter_ts = bpf_ktime_get_ns();
+//	active_write_args_map__update(&id, &write_args);
+//
+//	return 0;
+//}
+//
+//// /sys/kernel/debug/tracing/events/syscalls/sys_exit_sendto/format
+//TPPROG(sys_exit_sendto) (struct syscall_comm_exit_ctx *ctx) {
+//	__u64 id = bpf_get_current_pid_tgid();
+//	ssize_t bytes_count = ctx->ret;
+//
+//	// 潜在的问题:如果sentto() addr是由TCP连接提供的,系统调用可能会忽略它,但我们仍然会跟踪它。在实践中,TCP连接不应该使用带addr参数的sendto()。
+//	// 在手册页中:
+//	//     如果sendto()用于连接模式(SOCK_STREAM, SOCK_SEQPACKET)套接字,参数
+//	//     dest_addr和addrlen会被忽略(如果不是,可能会返回EISCONN错误空和0)
+//	//
+//	// Unstash arguments, and process syscall.
+//	struct data_args_t* write_args = active_write_args_map__lookup(&id);
+//	if (write_args != NULL) {
+//		write_args->bytes_count = bytes_count;
+//		process_syscall_data((struct pt_regs*)ctx, id, T_EGRESS, write_args, bytes_count);
+//		active_write_args_map__delete(&id);
+//	}
+//
+//	return 0;
+//}
+//
+//// ssize_t recvfrom(int sockfd, void *buf, size_t len, int flags,
+////		  struct sockaddr *src_addr, socklen_t *addrlen);
+//TPPROG(sys_enter_recvfrom) (struct syscall_comm_enter_ctx *ctx) {
+//	// If flags contains MSG_PEEK, it is returned directly.
+//	// ref : https://linux.die.net/man/2/recvfrom
+//	if (ctx->flags & MSG_PEEK)
+//		return 0;
+//	__u64 id = bpf_get_current_pid_tgid();
+//	int sockfd = (int)ctx->fd;
+//	char *buf = (char *)ctx->buf;
+//	// Stash arguments.
+//	struct data_args_t read_args = {};
+//	read_args.source_fn = SYSCALL_FUNC_RECVFROM;
+//	read_args.fd = sockfd;
+//	read_args.buf = buf;
+//	read_args.enter_ts = bpf_ktime_get_ns();
+//	read_args.tcp_seq = get_tcp_read_seq_from_fd(sockfd);
+//	active_read_args_map__update(&id, &read_args);
+//
+//	return 0;
+//}
+//
+//// /sys/kernel/debug/tracing/events/syscalls/sys_exit_recvfrom/format
+//TPPROG(sys_exit_recvfrom) (struct syscall_comm_exit_ctx *ctx) {
+//	__u64 id = bpf_get_current_pid_tgid();
+//	ssize_t bytes_count = ctx->ret;
+//
+//	// Unstash arguments, and process syscall.
+//	struct data_args_t* read_args = active_read_args_map__lookup(&id);
+//	if (read_args != NULL) {
+//		read_args->bytes_count = bytes_count;
+//		process_syscall_data((struct pt_regs *)ctx, id, T_INGRESS, read_args, bytes_count);
+//		active_read_args_map__delete(&id);
+//	}
+//
+//	return 0;
+//}
+//
+//// ssize_t sendmsg(int sockfd, const struct msghdr *msg, int flags);
+//KPROG(__sys_sendmsg) (struct pt_regs* ctx) {
+//	__u64 id = bpf_get_current_pid_tgid();
+//	int sockfd = (int)PT_REGS_PARM1(ctx);
+//	struct user_msghdr *msghdr_ptr = (struct user_msghdr *)PT_REGS_PARM2(ctx);
+//
+//	if (msghdr_ptr != NULL) {
+//		// Stash arguments.
+//		struct user_msghdr *msghdr, __msghdr;
+//		bpf_probe_read(&__msghdr, sizeof(__msghdr), msghdr_ptr);
+//		msghdr = &__msghdr;
+//		// Stash arguments.
+//		struct data_args_t write_args = {};
+//		write_args.source_fn = SYSCALL_FUNC_SENDMSG;
+//		write_args.fd = sockfd;
+//		write_args.iov = msghdr->msg_iov;
+//		write_args.iovlen = msghdr->msg_iovlen;
+//		write_args.enter_ts = bpf_ktime_get_ns();
+//		active_write_args_map__update(&id, &write_args);
+//	}
+//
+//	return 0;
+//}
+//
+//// /sys/kernel/debug/tracing/events/syscalls/sys_exit_sendmsg/format
+//TPPROG(sys_exit_sendmsg) (struct syscall_comm_exit_ctx *ctx) {
+//	__u64 id = bpf_get_current_pid_tgid();
+//	ssize_t bytes_count = ctx->ret;
+//	// Unstash arguments, and process syscall.
+//	struct data_args_t* write_args = active_write_args_map__lookup(&id);
+//	if (write_args != NULL) {
+//		write_args->bytes_count = bytes_count;
+//		process_syscall_data_vecs((struct pt_regs *)ctx, id, T_EGRESS, write_args, bytes_count);
+//		active_write_args_map__delete(&id);
+//	}
+//
+//	return 0;
+//}
+//
+//// int sendmmsg(int sockfd, struct mmsghdr *msgvec, unsigned int vlen,
+////              int flags);
+//KPROG(__sys_sendmmsg)(struct pt_regs* ctx) {
+//	__u64 id = bpf_get_current_pid_tgid();
+//	int sockfd = (int)PT_REGS_PARM1(ctx);
+//	struct mmsghdr *msgvec_ptr = (struct mmsghdr *)PT_REGS_PARM2(ctx);
+//	unsigned int vlen = (unsigned int)PT_REGS_PARM3(ctx);
+//
+//	if (msgvec_ptr != NULL && vlen >= 1) {
+//		struct mmsghdr *msgvec, __msgvec;
+//		bpf_probe_read(&__msgvec, sizeof(__msgvec), msgvec_ptr);
+//		msgvec = &__msgvec;
+//		// Stash arguments.
+//		struct data_args_t write_args = {};
+//		write_args.source_fn = SYSCALL_FUNC_SENDMMSG;
+//		write_args.fd = sockfd;
+//		write_args.iov = msgvec[0].msg_hdr.msg_iov;
+//		write_args.iovlen = msgvec[0].msg_hdr.msg_iovlen;
+//		write_args.msg_len = (void *)msgvec_ptr + offsetof(typeof(struct mmsghdr), msg_len); //&msgvec[0].msg_len;
+//		write_args.enter_ts = bpf_ktime_get_ns();
+//		active_write_args_map__update(&id, &write_args);
+//	}
+//
+//	return 0;
+//}
+//
+//// /sys/kernel/debug/tracing/events/syscalls/sys_exit_sendmmsg/format
+//TPPROG(sys_exit_sendmmsg) (struct syscall_comm_exit_ctx *ctx) {
+//	__u64 id = bpf_get_current_pid_tgid();
+//
+//	int num_msgs = ctx->ret;
+//
+//	// Unstash arguments, and process syscall.
+//	struct data_args_t* write_args = active_write_args_map__lookup(&id);
+//	if (write_args != NULL && num_msgs > 0) {
+//		ssize_t bytes_count;
+//		bpf_probe_read(&bytes_count, sizeof(write_args->msg_len), write_args->msg_len);
+//		process_syscall_data_vecs((struct pt_regs *)ctx, id, T_EGRESS, write_args, bytes_count);
+//	}
+//	active_write_args_map__delete(&id);
+//
+//	return 0;
+//}
+//
+//// BSD recvmsg interface
+//// long __sys_recvmsg(int fd, struct user_msghdr __user *msg, unsigned int flags,
+////		   bool forbid_cmsg_compat)
+//// ssize_t recvmsg(int sockfd, struct msghdr *msg, int flags);
+//KPROG(__sys_recvmsg) (struct pt_regs* ctx) {
+//	int flags = (int) PT_REGS_PARM3(ctx);
+//	if (flags & MSG_PEEK)
+//		return 0;
+//
+//	__u64 id = bpf_get_current_pid_tgid();
+//	struct user_msghdr __msg, *msghdr = (struct user_msghdr *)PT_REGS_PARM2(ctx);
+//	int sockfd = (int) PT_REGS_PARM1(ctx);
+//
+//	if (msghdr != NULL) {
+//		bpf_probe_read(&__msg, sizeof(__msg), (void *)msghdr);
+//		msghdr = &__msg;
+//		// Stash arguments.
+//		struct data_args_t read_args = {};
+//		read_args.source_fn = SYSCALL_FUNC_RECVMSG;
+//		read_args.fd = sockfd;
+//		read_args.iov = msghdr->msg_iov;
+//		read_args.iovlen = msghdr->msg_iovlen;
+//		read_args.enter_ts = bpf_ktime_get_ns();
+//		read_args.tcp_seq = get_tcp_read_seq_from_fd(sockfd);
+//		active_read_args_map__update(&id, &read_args);
+//	}
+//
+//	return 0;
+//}
+//
+//// /sys/kernel/debug/tracing/events/syscalls/sys_exit_recvmsg/format
+//TPPROG(sys_exit_recvmsg) (struct syscall_comm_exit_ctx *ctx) {
+//	__u64 id = bpf_get_current_pid_tgid();
+//	ssize_t bytes_count = ctx->ret;
+//	// Unstash arguments, and process syscall.
+//	struct data_args_t* read_args = active_read_args_map__lookup(&id);
+//	if (read_args != NULL) {
+//		read_args->bytes_count = bytes_count;
+//		process_syscall_data_vecs((struct pt_regs *)ctx, id, T_INGRESS, read_args, bytes_count);
+//		active_read_args_map__delete(&id);
+//	}
+//
+//	return 0;
+//}
+//
+//// int __sys_recvmmsg(int fd, struct mmsghdr __user *mmsg, unsigned int vlen,
+////		   unsigned int flags, struct timespec *timeout)
+//KPROG(__sys_recvmmsg) (struct pt_regs* ctx) {
+//	int flags = (int) PT_REGS_PARM4(ctx);
+//	if (flags & MSG_PEEK)
+//		return 0;
+//
+//	__u64 id = bpf_get_current_pid_tgid();
+//	int sockfd = (int)PT_REGS_PARM1(ctx);
+//	struct mmsghdr *msgvec = (struct mmsghdr *)PT_REGS_PARM2(ctx);
+//	unsigned int vlen = (unsigned int)PT_REGS_PARM3(ctx);
+//
+//	if (msgvec != NULL && vlen >= 1) {
+//		int offset;
+//		// Stash arguments.
+//		struct data_args_t read_args = {};
+//		read_args.source_fn = SYSCALL_FUNC_RECVMMSG;
+//		read_args.fd = sockfd;
+//		read_args.enter_ts = bpf_ktime_get_ns();
+//
+//		offset = offsetof(typeof(struct mmsghdr), msg_hdr) +
+//				offsetof(typeof(struct user_msghdr), msg_iov);
+//
+//		bpf_probe_read(&read_args.iov, sizeof(read_args.iov), (void *)msgvec + offset);
+//
+//		offset = offsetof(typeof(struct mmsghdr), msg_hdr) +
+//				offsetof(typeof(struct user_msghdr), msg_iovlen);
+//
+//		bpf_probe_read(&read_args.iovlen, sizeof(read_args.iovlen), (void *)msgvec + offset);
+//
+//		read_args.msg_len = (void *)msgvec + offsetof(typeof(struct mmsghdr), msg_len);
+//		read_args.tcp_seq = get_tcp_read_seq_from_fd(sockfd);
+//		active_read_args_map__update(&id, &read_args);
+//	}
+//
+//	return 0;
+//}
+//
+//// /sys/kernel/debug/tracing/events/syscalls/sys_exit_recvmmsg/format
+//TPPROG(sys_exit_recvmmsg) (struct syscall_comm_exit_ctx *ctx) {
+//	__u64 id = bpf_get_current_pid_tgid();
+//	int num_msgs = ctx->ret;
+//	// Unstash arguments, and process syscall.
+//	struct data_args_t* read_args = active_read_args_map__lookup(&id);
+//	if (read_args != NULL && num_msgs > 0) {
+//		ssize_t bytes_count;
+//		bpf_probe_read(&bytes_count, sizeof(read_args->msg_len), read_args->msg_len);
+//		process_syscall_data_vecs((struct pt_regs *)ctx, id, T_INGRESS, read_args, bytes_count);
+//	}
+//	active_read_args_map__delete(&id);
+//
+//	return 0;
+//}
+//
+////static ssize_t do_writev(unsigned long fd, const struct iovec __user *vec,
+////			 unsigned long vlen, rwf_t flags)
+//// ssize_t writev(int fd, const struct iovec *iov, int iovcnt);
+//KPROG(do_writev) (struct pt_regs* ctx) {
+//	__u64 id = bpf_get_current_pid_tgid();
+//	int fd = (int)PT_REGS_PARM1(ctx);
+//	struct iovec *iov = (struct iovec *)PT_REGS_PARM2(ctx);
+//	int iovlen = (int)PT_REGS_PARM3(ctx);
+//
+//	// Stash arguments.
+//	struct data_args_t write_args = {};
+//	write_args.source_fn = SYSCALL_FUNC_WRITEV;
+//	write_args.fd = fd;
+//	write_args.iov = iov;
+//	write_args.iovlen = iovlen;
+//	write_args.enter_ts = bpf_ktime_get_ns();
+//	active_write_args_map__update(&id, &write_args);
+//	return 0;
+//}
+//
+//// /sys/kernel/debug/tracing/events/syscalls/sys_exit_writev/format
+//TPPROG(sys_exit_writev) (struct syscall_comm_exit_ctx *ctx) {
+//	__u64 id = bpf_get_current_pid_tgid();
+//	ssize_t bytes_count = ctx->ret;
+//
+//	// Unstash arguments, and process syscall.
+//	struct data_args_t* write_args = active_write_args_map__lookup(&id);
+//	if (write_args != NULL) {
+//		write_args->bytes_count = bytes_count;
+//		process_syscall_data_vecs((struct pt_regs *)ctx, id, T_EGRESS, write_args, bytes_count);
+//	}
+//
+//	active_write_args_map__delete(&id);
+//	return 0;
+//}
+//
+//// ssize_t readv(int fd, const struct iovec *iov, int iovcnt);
+//KPROG(do_readv) (struct pt_regs* ctx) {
+//	__u64 id = bpf_get_current_pid_tgid();
+//	int fd = (int)PT_REGS_PARM1(ctx);
+//	struct iovec *iov = (struct iovec *)PT_REGS_PARM2(ctx);
+//	int iovlen = (int)PT_REGS_PARM3(ctx);
+//
+//	// Stash arguments.
+//	struct data_args_t read_args = {};
+//	read_args.source_fn = SYSCALL_FUNC_READV;
+//	read_args.fd = fd;
+//	read_args.iov = iov;
+//	read_args.iovlen = iovlen;
+//	read_args.enter_ts = bpf_ktime_get_ns();
+//	read_args.tcp_seq = get_tcp_read_seq_from_fd(fd);
+//	active_read_args_map__update(&id, &read_args);
+//
+//	return 0;
+//}
+//
+//// /sys/kernel/debug/tracing/events/syscalls/sys_exit_readv/format
+//TPPROG(sys_exit_readv) (struct syscall_comm_exit_ctx *ctx) {
+//	__u64 id = bpf_get_current_pid_tgid();
+//	ssize_t bytes_count = ctx->ret;
+//	struct data_args_t* read_args = active_read_args_map__lookup(&id);
+//	if (read_args != NULL) {
+//		read_args->bytes_count = bytes_count;
+//		process_syscall_data_vecs((struct pt_regs *)ctx, id, T_INGRESS, read_args, bytes_count);
+//	}
+//
+//	active_read_args_map__delete(&id);
+//	return 0;
+//}
+//
+//// /sys/kernel/debug/tracing/events/syscalls/sys_enter_close/format
+//// 为什么不用tcp_fin? 主要原因要考虑UDP场景。
+//TPPROG(sys_enter_close) (struct syscall_comm_enter_ctx *ctx) {
+//	int fd = ctx->fd;
+//	//Ignore stdin, stdout and stderr
+//	if (fd <= 2)
+//		return 0;
+//
+//	__u32 k0 = 0;
+//	struct member_fields_offset *offset = members_offset__lookup(&k0);
+//	if (!offset)
+//		return 0;
+//
+//	CHECK_OFFSET_READY(fd);
+//
+//	__u64 sock_addr = (__u64)get_socket_from_fd(fd, offset);
+//	if (sock_addr) {
+//		__u64 conn_key = gen_conn_key_id(bpf_get_current_pid_tgid() >> 32, (__u64)fd);
+//		struct socket_info_t *socket_info_ptr = socket_info_map__lookup(&conn_key);
+//		if (socket_info_ptr != NULL)
+//			delete_socket_info(conn_key, socket_info_ptr);
+//	}
+//
+//	return 0;
+//}
+//
+//// /sys/kernel/debug/tracing/events/syscalls/sys_enter_getppid
+//// 此处tracepoint用于周期性的将驻留在缓存中还未发送的数据发给用户态接收程序处理。
+//TPPROG(sys_enter_getppid) (struct syscall_comm_enter_ctx *ctx) {
+//	int k0 = 0;
+//	struct __socket_data_buffer *v_buff = bpf_map_lookup_elem(&NAME(data_buf), &k0);
+//	if (v_buff) {
+//		if (v_buff->events_num > 0) {
+//			struct __socket_data *v = (struct __socket_data *)&v_buff->data[0];
+//			if ((bpf_ktime_get_ns() - v->timestamp * NS_PER_US) > NS_PER_SEC) {
+//				__u32 buf_size = (v_buff->len +
+//						  offsetof(typeof(struct __socket_data_buffer), data))
+//						 & (sizeof(*v_buff) - 1);
+//				if (buf_size >= sizeof(*v_buff))
+//					bpf_perf_event_output(ctx, &NAME(socket_data),
+//							      BPF_F_CURRENT_CPU, v_buff,
+//							      sizeof(*v_buff));
+//				else
+//					/* 使用'buf_size + 1'代替'buf_size',来规避(Linux 4.14.x)长度检查 */
+//					bpf_perf_event_output(ctx, &NAME(socket_data),
+//							      BPF_F_CURRENT_CPU, v_buff,
+//							      buf_size + 1);
+//
+//				v_buff->events_num = 0;
+//				v_buff->len = 0;
+//			}
+//		}
+//	}
+//
+//	return 0;
+//}
+//
+//// /sys/kernel/debug/tracing/events/syscalls/sys_exit_socket/format
+//TPPROG(sys_exit_socket) (struct syscall_comm_exit_ctx *ctx) {
+//	__u64 id = bpf_get_current_pid_tgid();
+//	__u64 fd = (__u64)ctx->ret;
+//	char comm[TASK_COMM_LEN];
+//	bpf_get_current_comm(comm, sizeof(comm));
+//
+//	// 试用于nginx负载均衡场景
+//	if (!(comm[0] == 'n' && comm[1] == 'g' && comm[2] == 'i' &&
+//	      comm[3] == 'n' && comm[4] == 'x' && comm[5] == '\0'))
+//		return 0;
+//
+//	// nginx is not a go process, disable go tracking
+//	struct trace_key_t key = get_trace_key(0, true);
+//	struct trace_info_t *trace = trace_map__lookup(&key);
+//	if (trace && trace->peer_fd != 0 && trace->peer_fd != (__u32)fd) {
+//		struct socket_info_t sk_info = { 0 };
+//		sk_info.peer_fd = trace->peer_fd;
+//		sk_info.trace_id = trace->thread_trace_id;
+//		__u64 conn_key = gen_conn_key_id(id >> 32, fd);
+//		int ret = socket_info_map__update(&conn_key, &sk_info);
+//		__u32 k0 = 0;
+//		struct trace_stats *trace_stats = trace_stats_map__lookup(&k0);
+//		if (trace_stats == NULL)
+//			return 0;
+//		if (ret == 0) {
+//			__sync_fetch_and_add(&trace_stats->
+//					     socket_map_count, 1);
+//		}
+//	}
+//
+//	return 0;
+//}
 
 // Store IO event information
 MAP_PERARRAY(io_event_buffer, __u32, struct __io_event_buffer, 1)
@@ -1967,14 +1967,14 @@ static __inline int output_data_common(void *ctx) {
     debug("DataSeq: %llu", v->data_seq);
     debug("DataType: %u", v->data_type);
     debug("DataLen: %u", v->data_len);
-    debug("data: %s", v->data);
+//    debug("data: %s", v->data);
 //    for (size_t i = 0; i < v->data_len; ++i) {
 //        debug("%02x ", (unsigned char)v->data[i]);
 //        if ((i + 1) % 16 == 0) {
 //            debug("\n");
 //        }
 //    }
-    debug("=======================end");
+    debug("=======================end\n");
 
 	v_buff->len += offsetof(typeof(struct __socket_data), data) + v->data_len;
 	v_buff->events_num++;
@@ -2201,29 +2201,29 @@ static __inline void trace_io_event_common(void *ctx,
 		      PROG_OUTPUT_DATA_TP_IDX);
 	return;
 }
-
-PROGTP(io_event)(void *ctx)
-{
-	__u64 id = bpf_get_current_pid_tgid();
-
-	struct data_args_t *data_args = NULL;
-
-	data_args = active_read_args_map__lookup(&id);
-	if (data_args) {
-		trace_io_event_common(ctx, data_args, T_INGRESS, id);
-		active_read_args_map__delete(&id);
-		return 0;
-	}
-
-	data_args = active_write_args_map__lookup(&id);
-	if (data_args) {
-		trace_io_event_common(ctx, data_args, T_EGRESS, id);
-		active_write_args_map__delete(&id);
-		return 0;
-	}
-
-	return 0;
-}
+//
+//PROGTP(io_event)(void *ctx)
+//{
+//	__u64 id = bpf_get_current_pid_tgid();
+//
+//	struct data_args_t *data_args = NULL;
+//
+//	data_args = active_read_args_map__lookup(&id);
+//	if (data_args) {
+//		trace_io_event_common(ctx, data_args, T_INGRESS, id);
+//		active_read_args_map__delete(&id);
+//		return 0;
+//	}
+//
+//	data_args = active_write_args_map__lookup(&id);
+//	if (data_args) {
+//		trace_io_event_common(ctx, data_args, T_EGRESS, id);
+//		active_write_args_map__delete(&id);
+//		return 0;
+//	}
+//
+//	return 0;
+//}
 
 //Refer to the eBPF programs here
 //#include "go_tls_bpf.c"

+ 9 - 9
ebpftracer/ebpf/utrace/go/include/go_context.h

@@ -73,7 +73,7 @@ static __always_inline void *get_parent_go_context(void *ctx, void *map) {
         bpf_probe_read(&data, sizeof(data), data + 8);
     }
 
-    bpf_printk("context %lx not found in context map", ctx);
+//    cw_bpf_debug("context %lx not found in context map", ctx);
     return NULL;
 }
 
@@ -112,18 +112,18 @@ static __always_inline struct span_context *get_parent_span_context(void *ctx) {
 //    }
 //
 ////    debug("key.tgid:%llu|%llu",key.tgid,key.goid);
-//    bpf_printk("apm key.pid:%d",(__u32)pid_tgid);
-//    bpf_printk("apm key.goid:%llu",key.goid);
+//    cw_bpf_debug("apm key.pid:%d",(__u32)pid_tgid);
+//    cw_bpf_debug("apm key.goid:%llu",key.goid);
 //    return key;
 //}
 
 static __always_inline void start_tracking_span(void *contextContext, struct span_context *sc) {
     long err = 0;
-    bpf_printk("Save data");
+    cw_bpf_debug("Save data");
     err = bpf_map_update_elem(&tracked_spans, &contextContext, sc, BPF_ANY);
     if (err != 0)
     {
-        bpf_printk("Failed to update tracked_spans map: %ld", err);
+        cw_bpf_debug("Failed to update tracked_spans map: %ld", err);
         return;
     }
 //    struct apm_trace_key_t key = {};
@@ -132,28 +132,28 @@ static __always_inline void start_tracking_span(void *contextContext, struct spa
 //    err = bpf_map_update_elem(&tracked_spans_apm, &key, sc, BPF_ANY);
 //    if (err != 0)
 //    {
-//        bpf_printk("Failed to update tracked_spans map: %ld", err);
+//        cw_bpf_debug("Failed to update tracked_spans map: %ld", err);
 //        return;
 //    }
 
     err = bpf_map_update_elem(&tracked_spans_by_sc, sc, &contextContext, BPF_ANY);
     if (err != 0)
     {
-        bpf_printk("Failed to update tracked_spans_by_sc map: %ld", err);
+        cw_bpf_debug("Failed to update tracked_spans_by_sc map: %ld", err);
         return;
     }
 }
 
 static __always_inline void stop_tracking_span(struct span_context *sc, struct span_context *psc) {
     if (sc == NULL) {
-        bpf_printk("stop_tracking_span: sc is null");
+        cw_bpf_debug("stop_tracking_span: sc is null");
         return;
     }
 
     void *ctx = bpf_map_lookup_elem(&tracked_spans_by_sc, sc);
     if (ctx == NULL)
     {
-        bpf_printk("stop_tracking_span: cant find span context");
+        cw_bpf_debug("stop_tracking_span: cant find span context");
         return;
     }
 

+ 44 - 46
ebpftracer/ebpf/utrace/go/net/client.probe.bpf.c

@@ -67,12 +67,12 @@ static __always_inline long inject_header(void* headers_ptr, struct span_context
     long res = bpf_probe_read_user(&curr_keyvalue_count, sizeof(curr_keyvalue_count), headers_ptr);
 
     if (res < 0) {
-        bpf_printk("Couldn't read map key-value count from user");
+        cw_bpf_debug("Couldn't read map key-value count from user");
         return -1;
     }
 
     if (curr_keyvalue_count >= 8) {
-        bpf_printk("Map size is bigger than 8, skipping context propagation");
+        cw_bpf_debug("Map size is bigger than 8, skipping context propagation");
         return -1;
     }
 
@@ -91,13 +91,13 @@ static __always_inline long inject_header(void* headers_ptr, struct span_context
         // No key-value pairs in the Go map, need to "allocate" memory for the user
         bucket_ptr = write_target_data(bucket_map_value, sizeof(struct map_bucket));
         if (bucket_ptr == NULL) {
-            bpf_printk("inject_header: Failed to write bucket to user");
+            cw_bpf_debug("inject_header: Failed to write bucket to user");
             return -1;
         }
         // Update the buckets pointer in the hmap struct to point to newly allocated bucket
         res = bpf_probe_write_user(buckets_ptr_ptr, &bucket_ptr, sizeof(bucket_ptr));
         if (res < 0) {
-            bpf_printk("Failed to update the map bucket pointer for the user");
+            cw_bpf_debug("Failed to update the map bucket pointer for the user");
             return -1;
         }
     } else {
@@ -117,7 +117,7 @@ static __always_inline long inject_header(void* headers_ptr, struct span_context
     char key[W3C_KEY_LENGTH] = "traceparent";
     void *ptr = write_target_data(key, W3C_KEY_LENGTH);
     if (ptr == NULL) {
-        bpf_printk("inject_header: Failed to write key to user");
+        cw_bpf_debug("inject_header: Failed to write key to user");
         return -1;
     }
     bucket_map_value->keys[bucket_index] = (struct go_string_ot) {.len = W3C_KEY_LENGTH, .str = ptr};
@@ -128,7 +128,7 @@ static __always_inline long inject_header(void* headers_ptr, struct span_context
     span_context_to_w3c_string(propagated_ctx, val);
     ptr = write_target_data(val, sizeof(val));
     if(ptr == NULL) {
-        bpf_printk("inject_header: Failed to write value to user");
+        cw_bpf_debug("inject_header: Failed to write value to user");
         return -1;
     }
 
@@ -136,7 +136,7 @@ static __always_inline long inject_header(void* headers_ptr, struct span_context
     struct go_string_ot header_value = {.len = W3C_VAL_LENGTH, .str = ptr};
     ptr = write_target_data((void*)&header_value, sizeof(header_value));
     if(ptr == NULL) {
-        bpf_printk("inject_header: Failed to write go_string to user");
+        cw_bpf_debug("inject_header: Failed to write go_string to user");
         return -1;
     }
 
@@ -147,14 +147,14 @@ static __always_inline long inject_header(void* headers_ptr, struct span_context
     curr_keyvalue_count += 1;
     res = bpf_probe_write_user(headers_ptr, &curr_keyvalue_count, sizeof(curr_keyvalue_count));
     if (res < 0) {
-        bpf_printk("Failed to update key-value count in map header");
+        cw_bpf_debug("Failed to update key-value count in map header");
         return -1;
     }
 
     // Update the bucket
     res = bpf_probe_write_user(bucket_ptr, bucket_map_value, sizeof(struct map_bucket));
     if (res < 0) {
-        bpf_printk("Failed to update bucket content");
+        cw_bpf_debug("Failed to update bucket content");
         return -1;
     }
 
@@ -168,12 +168,12 @@ static __always_inline long cw_inject_header(void* headers_ptr, struct apm_span_
     long res = bpf_probe_read_user(&curr_keyvalue_count, sizeof(curr_keyvalue_count), headers_ptr);
 
     if (res < 0) {
-        bpf_printk("Couldn't read map key-value count from user");
+        cw_bpf_debug("Couldn't read map key-value count from user");
         return -1;
     }
 
     if (curr_keyvalue_count >= 8) {
-        bpf_printk("Map size is bigger than 8, skipping context propagation");
+        cw_bpf_debug("Map size is bigger than 8, skipping context propagation");
         return -1;
     }
 
@@ -192,13 +192,13 @@ static __always_inline long cw_inject_header(void* headers_ptr, struct apm_span_
         // No key-value pairs in the Go map, need to "allocate" memory for the user
         bucket_ptr = write_target_data(bucket_map_value, sizeof(struct map_bucket));
         if (bucket_ptr == NULL) {
-            bpf_printk("inject_header: Failed to write bucket to user");
+            cw_bpf_debug("inject_header: Failed to write bucket to user");
             return -1;
         }
         // Update the buckets pointer in the hmap struct to point to newly allocated bucket
         res = bpf_probe_write_user(buckets_ptr_ptr, &bucket_ptr, sizeof(bucket_ptr));
         if (res < 0) {
-            bpf_printk("Failed to update the map bucket pointer for the user");
+            cw_bpf_debug("Failed to update the map bucket pointer for the user");
             return -1;
         }
     } else {
@@ -218,7 +218,7 @@ static __always_inline long cw_inject_header(void* headers_ptr, struct apm_span_
     char key[W3C_KEY_LENGTH] = "traceparent";
     void *ptr = write_target_data(key, W3C_KEY_LENGTH);
     if (ptr == NULL) {
-        bpf_printk("inject_header: Failed to write key to user");
+        cw_bpf_debug("inject_header: Failed to write key to user");
         return -1;
     }
     bucket_map_value->keys[bucket_index] = (struct go_string_ot) {.len = W3C_KEY_LENGTH, .str = ptr};
@@ -229,7 +229,7 @@ static __always_inline long cw_inject_header(void* headers_ptr, struct apm_span_
 	span_context_to_cw_string(propagated_ctx, val);
     ptr = write_target_data(val, sizeof(val));
     if(ptr == NULL) {
-        bpf_printk("inject_header: Failed to write value to user");
+        cw_bpf_debug("inject_header: Failed to write value to user");
         return -1;
     }
 
@@ -237,7 +237,7 @@ static __always_inline long cw_inject_header(void* headers_ptr, struct apm_span_
     struct go_string_ot header_value = {.len = CW_HEADER_LENGTH, .str = ptr};
     ptr = write_target_data((void*)&header_value, sizeof(header_value));
     if(ptr == NULL) {
-        bpf_printk("inject_header: Failed to write go_string to user");
+        cw_bpf_debug("inject_header: Failed to write go_string to user");
         return -1;
     }
 
@@ -248,14 +248,14 @@ static __always_inline long cw_inject_header(void* headers_ptr, struct apm_span_
     curr_keyvalue_count += 1;
     res = bpf_probe_write_user(headers_ptr, &curr_keyvalue_count, sizeof(curr_keyvalue_count));
     if (res < 0) {
-        bpf_printk("Failed to update key-value count in map header");
+        cw_bpf_debug("Failed to update key-value count in map header");
         return -1;
     }
 
     // Update the bucket
     res = bpf_probe_write_user(bucket_ptr, bucket_map_value, sizeof(struct map_bucket));
     if (res < 0) {
-        bpf_printk("Failed to update bucket content");
+        cw_bpf_debug("Failed to update bucket content");
         return -1;
     }
 
@@ -270,12 +270,12 @@ static __always_inline long cw_inject_header2(void* headers_ptr, struct apm_span
     long res = bpf_probe_read_user(&curr_keyvalue_count, sizeof(curr_keyvalue_count), headers_ptr);
 
     if (res < 0) {
-        bpf_printk("Couldn't read map key-value count from user");
+        cw_bpf_debug("Couldn't read map key-value count from user");
         return -1;
     }
 
     if (curr_keyvalue_count >= 8) {
-        bpf_printk("Map size is bigger than 8, skipping context propagation");
+        cw_bpf_debug("Map size is bigger than 8, skipping context propagation");
         return -1;
     }
 
@@ -294,13 +294,13 @@ static __always_inline long cw_inject_header2(void* headers_ptr, struct apm_span
         // No key-value pairs in the Go map, need to "allocate" memory for the user
         bucket_ptr = write_target_data(bucket_map_value, sizeof(struct map_bucket));
         if (bucket_ptr == NULL) {
-            bpf_printk("inject_header: Failed to write bucket to user");
+            cw_bpf_debug("inject_header: Failed to write bucket to user");
             return -1;
         }
         // Update the buckets pointer in the hmap struct to point to newly allocated bucket
         res = bpf_probe_write_user(buckets_ptr_ptr, &bucket_ptr, sizeof(bucket_ptr));
         if (res < 0) {
-            bpf_printk("Failed to update the map bucket pointer for the user");
+            cw_bpf_debug("Failed to update the map bucket pointer for the user");
             return -1;
         }
     } else {
@@ -320,7 +320,7 @@ static __always_inline long cw_inject_header2(void* headers_ptr, struct apm_span
     char key[9] = "CLOUDWISE";
     void *ptr = write_target_data(key, 9);
     if (ptr == NULL) {
-        bpf_printk("inject_header: Failed to write key to user");
+        cw_bpf_debug("inject_header: Failed to write key to user");
         return -1;
     }
     bucket_map_value->keys[bucket_index] = (struct go_string_ot) {.len = 9, .str = ptr};
@@ -331,7 +331,7 @@ static __always_inline long cw_inject_header2(void* headers_ptr, struct apm_span
 	span_context_to_cw_string2(propagated_ctx, val);
     ptr = write_target_data(val, sizeof(val));
     if(ptr == NULL) {
-        bpf_printk("inject_header: Failed to write value to user");
+        cw_bpf_debug("inject_header: Failed to write value to user");
         return -1;
     }
 
@@ -339,7 +339,7 @@ static __always_inline long cw_inject_header2(void* headers_ptr, struct apm_span
     struct go_string_ot header_value = {.len = CW_HEADER_LENGTH2, .str = ptr};
     ptr = write_target_data((void*)&header_value, sizeof(header_value));
     if(ptr == NULL) {
-        bpf_printk("inject_header: Failed to write go_string to user");
+        cw_bpf_debug("inject_header: Failed to write go_string to user");
         return -1;
     }
 
@@ -350,14 +350,14 @@ static __always_inline long cw_inject_header2(void* headers_ptr, struct apm_span
     curr_keyvalue_count += 1;
     res = bpf_probe_write_user(headers_ptr, &curr_keyvalue_count, sizeof(curr_keyvalue_count));
     if (res < 0) {
-        bpf_printk("Failed to update key-value count in map header");
+        cw_bpf_debug("Failed to update key-value count in map header");
         return -1;
     }
 
     // Update the bucket
     res = bpf_probe_write_user(bucket_ptr, bucket_map_value, sizeof(struct map_bucket));
     if (res < 0) {
-        bpf_printk("Failed to update bucket content");
+        cw_bpf_debug("Failed to update bucket content");
         return -1;
     }
 
@@ -369,9 +369,7 @@ static __always_inline long cw_inject_header2(void* headers_ptr, struct apm_span
 // func net/http/transport.roundTrip(req *Request) (*Response, error)
 SEC("uprobe/Transport_roundTrip")
 int uprobe_Transport_roundTrip(struct pt_regs *ctx) {
-	bpf_printk("--------[Uprobe HTTP Client] start");
-	__u64 goroutine_id = GOROUTINE(ctx);
-	bpf_printk("[Uprobe HTTP Client] goroutine_id:%llu",goroutine_id);
+	cw_bpf_debug("--------[Uprobe HTTP Client] start");
 
     u64 request_pos = 2;
     void *req_ptr = get_argument(ctx, request_pos);
@@ -386,7 +384,7 @@ int uprobe_Transport_roundTrip(struct pt_regs *ctx) {
     void *httpReq_ptr = bpf_map_lookup_elem(&http_events, &key);
     if (httpReq_ptr != NULL)
     {
-        bpf_printk("uprobe/Transport_RoundTrip already tracked with the current context");
+        cw_bpf_debug("uprobe/Transport_RoundTrip already tracked with the current context");
         return 0;
     }
 
@@ -394,7 +392,7 @@ int uprobe_Transport_roundTrip(struct pt_regs *ctx) {
     struct http_request_t *httpReq = bpf_map_lookup_elem(&http_client_uprobe_storage_map, &map_id);
     if (httpReq == NULL)
     {
-        bpf_printk("uprobe/Transport_roundTrip: httpReq is NULL");
+        cw_bpf_debug("uprobe/Transport_roundTrip: httpReq is NULL");
         return 0;
     }
 
@@ -403,13 +401,13 @@ int uprobe_Transport_roundTrip(struct pt_regs *ctx) {
 
     struct span_context *parent_span_ctx = get_parent_span_context(context_ptr_val);
     if (parent_span_ctx != NULL) {
-        bpf_printk("[Client] parent_span_ctx != NULL");
+        cw_bpf_debug("[Client] parent_span_ctx != NULL");
 
 //        bpf_probe_read(&httpReq->psc, sizeof(httpReq->psc), parent_span_ctx);
 //        copy_byte_arrays(httpReq->psc.TraceID, httpReq->sc.TraceID, TRACE_ID_SIZE);
 //        generate_random_bytes(httpReq->sc.SpanID, SPAN_ID_SIZE);
     } else {
-//        bpf_printk("[Client] parent_span_ctx == NULL");
+//        cw_bpf_debug("[Client] parent_span_ctx == NULL");
 //	    struct apm_span_context *apm_sc = get_tracking_span();
 //	    if (apm_sc) {
 //		    httpReq->sc = *(struct span_context *) apm_sc;
@@ -436,7 +434,7 @@ int uprobe_Transport_roundTrip(struct pt_regs *ctx) {
     }
 
     if (!get_go_string_from_user_ptr((void *)(req_ptr+method_ptr_pos), httpReq->method, sizeof(httpReq->method))) {
-        bpf_printk("uprobe_Transport_roundTrip: Failed to get method from request");
+        cw_bpf_debug("uprobe_Transport_roundTrip: Failed to get method from request");
         return 0;
     }
 
@@ -444,22 +442,22 @@ int uprobe_Transport_roundTrip(struct pt_regs *ctx) {
     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_printk("uprobe_Transport_roundTrip: Failed to get path from Request.URL");
+        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))) {
-        bpf_printk("uprobe_Transport_roundTrip: Failed to get host from Request");
+        cw_bpf_debug("uprobe_Transport_roundTrip: Failed to get host from Request");
     }
 	// TODO set request_host_pos
-	bpf_printk("[Client] httpReq->host:%llu",request_host_pos);
+	cw_bpf_debug("[Client] httpReq->host:%llu",request_host_pos);
 //	for (int i = 0; i < MAX_HOSTNAME_SIZE; ++i) {
 //		if (httpReq->host[i] == '\0') {
 //			break;
 //		}
 ////		httpReq->apm_sc.assumed_app_id[i] = httpReq->host[i];
-//		bpf_printk("[Client] httpReq->host:%c",httpReq->host[i]);
+//		cw_bpf_debug("[Client] httpReq->host:%c",httpReq->host[i]);
 //	}
 //	unsigned char hash[APM_ASSUMED_APP_ID_STRING_SIZE];
 
@@ -468,7 +466,7 @@ int uprobe_Transport_roundTrip(struct pt_regs *ctx) {
 	struct trace_conf_t *trace_conf = trace_conf_map__lookup(&k0);
 	if (trace_conf) {
 		for (int i = 0; i < 8; ++i) {
-//			bpf_printk("[Client] host_id:%02x", trace_conf->host_id[i]);
+//			cw_bpf_debug("[Client] host_id:%02x", trace_conf->host_id[i]);
 		}
 		copy_byte_arrays(trace_conf->host_id, httpReq->apm_sc.host_id, APM_HOST_ID_SIZE);
 		copy_byte_arrays(trace_conf->app_id, httpReq->apm_sc.app_id, APM_APP_ID_SIZE);
@@ -480,7 +478,7 @@ int uprobe_Transport_roundTrip(struct pt_regs *ctx) {
 			bpf_map_lookup_elem(&proc_info_map, &tgid);
 	if (proc_info) {
 		for (int i = 0; i < 8; ++i) {
-//			bpf_printk("[Client] instance_id:%02x", proc_info->instance_id[i]);
+//			cw_bpf_debug("[Client] instance_id:%02x", proc_info->instance_id[i]);
 		}
 		copy_byte_arrays(proc_info->instance_id, httpReq->apm_sc.instance_id, APM_APP_ID_SIZE);
 	}
@@ -490,7 +488,7 @@ int uprobe_Transport_roundTrip(struct pt_regs *ctx) {
 	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))) {
-        bpf_printk("uprobe_Transport_roundTrip: Failed to get proto from Request");
+        cw_bpf_debug("uprobe_Transport_roundTrip: Failed to get proto from Request");
     }
 
     // get headers from Request
@@ -499,11 +497,11 @@ int uprobe_Transport_roundTrip(struct pt_regs *ctx) {
 //    long res = inject_header(headers_ptr, &httpReq->sc);
 //    long res = cw_inject_header(headers_ptr, &httpReq->apm_sc);
 //    if (res < 0) {
-//        bpf_printk("uprobe_Transport_roundTrip: Failed to inject header");
+//        cw_bpf_debug("uprobe_Transport_roundTrip: Failed to inject header");
 //    }
 	long res2 = cw_inject_header2(headers_ptr, &httpReq->apm_sc);
 	if (res2 < 0) {
-		bpf_printk("uprobe_Transport_roundTrip: Failed to inject header");
+		cw_bpf_debug("uprobe_Transport_roundTrip: Failed to inject header");
 	}
 
     // Write event
@@ -516,7 +514,7 @@ int uprobe_Transport_roundTrip(struct pt_regs *ctx) {
 // func net/http/transport.roundTrip(req *Request) (*Response, error)
 SEC("uprobe/Transport_roundTrip")
 int uprobe_Transport_roundTrip_Returns(struct pt_regs *ctx) {
-	bpf_printk("[Uprobe HTTP Client] start Return----------");
+	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);
@@ -524,7 +522,7 @@ int uprobe_Transport_roundTrip_Returns(struct pt_regs *ctx) {
 
     struct http_request_t *http_req_span = bpf_map_lookup_elem(&http_events, &key);
     if (http_req_span == NULL) {
-        bpf_printk("probe_Transport_roundTrip_Returns: entry_state is NULL");
+        cw_bpf_debug("probe_Transport_roundTrip_Returns: entry_state is NULL");
         return 0;
     }
 

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

@@ -169,16 +169,16 @@ static __always_inline struct span_context *extract_context_from_req_headers(voi
 			}
 //			if (!bpf_memcmp(current_header_key, "traceparent", W3C_KEY_LENGTH) && !bpf_memcmp(current_header_key, "Traceparent", W3C_KEY_LENGTH))
 //			{
-//				bpf_printk("not find it");
+//				cw_bpf_debug("not find it");
 //				continue;
 //			}
-//			bpf_printk("find it:%s", map_value->keys[i].str);
+//			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),
 			                     traceparent_header_value_ptr);
 			// 00-95b5ec2b81e2374a4a27ce36ab71d349-18f65a5a3ab22213-02
-			bpf_printk("traceparent_header_value_go_str.str:%s", traceparent_header_value_go_str.str);
+			cw_bpf_debug("traceparent_header_value_go_str.str:%s", traceparent_header_value_go_str.str);
 
 			if (res < 0) {
 				return NULL;
@@ -190,9 +190,9 @@ static __always_inline struct span_context *extract_context_from_req_headers(voi
 			res = bpf_probe_read(&traceparent_header_value, sizeof(traceparent_header_value),
 			                     traceparent_header_value_go_str.str);
 			// 00-95b5ec2b81e2374a4a27ce36ab71d349-18f65a5a3ab22213-02��c�����c����@c;
-//			bpf_printk("traceparent_header_value11:[%s]", traceparent_header_value);
+//			cw_bpf_debug("traceparent_header_value11:[%s]", traceparent_header_value);
 
-//			bpf_printk("111111111111111111:[%d]", range.start[1]);
+//			cw_bpf_debug("111111111111111111:[%d]", range.start[1]);
 
 
 			if (res < 0) {
@@ -201,12 +201,12 @@ static __always_inline struct span_context *extract_context_from_req_headers(voi
 
 			struct span_context *parent_span_context = bpf_map_lookup_elem(&parent_span_context_storage_map, &map_id);
 			if (!parent_span_context) {
-				bpf_printk("no parent_span_context");
+				cw_bpf_debug("no parent_span_context");
 				return NULL;
 			}
 			struct apm_span_context *cw_parent_span_context = bpf_map_lookup_elem(&cw_parent_span_context_storage_map, &map_id);
 			if (!cw_parent_span_context) {
-				bpf_printk("no cw_parent_span_context");
+				cw_bpf_debug("no cw_parent_span_context");
 				return NULL;
 			}
 
@@ -219,21 +219,21 @@ static __always_inline struct span_context *extract_context_from_req_headers(voi
 
 
 //            for (int i = 0; i < TRACE_ID_SIZE; i++) {
-//                bpf_printk("%02x", parent_span_context->TraceID[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) {
-//				bpf_printk("traceid--%c",val[i]);
+//				cw_bpf_debug("traceid--%c",val[i]);
 //			}
 
 
 
 //
 //			for (int i = 0; i < 1; i++) {
-//				bpf_printk("type_from------%02x", cw_parent_span_context->type_from[i]);
+//				cw_bpf_debug("type_from------%02x", cw_parent_span_context->type_from[i]);
 //			}
 //
 //			char val[2];
@@ -241,14 +241,14 @@ static __always_inline struct span_context *extract_context_from_req_headers(voi
 ////			// Write trace id
 //			bytes_to_hex_string(cw_parent_span_context->type_from, 1, out);
 //
-//			bpf_printk("type_from1--%s", out);
+//			cw_bpf_debug("type_from1--%s", out);
 
 //			for (int i = 0; i < 10; ++i) {
-//				bpf_printk("traceid--%c",val[i]);
+//				cw_bpf_debug("traceid--%c",val[i]);
 //			}
 
-//			bpf_printk("parent_span_context-TraceID2:%s", parent_span_context->TraceID);
-//			bpf_printk("parent_span_context-SpanID2:%s", parent_span_context->SpanID);
+//			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;
@@ -261,19 +261,19 @@ static __always_inline struct span_context *extract_context_from_req_headers(voi
 // func (sh serverHandler) ServeHTTP(rw ResponseWriter, req *Request)
 SEC("uprobe/HandlerFunc_ServeHTTP")
 int uprobe_HandlerFunc_ServeHTTP(struct pt_regs *ctx) {
-	bpf_printk("[uprobe_HandlerFunc_ServeHTTP]");
+	cw_bpf_debug("[uprobe_HandlerFunc_ServeHTTP]");
 	void *req_ctx_ptr = get_Go_context(ctx, 4, 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) {
-		bpf_printk("uprobe/HandlerFunc_ServeHTTP already tracked with the current request");
+		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) {
-		bpf_printk("uprobe/HandlerFunc_ServeHTTP: http_server_span is NULL");
+		cw_bpf_debug("uprobe/HandlerFunc_ServeHTTP: http_server_span is NULL");
 		return 0;
 	}
 
@@ -311,21 +311,21 @@ int uprobe_HandlerFunc_ServeHTTP(struct pt_regs *ctx) {
 	}
 
 	if (req_ctx_ptr == NULL) {
-//		bpf_printk("uprobe/HandlerFunc_ServeHTTP: req_ctx_ptr is NULL");
+//		cw_bpf_debug("uprobe/HandlerFunc_ServeHTTP: req_ctx_ptr is NULL");
 		return 0;
 	}
-//	bpf_printk("found parent context in http headers");
+//	cw_bpf_debug("found parent context in http headers");
 
-//	bpf_printk("parent_span_context-TraceID---");
+//	cw_bpf_debug("parent_span_context-TraceID---");
 
 
 //    for (int i = 0; i < TRACE_ID_SIZE; i++) {
-//        bpf_printk("%02x", uprobe_data->span.sc.TraceID[i]);
+//        cw_bpf_debug("%02x", uprobe_data->span.sc.TraceID[i]);
 //    }
 
-//    bpf_printk("parent_span_context-SpanID---");
+//    cw_bpf_debug("parent_span_context-SpanID---");
 //    for (int i = 0; i < SPAN_ID_SIZE; i++) {
-//        bpf_printk("%02x", uprobe_data->span.sc.SpanID[i]);
+//        cw_bpf_debug("%02x", uprobe_data->span.sc.SpanID[i]);
 //    }
 
 //	bpf_map_update_elem(&http_server_uprobes, &key, uprobe_data, 0);
@@ -339,7 +339,7 @@ int uprobe_HandlerFunc_ServeHTTP(struct pt_regs *ctx) {
 void read_go_string(void *base, int offset, char *output, int maxLen, const char *errorMsg) {
 	void *ptr = (void *) (base + offset);
 	if (!get_go_string_from_user_ptr(ptr, output, maxLen)) {
-		bpf_printk("Failed to get %s", errorMsg);
+		cw_bpf_debug("Failed to get %s", errorMsg);
 	}
 
 }
@@ -348,14 +348,14 @@ void read_go_string(void *base, int offset, char *output, int maxLen, const char
 // func (sh serverHandler) ServeHTTP(rw ResponseWriter, req *Request)
 SEC("uprobe/HandlerFunc_ServeHTTP")
 int uprobe_HandlerFunc_ServeHTTP_Returns(struct pt_regs *ctx) {
-	bpf_printk("[uprobe_HandlerFunc_ServeHTTP_Returns]");
+	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);
 	void *key = get_consistent_key(ctx, req_ctx_ptr);
 
 	struct uprobe_data_t *uprobe_data = bpf_map_lookup_elem(&http_server_uprobes, &key);
 	if (uprobe_data == NULL) {
-		bpf_printk("uprobe/HandlerFunc_ServeHTTP_Returns: entry_state is NULL");
+		cw_bpf_debug("uprobe/HandlerFunc_ServeHTTP_Returns: entry_state is NULL");
 		return 0;
 	}
 	bpf_map_delete_elem(&http_server_uprobes, &key);
@@ -389,6 +389,6 @@ int uprobe_HandlerFunc_ServeHTTP_Returns(struct pt_regs *ctx) {
 
 
 	clear_parent_span_context();
-	bpf_printk("HTTP_END");
+	cw_bpf_debug("HTTP_END");
 	return 0;
 }

+ 1 - 1
ebpftracer/tls.go

@@ -258,7 +258,7 @@ func (t *Tracer) AttachGoTlsUprobes(pid uint32, insID utils.ID) []link.Link {
 				break
 			}
 		}
-		fmt.Println("s.Name-----:", s.Name)
+		//fmt.Println("s.Name-----:", s.Name)
 
 		switch s.Name {
 		case goExecute:

+ 19 - 20
ebpftracer/tracer.go

@@ -23,7 +23,6 @@ import (
 	"strconv"
 	"strings"
 	"time"
-	"unsafe"
 )
 
 /*
@@ -504,10 +503,18 @@ func runEventsReader(name string, r *perf.Reader, ch chan<- Event, typ perfMapTy
 			//socketDataBuffer := rec.RawSample
 
 			// 解析 __socket_data_buffer
-			buf := (*SocketDataBuffer)(unsafe.Pointer(&rec.RawSample[0])) //nolint:gosec
-
-			// 获取 char data[32760];
-			socketData := (*SocketData)(unsafe.Pointer(&buf.data[0])) //nolint:gosec
+			//buf := (*SocketDataBuffer)(unsafe.Pointer(&rec.RawSample[0])) //nolint:gosec
+			//
+			//// 获取 char data[32760];
+			//socketData := (*SocketData)(unsafe.Pointer(&buf.data[0])) //nolint:gosec
+			//// todo
+			//fmt.Printf("socketData.DataType:%d \n", (socketData.data_type))
+			//fmt.Printf("socketData.DataLen:%d \n", (socketData.data_len))
+			//
+			//// 解析C结构体中的data字段
+			//dataSlice := C.GoBytes(unsafe.Pointer(&socketData.data[0]), C.int(socketData.data_len))
+			//// 打印或处理包含的数据
+			//fmt.Printf("socketData.Payload:%v \n", string(dataSlice))
 
 			/*todo */
 			//socketData := (*(*[128]byte)(unsafe.Pointer(&eventC.line)))
@@ -535,14 +542,6 @@ func runEventsReader(name string, r *perf.Reader, ch chan<- Event, typ perfMapTy
 			//fmt.Println("socketData.MsgType:", socketData.MsgType)
 			//fmt.Println("socketData.SyscallLen:", socketData.SyscallLen)
 			//fmt.Println("socketData.DataSeq:", socketData.DataSeq)
-			// todo
-			fmt.Printf("socketData.DataType:%d \n", (socketData.data_type))
-			fmt.Printf("socketData.DataLen:%d \n", (socketData.data_len))
-
-			// 解析C结构体中的data字段
-			dataSlice := C.GoBytes(unsafe.Pointer(&socketData.data[0]), C.int(socketData.data_len))
-			// 打印或处理包含的数据
-			fmt.Printf("socketData.Payload:%v \n", string(dataSlice))
 
 			//socketData := &SocketData{}
 			//reader := bytes.NewBuffer(rec.RawSample)
@@ -586,13 +585,13 @@ func runEventsReader(name string, r *perf.Reader, ch chan<- Event, typ perfMapTy
 				klog.Warningln("failed to read msg:", err)
 				continue
 			}
-			fmt.Println("v.TraceIdFrom")
-			fmt.Println(v.TraceIdFrom)
-			a := hex.EncodeToString(v.TraceIdFrom[:])
+			//fmt.Println("v.TraceIdFrom")
+			//fmt.Println(v.TraceIdFrom)
+			//a := hex.EncodeToString(v.TraceIdFrom[:])
 			//for _, b := range v.AssumedAppId {
 			//	fmt.Printf("v.AssumedAppId- %02\n", b)
 			//}
-			fmt.Println(a)
+			//fmt.Println(a)
 
 			payload := reader.Bytes()
 			req := &l7.RequestData{
@@ -621,9 +620,9 @@ func runEventsReader(name string, r *perf.Reader, ch chan<- Event, typ perfMapTy
 			default:
 				req.Payload = payload[:v.PayloadSize]
 			}
-			fmt.Println("==========")
-			fmt.Println("req.Payload:", string(req.Payload))
-			fmt.Println("==========")
+			//fmt.Println("==========")
+			//fmt.Println("req.Payload:", string(req.Payload))
+			//fmt.Println("==========")
 			event = Event{Type: EventTypeL7Request, Pid: v.Pid, Fd: v.Fd, Timestamp: v.ConnectionTimestamp, L7Request: req}
 		case perfMapTypeFileEvents:
 			v := &fileEvent{}

+ 19 - 11
pkg/go.opentelemetry.io/otel/exporters/otlp/otlptrace/apm_exporter.go

@@ -2,7 +2,6 @@ package otlptrace
 
 import (
 	"crypto/md5"
-	"encoding/json"
 	"fmt"
 	"go.opentelemetry.io/otel/exporters/otlp/otlptrace/internal/tracetransform"
 	tracesdk "go.opentelemetry.io/otel/sdk/trace"
@@ -10,6 +9,7 @@ import (
 	"strconv"
 	"strings"
 	"sync"
+	"time"
 )
 
 const (
@@ -109,10 +109,18 @@ var TraceRootMap map[string]*TraceMapT
 
 func init() {
 	TraceRootMap = make(map[string]*TraceMapT)
+	go func() {
+		for {
+			fmt.Println(G_sdl)
+			time.Sleep(5 * time.Second)
+		}
+	}()
 }
 
+var G_sdl int
+
 func tracetransformData(sdl []tracesdk.ReadOnlySpan) []RootDataT {
-	fmt.Println("len sdl", len(sdl))
+	G_sdl += len(sdl)
 	if len(sdl) == 0 {
 		return nil
 	}
@@ -134,18 +142,18 @@ func tracetransformData(sdl []tracesdk.ReadOnlySpan) []RootDataT {
 		if v.TheEnd {
 			sendData = append(sendData, v.RootData)
 			delete(TraceRootMap, traceId)
-			fmt.Println("the end!")
+			//fmt.Println("the end!")
 		} else {
-			fmt.Println("not end!")
+			//fmt.Println("not end!")
 		}
 	}
 
 	// Transform the categorized map into a slice
-	aa, err := json.Marshal(sendData)
-	fmt.Println(err)
-	fmt.Println(string(aa))
-	fmt.Println(len(sendData))
-	fmt.Println(len(sdl))
+	//aa, err := json.Marshal(sendData)
+	//fmt.Println(err)
+	//fmt.Println(string(aa))
+	//fmt.Println(len(sendData))
+	//fmt.Println(len(sdl))
 	return sendData
 }
 
@@ -248,7 +256,7 @@ func buildAppMap(mNode *MapInfoT, traceRoot *TraceMapT, sd apmTraceSpan) {
 	traceRoot.RootData.CollTime = mNode.StartTime
 	traceRoot.Index = 1
 	for _, attr := range sd.Attributes() {
-		fmt.Println(attr.Key, ":", attr.Value.AsInterface())
+		//fmt.Println(attr.Key, ":", attr.Value.AsInterface())
 		switch attr.Key {
 		case "http.uri":
 			traceRoot.RootData.Uri = attr.Value.AsString()
@@ -285,7 +293,7 @@ func buildHttpMap(mNode *MapInfoT, sd apmTraceSpan) {
 	mNode.MethodName = "net/http.serverHandler.ServeHTTP()"
 	var descAddr string
 	for _, attr := range sd.Attributes() {
-		fmt.Println(attr.Key, ":", attr.Value.AsInterface())
+		//fmt.Println(attr.Key, ":", attr.Value.AsInterface())
 		switch attr.Key {
 		case "http.ip":
 			mNode.Ip = attr.Value.AsString()

+ 0 - 1
tracing/apm_tracing.go

@@ -124,7 +124,6 @@ func (t *Trace) RedisTraceQuery(cmd, args string, error bool, duration time.Dura
 }
 
 func (t *Trace) HttpTraceRequest(method, path, ip string, port uint16, r *l7.RequestData) {
-	fmt.Println("HttpTraceRequest:", method, path, ip, port)
 	if t == nil || method == "" {
 		return
 	}