Переглянути джерело

Feature #TASK_QT-31498 去除内核打印

Carl 5 місяців тому
батько
коміт
57be071dc3

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

@@ -449,7 +449,7 @@ int trace_enter_write(void *ctx, __u64 fd, __u16 is_tls, char *buf, __u64 size,
 		    cw_copy_byte_arrays(cw_psc->span_id, e->span_id_from, APM_SPAN_ID_SIZE);
             cw_copy_byte_arrays(cw_psc->type_from, e->type_from, APM_TYPE_FROM_SIZE);
             cw_copy_byte_arrays(cw_psc->sysvs, e->sysvc_from, CW_SYS_HEADER_VAL_LENGTH);
-		    bpf_printk("trace_end %s",cw_psc->sysvs);
+//		    bpf_printk("trace_end %s",cw_psc->sysvs);
 		    // for (int i = 0; i < APM_TYPE_FROM_SIZE; i++) {
 			//     bpf_printk("trace_enter_write - type_from = %02x", e->type_from[i]);
 		    // }

+ 1 - 1
ebpftracer/ebpf/utrace/go/db/gocql.probe.bpf.c

@@ -305,7 +305,7 @@ int uprobe_Session_executeQuery_cassandra(struct pt_regs *ctx) {
     __u64 pid_tgid = bpf_get_current_pid_tgid();
     __u32 tgid = pid_tgid >> 32;
     
-    bpf_printk("[cassandra] enter Session.executeQuery");
+//    bpf_printk("[cassandra] enter Session.executeQuery");
     
     struct ebpf_proc_info *info = bpf_map_lookup_elem(&proc_info_map, &tgid);
     if (!info) {

+ 15 - 15
ebpftracer/ebpf/utrace/go/mq/kafka/consumer.probe.bpf.c

@@ -137,7 +137,7 @@ int uprobe_FetchMessage(struct pt_regs *ctx) {
 	
 	struct kafka_consumer_request_t *kafka_request = bpf_map_lookup_elem(&kafka_consumer_events, &goroutine);
 	if (kafka_request == NULL || reader == NULL) {
-//		bpf_printk("kafka goto end");
+//		cw_bpf_debug("kafka goto end");
 		// The current goroutine has no kafka request,
 		// this can happen in the first time FetchMessage is called
 		// Save the context for the return probe for in-process context propagation
@@ -191,8 +191,8 @@ int uprobe_FetchMessage(struct pt_regs *ctx) {
 		// 填充 MQ 相关信息
 		bpf_probe_read(&e->mq.topic, sizeof(e->mq.topic), kafka_request->topic);
 		bpf_probe_read(&e->mq.key, sizeof(e->mq.key), kafka_request->key);
-		bpf_printk("kafka_request->key %s",kafka_request->key);
-		bpf_printk("kafka_request->topic %s",kafka_request->topic);
+		cw_bpf_debug("kafka_request->key %s",kafka_request->key);
+		cw_bpf_debug("kafka_request->topic %s",kafka_request->topic);
 
 		bpf_map_delete_elem(&trace_event_count_heap, &e->trace_id);
 		// 清除业务层trace信息
@@ -227,7 +227,7 @@ int uprobe_FetchMessage_Returns(struct pt_regs *ctx) {
 	u32 map_id = 0;
 	struct kafka_consumer_request_t *kafka_request = bpf_map_lookup_elem(&kafka_consumer_request_storage_map, &map_id);
 	if (kafka_request == NULL) {
-		bpf_printk("uprobe/FetchMessage_Returns: kafka_request is NULL");
+		cw_bpf_debug("uprobe/FetchMessage_Returns: kafka_request is NULL");
 		return 0;
 	}
 
@@ -236,7 +236,7 @@ int uprobe_FetchMessage_Returns(struct pt_regs *ctx) {
 	__u32 tgid = pid_tgid >> 32;
 	struct ebpf_proc_info *proc_info = bpf_map_lookup_elem(&proc_info_map, &tgid);
 	if (proc_info == NULL) {
-		bpf_printk("uprobe/FetchMessage_Returns: proc_info is NULL");
+		cw_bpf_debug("uprobe/FetchMessage_Returns: proc_info is NULL");
 		return 0;
 	}
 
@@ -245,12 +245,12 @@ int uprobe_FetchMessage_Returns(struct pt_regs *ctx) {
 	if (proc_info->kafka_message_value_pos != 0) {
 		struct go_slice_ot value_slice = {0};
 		bpf_probe_read(&value_slice, sizeof(value_slice), (void *)(message + proc_info->kafka_message_value_pos));
-//		bpf_printk("len %d",value_slice.len);
+//		cw_bpf_debug("len %d",value_slice.len);
 		if (value_slice.array == NULL) {
-//			bpf_printk("no val");
+//			cw_bpf_debug("no val");
 			return 0;
 		} else {
-			bpf_printk("has val %llu", goroutine);
+			cw_bpf_debug("has val %llu", goroutine);
 		}
 	} else {
 		return 0;
@@ -265,7 +265,7 @@ int uprobe_FetchMessage_Returns(struct pt_regs *ctx) {
 
 	kafka_request->start_time = bpf_ktime_get_ns();
 
-//	bpf_printk("start %llu",message);
+//	cw_bpf_debug("start %llu",message);
 
 //	struct go_iface go_context = {0};
 //	get_Go_context(ctx, 2, 0, true, &go_context);
@@ -291,9 +291,9 @@ int uprobe_FetchMessage_Returns(struct pt_regs *ctx) {
 //		generate_random_bytes(kafka_request->psc.trace_id, TRACE_ID_SIZE);
 //	}
 	if (extract_result == 0) {
-		bpf_printk("find");
+		cw_bpf_debug("find");
 		for (int i = 0; i < APM_TRACE_ID_SIZE; i++) {
-			bpf_printk("cw_get_current_tracking_span-trace_id[%d] = %02x", i, kafka_request->psc.trace_id[i]);
+			cw_bpf_debug("cw_get_current_tracking_span-trace_id[%d] = %02x", i, kafka_request->psc.trace_id[i]);
 		}
 		// Successfully extracted parent span context from headers
 //		kafka_request->psc = *parent_span_context;
@@ -304,14 +304,14 @@ int uprobe_FetchMessage_Returns(struct pt_regs *ctx) {
 //		if (parent_sc != NULL) {
 //			kafka_request->psc = *parent_sc;
 //		}
-		bpf_printk("no header");
+		cw_bpf_debug("no header");
 	}
 
 	// Collecting message attributes
 	// topic
 	get_go_string_from_user_ptr(
 			(void *)(message + proc_info->kafka_message_topic_pos), kafka_request->topic, sizeof(kafka_request->topic));
-	bpf_printk("topic %s",kafka_request->topic);
+	cw_bpf_debug("topic %s",kafka_request->topic);
 	// Key is a byte slice, first read the slice
 	if (proc_info->kafka_message_key_pos != 0) {
 		struct go_slice_ot key_slice = {0};
@@ -345,12 +345,12 @@ int uprobe_FetchMessage_Returns(struct pt_regs *ctx) {
 		// Send event
 		long error = bpf_perf_event_output(ctx, &l7_events, BPF_F_CURRENT_CPU, e, sizeof(*e));
 		if (error == 0) {
-			bpf_printk("send start ok");
+			cw_bpf_debug("send start ok");
 //			cw_add_event_count(e->trace_id);
 //			cw_bpf_debug("[kafka consumer] send success trace %llu", e->trace_id);
 		}
 	} else {
-		bpf_printk("no e");
+		cw_bpf_debug("no e");
 	}
 //	return 0;
 

+ 22 - 22
ebpftracer/ebpf/utrace/go/mq/kafka/producer.probe.bpf.c

@@ -138,7 +138,7 @@ struct tcp_addr {
 
 static __always_inline int build_contxet_header(struct kafka_header_t *header, struct apm_span_context *span_ctx) {
 	if (header == NULL || span_ctx == NULL) {
-		bpf_printk("build_contxt_header: Invalid arguments");
+		cw_bpf_debug("build_contxt_header: Invalid arguments");
 		return -1;
 	}
 
@@ -146,7 +146,7 @@ static __always_inline int build_contxet_header(struct kafka_header_t *header, s
 	u32 temp_strings_id = 0;
 	struct kafka_temp_strings_t *temp_strings = bpf_map_lookup_elem(&kafka_temp_strings_storage_map, &temp_strings_id);
 	if (temp_strings == NULL) {
-		bpf_printk("build_contxt_header: Failed to get temp strings storage");
+		cw_bpf_debug("build_contxt_header: Failed to get temp strings storage");
 		return -1;
 	}
 
@@ -154,7 +154,7 @@ static __always_inline int build_contxet_header(struct kafka_header_t *header, s
 	__u32 tgid = pid_tgid >> 32;
 	struct ebpf_proc_info *proc_info = bpf_map_lookup_elem(&proc_info_map, &tgid);
 	if (proc_info == NULL) {
-		bpf_printk("uprobe/WriteMessages: proc_info is NULL");
+		cw_bpf_debug("uprobe/WriteMessages: proc_info is NULL");
 		return 0;
 	}
 
@@ -162,7 +162,7 @@ static __always_inline int build_contxet_header(struct kafka_header_t *header, s
 	__builtin_memcpy(temp_strings->key, CW_HEADER_KEY_VAL, CW_HEADER_KEY_LENGTH);
 	void *ptr = cw_write_target_data(temp_strings->key, CW_HEADER_KEY_LENGTH, proc_info);
 	if (ptr == NULL) {
-		bpf_printk("build_contxt_header: Failed to write key to user");
+		cw_bpf_debug("build_contxt_header: Failed to write key to user");
 		return -1;
 	}
 
@@ -199,10 +199,10 @@ static __always_inline int build_contxet_header(struct kafka_header_t *header, s
 
 	span_context_to_cw_string(span_ctx, temp_strings->val);
 
-	bpf_printk("%s",temp_strings->val);
+	cw_bpf_debug("%s",temp_strings->val);
 	ptr = cw_write_target_data(temp_strings->val, CW_HEADER_VAL_LENGTH, proc_info);
 	if (ptr == NULL) {
-		bpf_printk("build_contxt_header: Failed to write value to user");
+		cw_bpf_debug("build_contxt_header: Failed to write value to user");
 		return -1;
 	}
 
@@ -210,7 +210,7 @@ static __always_inline int build_contxet_header(struct kafka_header_t *header, s
 	header->value.array = ptr;
 	header->value.len = CW_HEADER_VAL_LENGTH;
 	header->value.cap = CW_HEADER_VAL_LENGTH;
-	bpf_printk("build_contxt_header success");
+	cw_bpf_debug("build_contxt_header success");
 	return 0;
 }
 
@@ -249,7 +249,7 @@ int uprobe_WriteMessages(struct pt_regs *ctx) {
 
 	void *kafka_request_ptr = bpf_map_lookup_elem(&kafka_events, &key);
 	if (kafka_request_ptr != NULL) {
-		bpf_printk("uprobe/WriteMessages already tracked with the current context");
+		cw_bpf_debug("uprobe/WriteMessages already tracked with the current context");
 		return 0;
 	}
 
@@ -258,7 +258,7 @@ int uprobe_WriteMessages(struct pt_regs *ctx) {
 	__u32 tgid = pid_tgid >> 32;
 	struct ebpf_proc_info *proc_info = bpf_map_lookup_elem(&proc_info_map, &tgid);
 	if (proc_info == NULL) {
-		bpf_printk("uprobe/WriteMessages: proc_info is NULL");
+		cw_bpf_debug("uprobe/WriteMessages: proc_info is NULL");
 		return 0;
 	}
 
@@ -266,7 +266,7 @@ int uprobe_WriteMessages(struct pt_regs *ctx) {
 	u32 zero_id = 0;
 	struct kafka_request_t *zero_kafka_request = bpf_map_lookup_elem(&kafka_request_storage_map, &zero_id);
 	if (zero_kafka_request == NULL) {
-		bpf_printk("uuprobe/WriteMessages: zero_kafka_request is NULL");
+		cw_bpf_debug("uuprobe/WriteMessages: zero_kafka_request is NULL");
 		return 0;
 	}
 
@@ -276,7 +276,7 @@ int uprobe_WriteMessages(struct pt_regs *ctx) {
 	// Get a pointer to the zeroed span
 	struct kafka_request_t *kafka_request = bpf_map_lookup_elem(&kafka_request_storage_map, &actual_id);
 	if (kafka_request == NULL) {
-		bpf_printk("uprobe/WriteMessages: Failed to get kafka_request");
+		cw_bpf_debug("uprobe/WriteMessages: Failed to get kafka_request");
 		return 0;
 	}
 
@@ -307,7 +307,7 @@ int uprobe_WriteMessages(struct pt_regs *ctx) {
 //	}
 
 //	u64 size_to_read = user_str.len > 22 ? 22 : user_str.len;
-//	bpf_printk("%s",user_str.str);
+//	cw_bpf_debug("%s",user_str.str);
 //	return 0;
 //	success = bpf_probe_read(dst, size_to_read, user_str.str);
 
@@ -330,14 +330,14 @@ int uprobe_WriteMessages(struct pt_regs *ctx) {
 //	__builtin_memset(assumed_app_id, 0, sizeof(assumed_app_id));
 //
 //	set_app_id_numeric16(kafka_request->broker_addr, assumed_app_id);
-//	bpf_printk("digit[%d]=%c", 0, assumed_app_id[0]);
+//	cw_bpf_debug("digit[%d]=%c", 0, assumed_app_id[0]);
 //	return 0;
 
 //	set_assumed_app_id_arrays2(kafka_request->broker_addr, assumed_app_id);
 	/*临时map绕一下*/
 //	struct kafka_request_t2 *kafka_request2 = bpf_map_lookup_elem(&kafka_request_storage_map2, &actual_id);
 //	if (kafka_request2 == NULL) {
-//		bpf_printk("uprobe/WriteMessages: Failed to get kafka_request");
+//		cw_bpf_debug("uprobe/WriteMessages: Failed to get kafka_request");
 //		return 0;
 //	}
 //	__builtin_memset(kafka_request2, 0, sizeof(struct kafka_request_t2));
@@ -357,7 +357,7 @@ int uprobe_WriteMessages(struct pt_regs *ctx) {
 
 
 
-	bpf_printk("Kafka BrokerAddr = %s", kafka_request->host);
+	cw_bpf_debug("Kafka BrokerAddr = %s", kafka_request->host);
 	struct apm_span_context *cw_psc = cw_get_parent_tracking_span();
 
 	if(cw_psc){
@@ -373,7 +373,7 @@ int uprobe_WriteMessages(struct pt_regs *ctx) {
 	bool global_topic = get_go_string_from_user_ptr((void *) (writer + proc_info->kafka_writer_topic_pos), kafka_request->global_topic,
 	                                                sizeof(kafka_request->global_topic));
 
-	bpf_printk("global_topic %d %s",global_topic,kafka_request->global_topic);
+	cw_bpf_debug("global_topic %d %s",global_topic,kafka_request->global_topic);
 
 
 	void *msg_ptr = msgs_array;
@@ -381,7 +381,7 @@ int uprobe_WriteMessages(struct pt_regs *ctx) {
 	u32 header_storage_id = 0;
 	struct kafka_header_t *header = bpf_map_lookup_elem(&kafka_header_storage_map, &header_storage_id);
 	if (header == NULL) {
-		bpf_printk("uprobe/WriteMessages: Failed to get header storage");
+		cw_bpf_debug("uprobe/WriteMessages: Failed to get header storage");
 		return 0;
 	}
 	// Zero the header
@@ -420,7 +420,7 @@ int uprobe_WriteMessages(struct pt_regs *ctx) {
 #ifndef NO_HEADER_PROPAGATION
 		// Build the header
 		if (build_contxet_header(header, &kafka_request->msgs[i].sc) != 0) {
-			bpf_printk("uprobe/WriteMessages: Failed to build header");
+			cw_bpf_debug("uprobe/WriteMessages: Failed to build header");
 			return 0;
 		}
 		// Inject the header
@@ -445,7 +445,7 @@ int uprobe_WriteMessages_Returns(struct pt_regs *ctx) {
 
 	struct kafka_request_t *kafka_request = bpf_map_lookup_elem(&kafka_events, &key);
 	if (kafka_request == NULL) {
-		bpf_printk("kafka_request is null\n");
+		cw_bpf_debug("kafka_request is null\n");
 		return 0;
 	}
 	kafka_request->end_time = bpf_ktime_get_ns();
@@ -488,8 +488,8 @@ int uprobe_WriteMessages_Returns(struct pt_regs *ctx) {
 //		bpf_probe_read(&e->payload, 22, kafka_request->host);
 //		bpf_probe_read(&e->payload , 50, kafka_request->msgs[i].topic);
 
-//		bpf_printk("tttttttttttttt %s", kafka_request->msgs[i].topic);
-//		bpf_printk("kkkkkkkkkk %s", kafka_request->msgs[i].key);
+//		cw_bpf_debug("tttttttttttttt %s", kafka_request->msgs[i].topic);
+//		cw_bpf_debug("kkkkkkkkkk %s", kafka_request->msgs[i].key);
 
 		// 填充 MQ 相关信息
 		bpf_probe_read(&e->mq.topic, sizeof(e->mq.topic), kafka_request->msgs[i].topic);
@@ -537,7 +537,7 @@ int uprobe_WriteMessages_Returns(struct pt_regs *ctx) {
 
 //		kafka_request->msgs[i].sc.span_id;
 //		for (int j = 0; j < 1; ++j) {
-//			bpf_printk("valid_messages %02x",kafka_request->msgs[i].sc.span_id[j]);
+//			cw_bpf_debug("valid_messages %02x",kafka_request->msgs[i].sc.span_id[j]);
 //		}
 	}
 

+ 6 - 6
ebpftracer/ebpf/utrace/go/net/grpc.client.probe.bpf.c

@@ -72,19 +72,19 @@ struct {
 
 // Injected in init
 // volatile const u64 clientconn_target_ptr_pos;
-u64 clientconn_target_ptr_pos = 24; //使用固定值24即可,不再处理多版本场景。
+#define clientconn_target_ptr_pos  24 //使用固定值24即可,不再处理多版本场景。
 // volatile const u64 httpclient_nextid_pos;
 // u64 httpclient_nextid_pos = 404;    //处理多版本,通过变量获取吧
 // volatile const u64 headerFrame_streamid_pos;
-u64 headerFrame_streamid_pos = 0;   //使用固定值0即可,不再处理多版本场景。
+#define headerFrame_streamid_pos  0   //使用固定值0即可,不再处理多版本场景。
 // volatile const u64 headerFrame_hf_pos;
-u64 headerFrame_hf_pos = 8;          //使用固定值8即可,不再处理多版本场景。
+#define headerFrame_hf_pos  8          //使用固定值8即可,不再处理多版本场景。
 // volatile const u64 error_status_pos;
-u64 error_status_pos = 0;           //使用固定值0即可,不再处理多版本场景。
+#define error_status_pos  0           //使用固定值0即可,不再处理多版本场景。
 // volatile const u64 status_s_pos;
-// static u64 status_s_pos = 0;
+// static u64 status_s_pos  0;
 // volatile const u64 status_message_pos;
-u64 status_message_pos = 48;        //使用固定值48即可,不再处理多版本场景。
+#define status_message_pos  48        //使用固定值48即可,不再处理多版本场景。
 // volatile const u64 status_code_pos;
 // static u64 status_code_pos = 40;
 

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

@@ -58,21 +58,21 @@ struct hpack_header_field {
 // volatile const u64 stream_method_ptr_pos;
 // u64 stream_method_ptr_pos = 80; //需要处理多版本场景
 // volatile const u64 frame_fields_pos;
-u64 frame_fields_pos = 8;       //使用固定值8即可,不再处理多版本场景。
+#define frame_fields_pos  8       //使用固定值8即可,不再处理多版本场景。
 // volatile const u64 frame_stream_id_pod;
-u64 frame_stream_id_pod = 8;    //使用固定值8即可,不再处理多版本场景。
+#define frame_stream_id_pod  8    //使用固定值8即可,不再处理多版本场景。
 // volatile const u64 stream_id_pos;
-u64 stream_id_pos = 0;          //使用固定值0即可,不再处理多版本场景。
+#define stream_id_pos  0          //使用固定值0即可,不再处理多版本场景。
 // volatile const u64 stream_ctx_pos;
-// u64 stream_ctx_pos = 32;        //需要做多版本处理  
+// u64 stream_ctx_pos  32        //需要做多版本处理
 // volatile const u64 server_stream_stream_pos;
-u64 server_stream_stream_pos = 0;   //1.69之前版本用不到,1.69之后版本用这个
+#define server_stream_stream_pos  0   //1.69之前版本用不到,1.69之后版本用这个
 // volatile const bool is_new_frame_pos;
 // bool is_new_frame_pos;          // < 1.60 为false,>= 1.60 为true,直接在 用户态赋值即可,不再做处理。
 // volatile const u64 status_s_pos;
-static u64 status_s_pos = 0;    //使用固定值即可,不再处理多版本场景。
+#define status_s_pos  0    //使用固定值即可,不再处理多版本场景。
 // volatile const u64 status_code_pos;
-static u64 status_code_pos = 40;    //使用固定值即可,不再做多版本处理
+#define status_code_pos  40   //使用固定值即可,不再做多版本处理
 // volatile const u64 http2server_peer_pos;
 // u64 http2server_peer_pos;
 // volatile const u64 peer_local_addr_pos;

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

@@ -216,9 +216,9 @@ int uprobe_HandlerFunc_ServeHTTP(struct pt_regs *ctx) {
 	// parentSys parentService
 	char *header_sys_val = bpf_map_lookup_elem(&http_server_context_sys_headers, &key);
 	if (header_sys_val) {
-		bpf_printk("has sys");
+//		bpf_printk("has sys");
 		bpf_probe_read(&cw_parent_span_context->sysvs, sizeof(cw_parent_span_context->sysvs), header_sys_val);
-		bpf_printk("has sys %s", cw_parent_span_context->sysvs);
+//		bpf_printk("has sys %s", cw_parent_span_context->sysvs);
 	}
 
 	if (traceparent_header_value != NULL) {