Skip to content

Commit

Permalink
netwatcher:寻找并修改挂载函数,使其能正确拉取延时 (#852)
Browse files Browse the repository at this point in the history
* change the uprobe function

* delete the useless

---------

Co-authored-by: zmx <xupt_zmx>
  • Loading branch information
zhangxianyu777 authored Jul 4, 2024
1 parent 04a4669 commit 9f34178
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,8 @@ int BPF_KPROBE(query__end){
return __handle_mysql_end(ctx);
}

SEC("uprobe/call")
int BPF_KPROBE(query__start_redis) {
SEC("uprobe/processCommand")
int BPF_KPROBE(query__start_redis_process) {
return __handle_redis_start(ctx);
}
SEC("uretprobe/call")
Expand Down
12 changes: 8 additions & 4 deletions eBPF_Supermarket/Network_Subsystem/net_watcher/netwatcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -563,10 +563,10 @@ static void set_disable_load(struct netwatcher_bpf *skel) {
mysql_info ? true : false);
bpf_program__set_autoload(skel->progs.query__end,
mysql_info ? true : false);
bpf_program__set_autoload(skel->progs.query__start_redis,
redis_info ? true : false);
bpf_program__set_autoload(skel->progs.query__end_redis,
redis_info ? true : false);
bpf_program__set_autoload(skel->progs.query__start_redis_process,
redis_info ? true : false);
}

static void print_header(enum MonitorMode mode) {
Expand Down Expand Up @@ -1190,8 +1190,12 @@ int attach_uprobe_mysql(struct netwatcher_bpf *skel) {
return 0;
}
int attach_uprobe_redis(struct netwatcher_bpf *skel) {
ATTACH_UPROBE_CHECKED(skel, call, query__start_redis);
ATTACH_UPROBE_CHECKED(skel, call, query__end_redis);
ATTACH_UPROBE_CHECKED(
skel, call,
query__end_redis);
ATTACH_UPROBE_CHECKED(
skel, processCommand,
query__start_redis_process);
return 0;
}
int main(int argc, char **argv) {
Expand Down
4 changes: 1 addition & 3 deletions eBPF_Supermarket/Network_Subsystem/net_watcher/redis.bpf.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#include "common.bpf.h"
#include "redis_helper.bpf.h"
#define MAXEPOLL 4
#define MAXEPOLL 5
static __always_inline int __handle_redis_start(struct pt_regs *ctx) {
struct client *cli = (struct client *)PT_REGS_PARM1(ctx);
struct redis_query start={};
Expand All @@ -34,7 +34,6 @@ static __always_inline int __handle_redis_start(struct pt_regs *ctx) {
bpf_probe_read(&arg1, sizeof(arg1), &arg0[i]);
bpf_probe_read(&ptr, sizeof(ptr),&arg1->ptr);
bpf_probe_read_str(&start.redis[i], sizeof(start.redis[i]), ptr);
//bpf_printk("%s",start.redis[i]);
}
pid_t pid = bpf_get_current_pid_tgid() >> 32;
u64 start_time = bpf_ktime_get_ns() / 1000;
Expand Down Expand Up @@ -64,7 +63,6 @@ static __always_inline int __handle_redis_end(struct pt_regs *ctx) {
}
bpf_probe_read_str(&message->redis, sizeof(start->redis), start->redis);
message->duratime = end_time - start->begin_time;
bpf_printk("%llu - %llu = %llu",end_time,start->begin_time,message->duratime);
bpf_ringbuf_submit(message, 0);
return 0;
}

0 comments on commit 9f34178

Please sign in to comment.