فهرست منبع

Merge branch 'dev-stack' of ssh://git.cloudwise.com:36000/TSB/euspace into dev-stack

Carl 1 سال پیش
والد
کامیت
7bdf5f776f
7فایلهای تغییر یافته به همراه78 افزوده شده و 39 حذف شده
  1. 17 2
      build.sh
  2. 2 2
      containers/container_apm.go
  3. 3 3
      containers/registry.go
  4. 33 23
      ebpftracer/ebpf/utrace/go/net/stack.probe.bpf.c
  5. 2 2
      ebpftracer/stack.go
  6. 4 4
      ebpftracer/tracer.go
  7. 17 3
      run.sh

+ 17 - 2
build.sh

@@ -1,6 +1,21 @@
 #!/bin/sh
 rm ./euspace
 make -f Makefile2 all debug=1 pid=1121
-pid=`ps aux | grep ebpfdemo81 | grep -v grep | awk '{print $2}'`
+
+# pid=`ps aux | grep ebpfdemo81 | grep -v grep | awk '{print $2}'`
+# echo $pid
+# TRACES_ENDPOINT=http://10.2.31.156:8099/docp/api/v2/data/receive BIN_TYPE=go SEND=1 FILTER_PID=$pid WHITE_LIST=".*HandleFunc|.*main.*|.*serverHandler.*|.*ServeHTTP.*" ./euspace --listen="0.0.0.0:8123"
+
+
+# pid=`ps aux | grep ./helloworld | grep -v grep | awk '{print $2}'`
+# echo $pid
+# TRACES_ENDPOINT=http://10.2.31.156:8099/docp/api/v2/data/receive BIN_TYPE=java DBG_PATH="/data/roger/graalvm/simplehttpserver.debug" SEND=1 FILTER_PID=$pid WHITE_LIST="main.*|addwj.*" ./euspace  --listen="0.0.0.0:8123"
+
+
+pid=`ps aux | grep ./simplehttpserver | grep -v grep | awk '{print $2}'`
 echo $pid
-TRACES_ENDPOINT=http://10.2.31.73:8099/docp/api/v2/data/receive SEND=1 FILTER_PID=$pid WHITE_LIST=".*HandleFunc|.*main.*|.*serverHandler.*|.*ServeHTTP.*" ./euspace  --listen="0.0.0.0:8123"
+TRACES_ENDPOINT=http://10.2.31.156:8099/docp/api/v2/data/receive BIN_TYPE=java DBG_PATH="/data/roger/graalvm/simplehttpserver.debug" SEND=1 FILTER_PID=$pid WHITE_LIST="handle*|addw.*" ./euspace  --listen="0.0.0.0:8123"
+
+# pid=`ps aux | grep CoreAoT | grep -v grep | awk '{print $2}'`
+# echo $pid
+# TRACES_ENDPOINT=http://10.2.31.156:8099/docp/api/v2/data/receive BIN_TYPE=dotnet DBG_PATH="/data/roger/NET8/CoreAoT/bin/Release/net8.0/linux-x64/publish/CoreAoT.dbg" SEND=1 FILTER_PID=$pid WHITE_LIST="main.*|Addwj.*" ./euspace  --listen="0.0.0.0:8123"

+ 2 - 2
containers/container_apm.go

@@ -376,9 +376,9 @@ func (c *Container) GetUprobe(event ebpftracer.StackEvent, tracer *ebpftracer.Tr
 	fmt.Printf("memoryMap.Start: %x, event.Ip: %x, Address: %x\n", memoryMap.Start, event.Ip, Address)
 
 	for _, fun := range tracer.UprobesMap {
-		// funAddress := fun.Address + fun.AbsOffset
+		funAddress := fun.Address + fun.AbsOffset
 		// fmt.Printf("GetUprobeGetUprobeGetUprobe:fun.Address %x, fun.AbsOffset: %x\n", fun.Address, fun.AbsOffset)
-		if fun.Address == Address {
+		if funAddress == Address {
 			// fmt.Printf("---GetUprobeGetUprobeGetUprobe: %x, event.Ip: %x\n", memoryMap.Start, event.Ip)
 			return fun, nil
 		}

+ 3 - 3
containers/registry.go

@@ -300,12 +300,12 @@ func (r *Registry) handleEvents(ch <-chan ebpftracer.Event) {
 				}
 
 				if c := r.containersByPid[uint32(e.StackEvent.Pid)]; c != nil {
-					fmt.Printf("e.EventTypeFunEnt: TraceId:%d, Pid:%d, Location:%d, Goid:%d, TimeNs:%d, Ip:%X, CallerIp:%x, Bp:%x, CallerBp:%x\n", e.StackEvent.TraceId, e.StackEvent.Pid, e.StackEvent.Location, e.StackEvent.Goid, e.StackEvent.TimeNsStart, e.StackEvent.Ip, e.StackEvent.CallerIp, e.StackEvent.Bp, e.StackEvent.CallerBp)
-					fmt.Printf("e.EventTypeFunEnt: FPid:%x, Nid:%x, Level:%d\n", e.StackEvent.Fpid, e.StackEvent.Nid, e.StackEvent.Level)
+					fmt.Printf("e.EventTypeFunEnt: TraceId:%lld, Pid:%d, Location:%d, Goid:%lld, TimeNs:%d, Ip:%x, CallerIp:%x, Bp:%x, CallerBp:%x\n", e.StackEvent.TraceId, e.StackEvent.Pid, e.StackEvent.Location, e.StackEvent.Goid, e.StackEvent.TimeNsStart, e.StackEvent.Ip, e.StackEvent.CallerIp, e.StackEvent.Bp, e.StackEvent.CallerBp)
+					// fmt.Printf("e.EventTypeFunEnt: FPid:%x, Nid:%x, Level:%d\n", e.StackEvent.Fpid, e.StackEvent.Nid, e.StackEvent.Level)
 					c.StackProcess2(*e.StackEvent, r.tracer)
 				} else {
 					fmt.Printf("e.EventTypeFunEnt ErrorError: TraceId:%d, Pid:%d, Location:%d, Goid:%d, TimeNs:%d, Ip:%X, CallerIp:%x, Bp:%x, CallerBp:%x", e.StackEvent.TraceId, e.StackEvent.Pid, e.StackEvent.Location, e.StackEvent.Goid, e.StackEvent.TimeNsStart, e.StackEvent.Ip, e.StackEvent.CallerIp, e.StackEvent.Bp, e.StackEvent.CallerBp)
-					fmt.Printf("e.EventTypeFunEnt ErrorError: TraceId:%x, FPid:%x, Nid:%x, Level:%d\n", e.StackEvent.Fpid, e.StackEvent.Nid, e.StackEvent.Level)
+					// fmt.Printf("e.EventTypeFunEnt ErrorError: TraceId:%x, FPid:%x, Nid:%x, Level:%d\n", e.StackEvent.Fpid, e.StackEvent.Nid, e.StackEvent.Level)
 				}
 			}
 		}

+ 33 - 23
ebpftracer/ebpf/utrace/go/net/stack.probe.bpf.c

@@ -21,13 +21,11 @@ struct event
 	__u64 caller_bp;
 	__u64 time_ns_start;
 	__u64 time_ns_end;
-	__u64 nid;
-	__u64 fpid;
-	__u64 level;
 	__u8 location;
 }__attribute__((packed));
 
 struct trace_stack_entry_key_t {
+	__u64 trace_id;
 	__u64 caller_bp;
 	__u64 bp;
 };
@@ -105,17 +103,25 @@ int ent(struct pt_regs *ctx)
 
 	cw_bpf_debug("[Go] [uprobe/ent]: goid: %llu", e->goid);
 
-	cw_bpf_debug("[Go] [uprobe/ent]: event: location:%x,ip:%lx,time_ns_start:%lld\n", e->location, e->ip, e->time_ns_start);
+	cw_bpf_debug("[Go] [uprobe/ent]: event: location:%x,ip:%lx,time_ns_start:%llu\n", e->location, e->ip, e->time_ns_start);
 	cw_bpf_debug("[Go] [uprobe/ent]: event: bp:%x,caller_bp:%x,caller_ip:%x\n", e->bp,e->caller_bp,e->caller_ip);
 
 	struct trace_stack_entry_key_t trace_key = {};
 	trace_key.caller_bp = e->caller_bp % 0x800 + (e->goid << 12);
 	trace_key.bp = e->bp % 0x800 + (e->goid << 12);
+	trace_key.trace_id = trace_id;
 
 	// trace_key.caller_bp = e->caller_bp;
 	// trace_key.bp = e->bp;
 	// cw_bpf_debug("[Go] [uprobe/ent]: trace_keytrace_keytrace_key: bp: %x", trace_key.bp);
-	cw_bpf_debug("[Go] [uprobe/ent]: trace_keytrace_keytrace_key: caller_bp: %x, bp: %x", trace_key.caller_bp, trace_key.bp);
+	bpf_printk("[Go] [uprobe/ent]: trace_keytrace_keytrace_key: caller_bp: %x, bp: %x, %lld", trace_key.caller_bp, trace_key.bp, trace_key.trace_id);
+
+	struct event *event_p = bpf_map_lookup_elem(&trace_stack_entry, &trace_key);
+
+	if (event_p) {
+		cw_bpf_debug("[Go] [uprobe/ent]:Error get alike funEntry %x, %x, %x", event_p->ip, event_p->caller_bp, event_p->bp);
+		// return 0;
+	}
 
 	struct event event_current = {};
 	event_current.bp = e->bp,
@@ -127,8 +133,6 @@ int ent(struct pt_regs *ctx)
 	event_current.ip = e->ip,
 	event_current.time_ns_start = e->time_ns_start,
 	event_current.location = e->location,
-	event_current.nid = ((e->ip % 0x1000) << 24) + e->bp % 0x800 + (e->goid << 12),
-	event_current.fpid = e->caller_bp % 0x800 + (e->goid << 12),
 
 	bpf_map_update_elem(&trace_stack_entry, &trace_key, &event_current, BPF_ANY);
 
@@ -167,20 +171,22 @@ int ret(struct pt_regs *ctx)
 	cw_bpf_debug("[Go] [uprobe/ret]: yes");
 	e->pid = pid;
 	e->trace_id = trace_id;
-	e->location = RETPOINT;
+	e->location = ENTPOINT;
 	e->ip = PT_REGS_IP(ctx);
 	e->time_ns_end = bpf_ktime_get_ns();
 	e->bp = PT_REGS_SP(ctx) - 8;
+	e->caller_bp = PT_REGS_FP(ctx);
 
-	__u64 caller_bp = PT_REGS_FP(ctx);
-	cw_bpf_debug("[Go] [uprobe/ret]: e->ip:%lx,bp:%x,caller_bp:%x", e->ip, e->bp, caller_bp);
+	// __u64 caller_bp = PT_REGS_FP(ctx);
+	cw_bpf_debug("[Go] [uprobe/ret]: e->ip:%lx,bp:%x,caller_bp:%x", e->ip, e->bp, e->caller_bp);
 	cw_bpf_debug("[Go] [uprobe/ret]: sp:%x, goid: %llu, goid:0x:%x", PT_REGS_SP(ctx), e->goid, e->goid);
 
-	cw_bpf_debug("[Go] [uprobe/ret]: event: location:%x,ip:%x,time_ns_end:%lld\n", e->location, e->ip, e->time_ns_end);
+	cw_bpf_debug("[Go] [uprobe/ret]: event: location:%x,ip:%x,time_ns_end:%llu\n", e->location, e->ip, e->time_ns_end);
 
 	struct trace_stack_entry_key_t trace_key = {};
-	trace_key.caller_bp = caller_bp % 0x800 + (e->goid << 12);
+	trace_key.caller_bp = e->caller_bp % 0x800 + (e->goid << 12);
 	trace_key.bp = e->bp % 0x800 + (e->goid << 12);
+	trace_key.trace_id = trace_id;
 
 	// trace_key.caller_bp = caller_bp;
 	// trace_key.bp = e->bp;
@@ -197,21 +203,26 @@ int ret(struct pt_regs *ctx)
 
 	event_p->time_ns_end = e->time_ns_end;
 
-	cw_bpf_debug("[Go] [uprobe/ret]: ent:event: location:%d,ip:%x,time_ns_start:%lld\n", event_p->location, event_p->ip, event_p->time_ns_start);
+	cw_bpf_debug("[Go] [uprobe/ret]: ent:event: location:%d,ip:%x,time_ns_start:%llu\n", event_p->location, event_p->ip, event_p->time_ns_start);
 	cw_bpf_debug("[Go] [uprobe/ret]: ent:event: bp:%x,caller_bp:%x,caller_ip:%x\n", event_p->bp,event_p->caller_bp,event_p->caller_ip);
-	cw_bpf_debug("[Go] [uprobe/ret]: ent:event: nid:%llx,fpid:%llx,level:%d\n", event_p->nid,event_p->fpid,event_p->level);
-
-	bpf_map_delete_elem(&trace_stack_entry, &trace_key);
 
+	e->time_ns_start = event_p->time_ns_start;
+	// e->caller_ip = event_p->caller_ip;
+	// e->ip = event_p->ip;
+	
 	// return bpf_map_push_elem(&event_queue, e, BPF_EXIST);
-	cw_bpf_debug("[Go] [uprobe/ret]: ent:event_ret push: nid:%llx,fpid:%llx,level:%d\n", event_p->nid,event_p->fpid,event_p->level);
-	long err =  bpf_perf_event_output(ctx, &event_queue, BPF_F_CURRENT_CPU, event_p, sizeof(*e));
-	if (err ==0) {
+	cw_bpf_debug("[Go] [uprobe/ret]: ent:event_ret push: event_p->ip:%llx,ip:%llx\n", event_p->ip, e->ip);
+	long err =  bpf_perf_event_output(ctx, &event_queue, BPF_F_CURRENT_CPU, e, sizeof(*e));
+	if (err == 0) {
 		__u32 count = cw_add_event_count(trace_id);
-		if (count > 0) {
-			cw_bpf_debug("count->%d",count);
+		if (event_p->trace_id != trace_id) {
+			cw_bpf_debug("[pref] fuck err<%d> ip->%x->%x", err, PT_REGS_IP(ctx), e->ip);
 		}
+		cw_bpf_debug("[pref] err<%d> count->%d trace_id->%llu", err, count, trace_id);
+	} else {
+		cw_bpf_debug("[pref] err<%d> trace_id->%d", err, trace_id);
 	}
+	bpf_map_delete_elem(&trace_stack_entry, &trace_key);
 	cw_bpf_debug("[Go] [uprobe/ret] end");
 	return 1;
 }
@@ -275,6 +286,7 @@ int dotnetent(struct pt_regs *ctx)
 	struct trace_stack_entry_key_t trace_key = {};
 	trace_key.caller_bp = e->caller_bp % 0x800 + (e->goid << 12);
 	trace_key.bp = e->bp % 0x800 + (e->goid << 12);
+	trace_key.trace_id = trace_id;
 
 	// trace_key.caller_bp = e->caller_bp;
 	// trace_key.bp = e->bp;
@@ -291,8 +303,6 @@ int dotnetent(struct pt_regs *ctx)
 	event_current.ip = e->ip,
 	event_current.time_ns_start = e->time_ns_start,
 	event_current.location = e->location,
-	event_current.nid = ((e->ip % 0x1000) << 24) + e->bp % 0x800 + (e->goid << 12),
-	event_current.fpid = e->caller_bp % 0x800 + (e->goid << 12),
 
 	bpf_map_update_elem(&trace_stack_entry, &trace_key, &event_current, BPF_ANY);
 

+ 2 - 2
ebpftracer/stack.go

@@ -73,8 +73,8 @@ func (t *Tracer) stack() error {
 	t.UprobesMap = map[string]tracer.Uprobe{}
 	fmt.Println("UprobesMap:::init")
 	for _, up := range t.Uprobes {
-		fmt.Println("UprobesMap:::", up.Funcname)
-		t.UprobesMap[fmt.Sprintf("%s-%s", up.Funcname, up.Address)] = up
+		fmt.Println("UprobesMap:::", up.Funcname, up.Address, up.AbsOffset)
+		t.UprobesMap[fmt.Sprintf("%s-%s", up.Funcname, up.Address+up.AbsOffset)] = up
 	}
 	links := t.attachUprobes(path, t.Uprobes)
 	t.links = append(t.links, links...)

+ 4 - 4
ebpftracer/tracer.go

@@ -482,10 +482,10 @@ type StackEvent struct {
 	CallerBp    uint64
 	TimeNsStart uint64
 	TimeNsEnd   uint64
-	Nid         uint64
-	Fpid        uint64
-	Level       uint64
-	Location    byte
+	// Nid         uint64
+	// Fpid        uint64
+	// Level       uint64
+	Location byte
 }
 
 type StackFunEvent struct {

+ 17 - 3
run.sh

@@ -1,4 +1,18 @@
-#!/bin/sh
-pid=`ps aux | grep ebpfdemo81 | grep -v grep | awk '{print $2}'`
+!/bin/sh
+# pid=`ps aux | grep ebpfdemo81 | grep -v grep | awk '{print $2}'`
+# echo $pid
+# TRACES_ENDPOINT=http://10.2.31.156:8099/docp/api/v2/data/receive BIN_TYPE=go SEND=1 FILTER_PID=$pid WHITE_LIST=".*HandleFunc|.*main.*|.*serverHandler.*|.*ServeHTTP.*" ./euspace --listen="0.0.0.0:8123"
+
+
+# pid=`ps aux | grep ./helloworld | grep -v grep | awk '{print $2}'`
+# echo $pid
+# TRACES_ENDPOINT=http://10.2.31.156:8099/docp/api/v2/data/receive BIN_TYPE=java DBG_PATH="/data/roger/graalvm/simplehttpserver.debug" SEND=1 FILTER_PID=$pid WHITE_LIST="main.*|addwj.*" ./euspace  --listen="0.0.0.0:8123"
+
+
+pid=`ps aux | grep ./simplehttpserver | grep -v grep | awk '{print $2}'`
 echo $pid
-TRACES_ENDPOINT=http://10.2.31.73:8099/docp/api/v2/data/receive FILTER_PID=$pid WHITE_LIST=".*HandleFunc|.*main.*|.*serverHandler.*|.*ServeHTTP.*" ./euspace --listen="0.0.0.0:8123"
+TRACES_ENDPOINT=http://10.2.31.156:8099/docp/api/v2/data/receive BIN_TYPE=java DBG_PATH="/data/roger/graalvm/simplehttpserver.debug" SEND=1 FILTER_PID=$pid WHITE_LIST="handle*|addw.*" ./euspace  --listen="0.0.0.0:8124"
+
+# pid=`ps aux | grep CoreAoT | grep -v grep | awk '{print $2}'`
+# echo $pid
+# TRACES_ENDPOINT=http://10.2.31.156:8099/docp/api/v2/data/receive BIN_TYPE=dotnet DBG_PATH="/data/roger/NET8/CoreAoT/bin/Release/net8.0/linux-x64/publish/CoreAoT.dbg" SEND=1 FILTER_PID=$pid WHITE_LIST="main.*|Addwj.*" ./euspace  --listen="0.0.0.0:8123"